Skip to content

Commit

Permalink
Fix a string-length issue with newline normalization in insertComplet…
Browse files Browse the repository at this point in the history
…ionText

FIX: Fix an issue where `insertCompletionText` would get confused about the length
of the inserted text when it contained CRLF line breaks, and create an invalid selection.

Closes codemirror/dev#1434
  • Loading branch information
marijnh committed Aug 30, 2024
1 parent 4f1734c commit a9adf23
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ export function insertCompletionText(state: EditorState, text: string, from: num
if (range != main && from != to &&
state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to))
return {range}
let lines = state.toText(text)
return {
changes: {from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text},
range: EditorSelection.cursor(range.from + fromOff + text.length)
changes: {from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: lines},
range: EditorSelection.cursor(range.from + fromOff + lines.length)
}
}),
scrollIntoView: true,
Expand Down

0 comments on commit a9adf23

Please sign in to comment.