Skip to content

Commit

Permalink
fixed crash when lsp sends invalid cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Mar 18, 2024
1 parent 5959262 commit 9fb9a7e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/text/text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ proc lspRangeToSelection*(self: TextDocument, `range`: lsp_types.Range): Selecti
return ((`range`.start.line, firstColumn), (`range`.`end`.line, lastColumn))

proc runeCursorToCursor*(self: TextDocument, cursor: CursorT[RuneIndex]): Cursor =
if cursor.line > self.lines.high or cursor.line > self.lines.high:
if cursor.line < 0 or cursor.line > self.lines.high:
return (0, 0)

return (cursor.line, self.lines[cursor.line].runeOffset(cursor.column))
return (cursor.line, self.lines[cursor.line].runeOffset(max(0.RuneIndex, cursor.column)))

proc runeSelectionToSelection*(self: TextDocument, cursor: SelectionT[RuneIndex]): Selection =
return (self.runeCursorToCursor(cursor.first), self.runeCursorToCursor(cursor.last))
Expand Down

0 comments on commit 9fb9a7e

Please sign in to comment.