Skip to content

Commit

Permalink
fix: prevent negative offset in caret movement
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Jan 6, 2025
1 parent 89e59e2 commit 81615f7
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.SwingUtilities
import kotlin.math.abs
import kotlin.math.max

class CodeSuggestionDiffViewer(
request: DiffRequest,
Expand Down Expand Up @@ -223,7 +224,7 @@ class CodeSuggestionDiffViewer(
val previousChar = document.getText(TextRange(changeEndOffset - 1, changeEndOffset))
val offset = if (previousChar == "\n") changeEndOffset - 1 else changeEndOffset

mainEditor.caretModel.moveToOffset(offset)
mainEditor.caretModel.moveToOffset(max(offset, 0))

val offsetPosition = mainEditor.offsetToXY(offset)
val offsetVisible = mainEditor.scrollingModel.visibleArea.contains(offsetPosition)
Expand Down

0 comments on commit 81615f7

Please sign in to comment.