Skip to content

Commit 8e848c6

Browse files
committed
fix(diff): handle edge case in line highlighting
Add boundary check to prevent index out of bounds when highlighting lines in the diff editor.
1 parent 695b552 commit 8e848c6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

core/src/main/kotlin/cc/unitmesh/devti/diff/DiffStreamHandler.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class DiffStreamHandler(
195195

196196
private fun initUnfinishedRangeHighlights() {
197197
for (i in startLine..endLine) {
198+
if (i >= editor.document.lineCount) {
199+
break
200+
}
201+
198202
val highlighter = editor.markupModel.addLineHighlighter(
199203
unfinishedKey, min(
200204
i, editor.document.lineCount - 1

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/DiffLangSketch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class DiffLangSketch(private val myProject: Project, private var patchContent: S
172172

173173
fun showSingleDiff(project: Project, patchContent: String, handleAccept: (() -> Unit)?) {
174174
val editorProvider = FileEditorProvider.EP_FILE_EDITOR_PROVIDER.extensionList.firstOrNull {
175-
it.javaClass.simpleName == "DiffPatchFileEditorProvider"
175+
it.javaClass.simpleName == "DiffPatchFileEditorProvider" || it.javaClass.simpleName == "DiffEditorProvider"
176176
}
177177

178178
if (editorProvider != null) {

0 commit comments

Comments
 (0)