How to get a selected text?
See original GitHub issueIf I have next text in the editor
Example text here
Another paragraph
And when I select word text
and print to console state.focusText.text
- I got whole Example text here
sentence. Bu I wan to get text
word instead. I tried bunch of methods - but no one seems to work.
I guess I can get selected work by using state.startOffset
and state.endOffset
properties ( or state.focusKey
) - but I don’t know how.
Slate should have some convenient method for this case. Am I right?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Get the Highlighted/Selected text - javascript - Stack Overflow
Getting the text the user has selected is relatively simple. ... function getSelectionText() { var text = ""; var activeEl = document.
Read more >How to get the Highlighted/Selected text in JavaScript?
There may be a need to find out the text selected/highlighted by the user. It can be done very easily using the window...
Read more >How do I get the text value of a selected option?
Select elements typically have two values that you want to access. First there's the value ... The second is the text value of...
Read more >Window.getSelection() - Web APIs | MDN
The Window.getSelection() method returns a Selection object representing the range of text selected by the user or the current position of ...
Read more >get selected text with JavaScript - CodePen
1. <p onmouseup="getSelectedText(); alert(txt)"> ; 2. Highlight some of this text ; 3. with the mouse select press button end release ; 4....
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
There’s
Editor.string
function that can be used to get the text at the selection.const selectedText = Editor.string(editor, editor.selection);
It’s now
value.fragment.text
, wherevalue
is fromchange.value
.It seems to be
Node.texts(root: Node, options?): Iterable<NodeEntry<Text>>
nowhttps://docs.slatejs.org/api/nodes#static-methods