Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for double-click word selection#840

Merged
noborus merged 3 commits intomasterfrom
add-support-double-click
Sep 1, 2025
Merged

Add support for double-click word selection#840
noborus merged 3 commits intomasterfrom
add-support-double-click

Conversation

@noborus
Copy link
Owner

@noborus noborus commented Sep 1, 2025

  • Implement double-click detection with configurable interval and distance
  • Add word boundary detection for smart text selection
  • Enhance mouse event handling with click state management
  • Support alphanumeric, whitespace, and symbol character types
  • Improve user experience with intuitive text selection

- Implement double-click detection with configurable interval and distance
- Add word boundary detection for smart text selection
- Enhance mouse event handling with click state management
- Support alphanumeric, whitespace, and symbol character types
- Improve user experience with intuitive text selection
@noborus noborus requested a review from Copilot September 1, 2025 00:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements double-click word selection functionality to enhance the text editor's user experience. The feature enables users to quickly select words by double-clicking, with intelligent word boundary detection based on character types.

Key changes:

  • Added configurable double-click detection with timing and distance thresholds
  • Implemented smart word boundary detection that differentiates between alphanumeric, whitespace, and symbol characters
  • Refactored mouse event handling to support click state management and improved selection logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
oviewer/oviewer.go Added clickState field to Root struct for tracking mouse click state
oviewer/mouse.go Implemented double-click detection, word boundary finding, and refactored mouse selection handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

oviewer/mouse.go Outdated
Comment on lines 293 to 303
return 0 // Out of range is treated as whitespace
}

char := line.lc[contentX].mainc
if char == ' ' || char == '\t' {
return 1 // Whitespace
}
if unicode.IsLetter(char) || unicode.IsDigit(char) || char == '_' {
return 2 // Alphanumeric and underscore
}
return 3 // Other characters
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using magic numbers (0, 1, 2, 3) for character types reduces code readability. Consider defining constants like const (CharTypeWhitespace = 0; CharTypeAlphanumeric = 1; ...) to make the code more self-documenting.

Suggested change
return 0 // Out of range is treated as whitespace
}
char := line.lc[contentX].mainc
if char == ' ' || char == '\t' {
return 1 // Whitespace
}
if unicode.IsLetter(char) || unicode.IsDigit(char) || char == '_' {
return 2 // Alphanumeric and underscore
}
return 3 // Other characters
return charTypeOutOfRange // Out of range is treated as whitespace
}
char := line.lc[contentX].mainc
if char == ' ' || char == '\t' {
return charTypeWhitespace // Whitespace
}
if unicode.IsLetter(char) || unicode.IsDigit(char) || char == '_' {
return charTypeAlphanumeric // Alphanumeric and underscore
}
return charTypeOther // Other characters

Copilot uses AI. Check for mistakes.
Comment on lines 218 to 221
if timeDiff > DoubleClickInterval {
root.resetClickState() // Reset if too much time has passed
return false
}
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The side effect of calling resetClickState() inside isDoubleClick() makes the function less predictable. Consider moving this reset logic to the caller (updateClickState) to keep isDoubleClick() as a pure query function.

Copilot uses AI. Check for mistakes.
noborus and others added 2 commits September 1, 2025 10:07
- Replace isDoubleClick boolean function with checkClickType enum return
- Add ClickType enum (ClickSingle, ClickDouble, ClickExpired) for clearer state handling
- Consolidate click state management logic in handlePrimaryButtonClick
- Add character type constants for better code readability
- Reduce code duplication by centralizing timeout and reset logic

This improves the maintainability of the double-click detection system and makes the click handling
@noborus noborus merged commit 842f88c into master Sep 1, 2025
9 checks passed
@noborus noborus deleted the add-support-double-click branch September 3, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant