Skip to content

Commit

Permalink
Merge pull request #44 from KrialY/fix/model_value_update
Browse files Browse the repository at this point in the history
fix: editor not update content when `modelValue` change and selection is out of range
  • Loading branch information
logue authored Jul 11, 2024
2 parents 0cf8680 + 2501403 commit 0e70955
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/components/CodeMirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,18 +462,14 @@ export default defineComponent({

// Range Fix ?
// https://github.com/logue/vue-codemirror6/issues/27
if (
!selection.value.ranges.every(
range => range.anchor < value.length && range.head < value.length
)
) {
return;
}

const isSelectionOutOfRange = !view.value.state.selection.ranges.every(
range => range.anchor < value.length && range.head < value.length
)

// Update
view.value.dispatch({
changes: { from: 0, to: view.value.state.doc.length, insert: value },
selection: view.value.state.selection,
selection: isSelectionOutOfRange ? { anchor: 0, head: 0 } : view.value.state.selection,
scrollIntoView: true,
});
},
Expand Down

0 comments on commit 0e70955

Please sign in to comment.