Add support for double-click word selection#840
Conversation
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
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
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.
| 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 |
| if timeDiff > DoubleClickInterval { | ||
| root.resetClickState() // Reset if too much time has passed | ||
| return false | ||
| } |
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
- 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