Skip to content

Commit 59ff625

Browse files
authored
fix cursor position on state changes (#1035)
fix cursor position on state changes - fixes #935
1 parent 2f8b59d commit 59ff625

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/editor/src/lib/Workspace.svelte.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ export class Workspace {
556556
const existing = state.doc.toString();
557557

558558
if (file.contents !== existing) {
559-
const current_cursor_position = this.#view?.state.selection.ranges[0].from!;
559+
const current_cursor_position = Math.min(
560+
this.#view?.state.selection.ranges[0].from!,
561+
file.contents.length
562+
);
560563

561564
const transaction = state.update({
562565
changes: {

0 commit comments

Comments
 (0)