Skip to content

How to console the row and column in time when cursor locate in the editor? Is there an official explanation? #4621

Answered by rcjsuen
liaodalin19903 asked this question in Q&A
Discussion options

You must be logged in to vote

@liaodalin19903 Perhaps this snippet of code may be of help to you then.

const value = `function hello() {
	alert('Hello world!');
}`;

const editor = monaco.editor.create(
	document.getElementById("container"), {
	value,
	language: "javascript",
	automaticLayout: true,
});

editor.onDidChangeCursorPosition((e) => {
	document.getElementById("console").textContent = JSON.stringify(e.position);
});
<div id="container" style="height: 100%">
    <div id="console">Console</div>
</div>

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by liaodalin19903
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants