What’s the recommended way to get selected text in the editor #5077
Replies: 3 comments 23 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)
````
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 ?
Beta Was this translation helpful? Give feedback.
All reactions