Skip to content

Selecting text with mouse cursor #1214

Answered by Noyabronok
Noyabronok asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, figured it out. These unit tests provide good examples.

// highlight 5 characters from beginning of text element
await user.pointer(
[
  // left click and hold at char 0
  { target: textElement, offset: 0, keys: '[MouseLeft>]' }, 
  // drag the mouse to the right 5 characters
  { offset: 5 },
  // release the left mouse button
  { keys: '[/MouseLeft]' }
]);

// get the selected text
const selection = document.getSelection()?.toString();
// assert the selection
expect(selection).toBe('12345');

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Noyabronok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant