Skip to content

Commit 8af3a99

Browse files
committed
playground: improve cursor handling in editor
1 parent 4fd0662 commit 8af3a99

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

website/src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,14 @@ class HdxEditor extends HTMLElement {
270270
} else if (event.type == "click" || event.type === "focusin") {
271271
codeFromUrl.set(this.code);
272272
codeFromLocal.set(this.code);
273-
const pos = this.view.posAtCoords(event);
274273
const tree = syntaxTree(this.view.state);
275-
let cursor = tree.cursorAt(pos);
274+
let cursor;
275+
if (event.x && event.y) {
276+
const pos = this.view.posAtCoords(event);
277+
cursor = tree.cursorAt(pos);
278+
} else {
279+
cursor = tree.cursorAt(this.view.state.selection.anchor);
280+
}
276281
this.dispatchEvent(
277282
new EditorFocus({ start: cursor.from, end: cursor.to }),
278283
);

0 commit comments

Comments
 (0)