refactor: Improve the diff block logic for inline chat

This commit is contained in:
liuk 2024-11-22 20:46:43 +08:00
parent 28c84c8211
commit b4000e1e8e
2 changed files with 4 additions and 3 deletions

View file

@ -51,7 +51,7 @@ class EditorComponentInlaysManager(val editor: EditorImpl, private val onlyOneIn
}
val wrappedComponent = ComponentWrapper(component)
val offset = editor.document.getLineEndOffset(lineIndex)
val offset = editor.document.getLineStartOffset(lineIndex)
return EditorEmbeddedComponentManager.getInstance()
.addComponent(
@ -59,7 +59,7 @@ class EditorComponentInlaysManager(val editor: EditorImpl, private val onlyOneIn
EditorEmbeddedComponentManager.Properties(
EditorEmbeddedComponentManager.ResizePolicy.none(),
null,
true,
!editor.inlayModel.getBlockElementsInRange(offset,offset).isEmpty(),
showAbove,
0,
offset

View file

@ -59,11 +59,12 @@ class VerticalDiffBlock(
fun deleteLineAt(line: Int) {
val startOffset = editor.document.getLineStartOffset(line)
val endOffset = editor.document.getLineEndOffset(line) + 1
val endOffset = min(editor.document.getLineEndOffset(line) + 1, editor.document.textLength)
val deletedText = editor.document.getText(TextRange(startOffset, endOffset))
deletedLines.add(deletedText.trimEnd())
// Unable to ensure that text length has not changed, so we need to get it again
editor.document.deleteString(startOffset, min(endOffset, editor.document.textLength))
}