Skip to content

Commit 6e511fa

Browse files
committedNov 8, 2023
fix: #331 changing contents during the onChange callback throws a selection error
1 parent b07d08d commit 6e511fa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎src/lib/components/modes/textmode/TextMode.svelte

+7-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,13 @@
765765
766766
updateCanUndoRedo()
767767
emitOnChange(content, previousContent)
768-
emitOnSelect()
768+
769+
// We emit OnSelect on the next tick to cater for the case where
770+
// the user changes the content directly inside the OnChange callback.
771+
// This change will be dispatched by Svelte on the next tick. Before
772+
// that tick, emitOnSelect would be fired based on the "old" contents,
773+
// which may be out of range when the replacement by the user is shorter.
774+
tick().then(emitOnSelect)
769775
}
770776
771777
function updateLinter(validator: Validator | null) {

0 commit comments

Comments
 (0)
Please sign in to comment.