What’s the recommended way to get selected text in the editor #5077
Answered
by
code-asher
Oliver-Weng-Sorcerer
asked this question in
Q&A
Replies: 3 comments 23 replies
0 replies
|
I am not sure JavaScript-level features will work very well here. The
best method is to go through the Code API via a custom extension.
https://code.visualstudio.com/api/references/vscode-api
For example (untested):
```
const editor = vscode.window.activeTextEditor
conts text = editor.getText(editor.selection)
````
|
8 replies
Answer selected by
jsjoeio
|
Hi @jsjoeio and @code-asher , I'm not sure if it's just me or it's a bug. here is what I see right now. my extension has this code snippet in it. but whenever I use the extension in the code server in Firefox, and start writing content in a file, it gives me this error. but it's happening in chrome. I'm wondering if code server internally interpret the vscode.env.clipboard object to navigator.clipboard, since it's currently a firefox limitation. Any workaround to avoid the warning message downbelow? ref: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read |
15 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Currently I’m working on an additional feature, wondering what’s the best way to get the selected text in the editor.
Is there any Js object exposed in root document something like “editor.getSlection()” exists?
currently I’m using document.selection().toString(), but that doesn’t work well with Firefox.
Any ideas ?
All reactions