Skip to content

Commit

Permalink
fix cursor position on state changes (sveltejs#1035)
Browse files Browse the repository at this point in the history
fix cursor position on state changes - fixes sveltejs#935
  • Loading branch information
Rich-Harris authored Dec 18, 2024
1 parent 2f8b59d commit 59ff625
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/editor/src/lib/Workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ export class Workspace {
const existing = state.doc.toString();

if (file.contents !== existing) {
const current_cursor_position = this.#view?.state.selection.ranges[0].from!;
const current_cursor_position = Math.min(
this.#view?.state.selection.ranges[0].from!,
file.contents.length
);

const transaction = state.update({
changes: {
Expand Down

0 comments on commit 59ff625

Please sign in to comment.