getSelection() does not return a single character selection
See original GitHub issueRelates to: #2244 This works fine when a double-click highlights a word selection > 1 character. But if the selection only highlights a single character, getSelection() returns an empty string. Is this by design?
Details
- Browser and browser version: Chrome 78
- OS version: Linux
- xterm.js version: 4.3.0
Steps to reproduce
- ITerminalOptions.wordSeparator = ` .:;?!"'<>(/)[=]`
- term.write('Sex (M/F)? ')
- double-click the ‘M’
- getSelection() returns ‘’
Online example: https://play.ddgame.us
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Why getSelection() always returns nothing? - Stack Overflow
The click event happens when the mouse button is pressed, and then released, and at that time the selection is lost.
Read more >Window.getSelection() - Web APIs | MDN
getSelection() method returns a Selection object representing the range of text selected by the user or the current position of the caret.
Read more >Selection API - W3C
Abstract. This document is a preliminary draft of a specification for the Selection API and selection related functionality.
Read more >Google Visualization API Reference | Charts
Returns a sorted version of the table without modifying the order of the underlying data. To permanently sort the underlying data, call sort()...
Read more >Word.Range class - Office Add-ins - Microsoft Learn
Returns a new range that extends from this range in either direction to cover another range. This range is not changed. If the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
4.7.0 works great, thanks!
@daniel-j-davis good find! Moving this
event.altKey
up one line would probably fix it, do you want to do a PR?https://github.com/xtermjs/xterm.js/blob/afc39106c3707532136c0818e9d3aa1dbcf176ac/src/browser/services/SelectionService.ts#L670-L671
To verify, make sure alt+click still works by moving the cursor horizontally in a prompt with input