Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] editorInstance.setSelection() is not working #4814

Open
2 tasks done
naganand123 opened this issue Jan 24, 2025 · 1 comment
Open
2 tasks done

[Bug] editorInstance.setSelection() is not working #4814

naganand123 opened this issue Jan 24, 2025 · 1 comment

Comments

@naganand123
Copy link

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

No response

Monaco Editor Playground Code

Reproduction Steps

editorInstance.setSelection({startLineNumber: 4,startColumn: 12,endLineNumber: 4,endColumn: 14});

I am using "monaco-editor": "0.41.0" version

Actual (Problematic) Behavior

No response

Expected Behavior

No response

Additional Context

No response

@rcjsuen
Copy link
Contributor

rcjsuen commented Jan 24, 2025

  1. This code seems to work fine for me. If I click on the code lens action then XX gets highlighted on the fourth line.
  2. You are using Monaco 0.41.0 so you should probably consider upgrading.
const editor = monaco.editor.create(document.getElementById("container"), {
	value: '123456789012345678901234567890\n123456789012345678901234567890\n123456789012345678901234567890\n12345678901XX45678901234567890',
	language: "plaintext",
});

const commandId = editor.addCommand(
	0,
	function () {
		editor.setSelection({startLineNumber: 4,startColumn: 12,endLineNumber: 4,endColumn: 14});
	},
	""
);

monaco.languages.registerCodeLensProvider("plaintext", {
	provideCodeLenses: function (model, token) {
		return {
			lenses: [
				{
					range: {
						startLineNumber: 1,
						startColumn: 1,
						endLineNumber: 2,
						endColumn: 1,
					},
					id: "command.setSelection",
					command: {
						id: commandId,
						title: "Set Selection",
					},
				},
			],
			dispose: () => {},
		};
	},
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants