question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getSelection() does not return a single character selection

See original GitHub issue

Relates 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

  1. ITerminalOptions.wordSeparator = ` .:;?!"'<>(/)[=]`
  2. term.write('Sex (M/F)? ')
  3. double-click the ‘M’
  4. getSelection() returns ‘’

Online example: https://play.ddgame.us

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
theflyingapecommented, Jun 11, 2020

4.7.0 works great, thanks!

1reaction
Tyriarcommented, Jun 11, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found