fix: resolve crashes in DiffStreamHandler — unsafe cast and negative line numbers (#11893)
* fix: resolve crashes in DiffStreamHandler — unsafe cast and negative line numbers - Use safe cast (as?) for TextEditor in undoChanges() to prevent ClassCastException - Add early return for empty documents and clamp line numbers to prevent IndexOutOfBoundsException in initUnfinishedRangeHighlights() - Remove redundant .toList() call in rejectAll() Fixes #4267 * refactor: inline lineNum variable in initUnfinishedRangeHighlights
This commit is contained in:
parent
e8d2c4e139
commit
5a8d10fff4
1 changed files with 6 additions and 5 deletions
|
|
@ -82,7 +82,7 @@ class DiffStreamHandler(
|
|||
if (hasAcceptedOrRejectedBlock) {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val blocksToReject = diffBlocks.toList()
|
||||
blocksToReject.toList().forEach { it.handleReject() }
|
||||
blocksToReject.forEach { it.handleReject() }
|
||||
}
|
||||
} else {
|
||||
undoChanges()
|
||||
|
|
@ -265,14 +265,14 @@ class DiffStreamHandler(
|
|||
}
|
||||
|
||||
private fun initUnfinishedRangeHighlights() {
|
||||
if (editor.document.lineCount == 0) return
|
||||
|
||||
val editorUtils = EditorUtils(editor)
|
||||
val unfinishedKey = editorUtils.createTextAttributesKey("CONTINUE_DIFF_UNFINISHED_LINE", 0x20888888)
|
||||
|
||||
for (i in startLine..endLine) {
|
||||
val highlighter = editor.markupModel.addLineHighlighter(
|
||||
unfinishedKey, min(
|
||||
i, editor.document.lineCount - 1
|
||||
), HighlighterLayer.LAST
|
||||
unfinishedKey, min(i, editor.document.lineCount - 1).coerceAtLeast(0), HighlighterLayer.LAST
|
||||
)
|
||||
unfinishedHighlighters.add(highlighter)
|
||||
}
|
||||
|
|
@ -413,7 +413,8 @@ class DiffStreamHandler(
|
|||
|
||||
WriteCommandAction.runWriteCommandAction(project) {
|
||||
val undoManager = UndoManager.getInstance(project)
|
||||
val fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile) as TextEditor
|
||||
val fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile) as? TextEditor
|
||||
?: return@runWriteCommandAction
|
||||
|
||||
if (undoManager.isUndoAvailable(fileEditor)) {
|
||||
val numChanges = diffBlocks.sumOf { it.deletedLines.size + it.addedLines.size }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue