Skip to content

Commit

Permalink
fix: #423 error about an invalid selection in text mode when clearing…
Browse files Browse the repository at this point in the history
… the contents
  • Loading branch information
josdejong committed Apr 17, 2024
1 parent fd6d698 commit 5ed8a86
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib/components/modes/textmode/TextMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@
const state = EditorState.create({
doc: initialText,
selection: toCodeMirrorSelection(externalSelection),
selection: isValidSelection(externalSelection, initialText)
? toCodeMirrorSelection(externalSelection)
: undefined,
extensions: [
keymap.of([indentWithTab, formatCompactKeyBinding]),
linterCompartment.of(createLinter()),
Expand Down Expand Up @@ -632,6 +634,14 @@
: false
}
function isValidSelection(selection: JSONEditorSelection | null, text: string): boolean {
if (!isTextSelection(selection)) {
return false
}
return selection.ranges.every((range) => range.anchor < text.length && range.head < text.length)
}
function toRichValidationError(validationError: ValidationError): RichValidationError {
const { path, message, severity } = validationError
const { line, column, from, to } = findTextLocation(normalization.escapeValue(text), path)
Expand Down

0 comments on commit 5ed8a86

Please sign in to comment.