You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extension API: cursor position (determining current location and moving it) #111
Even if there is no selected text, you have to use the selection object. Something like this:
// current editor
const editor = vscode.window.activeTextEditor;
// check if there is no selection
if (editor.selection.isEmpty) {
// the Position object gives you the line and character where the cursor is
const position = editor.selection.active;
}
// current editor
const editor = vscode.window.activeTextEditor;
// check if there is no selection
if (editor.selection.isEmpty) {
// the Position object gives you the line and character where the cursor is
const position = editor.selection.active;
// move cursor to this new position?
var newPosition = position.with(position.line, 0);
}
changed the title [-]Extension API: Determine current cursor position[/-][+]Extension API: cursor position (determining current location and moving it)[/+]on Nov 19, 2015
Activity
alefragnani commentedon Nov 19, 2015
Hi Jason Poon (@jpoon),
Even if there is no selected text, you have to use the
selectionobject. Something like this:Hope this helps
jpoon commentedon Nov 19, 2015
Alessandro Fragnani (@alefragnani) perfect. I'm going to close this issue 👍
jpoon commentedon Nov 19, 2015
Alessandro Fragnani (@alefragnani) one more question, is there a way to move the cursor?
Say for the sample code you posted:
[-]Extension API: Determine current cursor position[/-][+]Extension API: cursor position (determining current location and moving it)[/+]joaomoreno commentedon Nov 19, 2015
It's a setter!
joaomoreno commentedon Nov 19, 2015
Johannes Rieken (@jrieken) The API should probably indicate in the doc comments what can be set.
jpoon commentedon Nov 19, 2015
😍 Perfect!
+1 on the docs to denote setters.
jrieken commentedon Nov 19, 2015
All properties that don't have the
@readonlytag can be set.