mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
Display full replaced text and add comment about replacement
This commit is contained in:
parent
4d16c5da0b
commit
1dea2f4ae0
@ -172,18 +172,31 @@ LLMSuggestion::LLMSuggestion(
|
|||||||
|
|
||||||
int cursorPositionInBlock = cursor.positionInBlock();
|
int cursorPositionInBlock = cursor.positionInBlock();
|
||||||
|
|
||||||
QString rightText = blockText.mid(cursorPositionInBlock);
|
QString displayText;
|
||||||
|
|
||||||
if (!data.text.contains('\n')) {
|
if (!data.text.contains('\n')) {
|
||||||
|
QString rightText = blockText.mid(cursorPositionInBlock);
|
||||||
QString processedRightText = mergeWithRightText(data.text, rightText);
|
QString processedRightText = mergeWithRightText(data.text, rightText);
|
||||||
processedRightText = processedRightText.mid(data.text.length());
|
processedRightText = processedRightText.mid(data.text.length());
|
||||||
QString displayText = blockText.left(cursorPositionInBlock) + data.text
|
displayText = blockText.left(cursorPositionInBlock) + data.text + processedRightText;
|
||||||
+ processedRightText;
|
|
||||||
replacementDocument()->setPlainText(displayText);
|
|
||||||
} else {
|
} else {
|
||||||
QString displayText = blockText.left(cursorPositionInBlock) + data.text;
|
int toReplace = linesToReplace(data.text, cursor);
|
||||||
replacementDocument()->setPlainText(displayText);
|
if (toReplace < 2) {
|
||||||
|
displayText = blockText.left(cursorPositionInBlock) + data.text;
|
||||||
|
} else {
|
||||||
|
QTextCursor lastLineCursor = cursor;
|
||||||
|
lastLineCursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor, toReplace);
|
||||||
|
lastLineCursor.select(QTextCursor::LineUnderCursor);
|
||||||
|
QString lastExistingLine = lastLineCursor.selectedText();
|
||||||
|
|
||||||
|
QString lastSuggestedLine = data.text.mid(data.text.lastIndexOf('\n') + 1);
|
||||||
|
|
||||||
|
QString tail = existingTailToKeep(lastSuggestedLine, lastExistingLine);
|
||||||
|
|
||||||
|
displayText = blockText.left(cursorPositionInBlock) + data.text + tail
|
||||||
|
+ QString("\n(replaces %1 lines)").arg(toReplace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
replacementDocument()->setPlainText(displayText);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LLMSuggestion::applyWord(TextEditor::TextEditorWidget *widget)
|
bool LLMSuggestion::applyWord(TextEditor::TextEditorWidget *widget)
|
||||||
|
Loading…
Reference in New Issue
Block a user