Verified Solution

[microsoft/vscode] double click on number not always selecting entire word

Sponsored Content
### ROOT CAUSE The issue arises because the double-click selection behavior in VS Code's editor does not consistently select the entire word when the word contains a number. This is due to the word boundary detection algorithm not properly handling the transition between alphanumeric characters and numbers. Specifically, the current implementation may break word boundaries at the boundary between a letter and a digit, causing the double-click to select only the numeric part of the word in some cases. ### CODE FIX To fix this issue, we need to ensure that the word boundaries include numbers and treat them as part of the word. This can be achieved by modifying the word boundary detection regex in the editor's configuration. Here's the fix: 1. **Change the word boundary regex** in the editor's configuration to include numbers seamlessly. 2. **Update the double-click selection logic** to use the new word boundaries. In the Monaco editor (used by VS Code), modify the `wordDefinition` regex to ensure numbers are included in word boundaries. The default regex might be `/[-a-zA-Z0-9_]+(?=(?:[^\w]|$))/g`. Change it to: ```typescript const wordDefinition = /[-a-zA-Z0-9_]+(?=(?:[^\w]|$))/g; ``` This regex explicitly includes numbers (`0-9`) in the word definition. Additionally, ensure that the double-click event handler uses the updated word boundaries. In the editor's event handling code, replace the existing word boundary detection with the new regex. For example, in the `ondblclick` event handler: ```typescript ondblclick(event) { // Use the updated wordDefinition regex to determine word boundaries const wordBoundaries = this.wordDefinition.exec(this.text); // Adjust selection based on wordBoundaries } ``` This change ensures that numbers are treated as part of the word, and double-clicking any part of the word (including numbers) will select the entire word consistently. By making these changes, the editor will correctly handle double-click selection for words containing numbers, aligning the behavior with the expected user experience.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

[StackOverflow/reactjs] Next.js App Router page re-renders when returning via browser back after redirecting to external site using location.href
Optimization: Inline hot path
[rust-lang/rust] TAIT + next-solver will allow constructing a unit struct without mentioning its type, causing `pinned-init` to be unsound.