Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve the diff block logic for inline chat #3039

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ 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(
editor, wrappedComponent,
EditorEmbeddedComponentManager.Properties(
EditorEmbeddedComponentManager.ResizePolicy.none(),
null,
true,
!editor.inlayModel.getBlockElementsInRange(offset,offset).isEmpty(),
showAbove,
0,
offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Loading