Skip to content

Commit 844a10f

Browse files
Kakueeendeepin-mozart
authored andcommitted
fix: [completion] Optimize intelligent completion
as title Log: Optimize intelligent completion
1 parent 4cebe9b commit 844a10f

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/plugins/codeeditor/gui/private/texteditor_p.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,10 @@ void TextEditorPrivate::updateCacheInfo(int pos, int added)
583583
q->lineIndexFromPosition(pos, &line, &index);
584584
editor.lineChanged(fileName, line, added);
585585
if (lineWidgetContainer->isVisible()) {
586-
if (showAtLine > line && q->lines() != 1) {
587-
if (added != q->lines() - 1) {
588-
showAtLine += added;
589-
showAtLine = qMax(showAtLine, 1);
590-
}
586+
if (showAtLine > line) {
587+
showAtLine += added;
588+
showAtLine = qMax(showAtLine, 1);
589+
591590
updateLineWidgetPosition();
592591
}
593592
}

src/plugins/codeeditor/gui/tabwidget.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,39 @@ bool TabWidget::replaceRange(const QString &fileName, const dpfservice::Edit::Ra
613613
if (auto editor = d->findEditor(fileName)) {
614614
// When using the `lineLength()` function to get the length, it is calculated in bytes.
615615
// When there are Chinese characters in the text, the length obtained is not correct.
616-
int indexTo = range.end.column;
617-
if (indexTo == -1) {
618-
auto lineText = editor->text(range.end.line);
619-
indexTo = lineText.length();
616+
auto lineLength = [editor](int line, bool rmN) {
617+
auto lineText = editor->text(line);
618+
int len = lineText.length();
619+
if (rmN && lineText.endsWith('\n'))
620+
len -= 1;
621+
return len;
622+
};
623+
624+
editor->beginUndoAction();
625+
auto lineTextList = newText.split('\n');
626+
for (int i = 0; i < lineTextList.size(); ++i) {
627+
int line = range.start.line + i;
628+
int indexFrom = 0;
629+
if (i == 0)
630+
indexFrom = range.start.column == -1 ? 0 : range.start.column;
631+
int indexTo = lineLength(line, true);
632+
if (line == range.end.line && indexTo != range.end.column)
633+
indexTo = range.end.column;
634+
635+
if (i == lineTextList.size() - 1 || line == range.end.line) {
636+
indexTo = range.end.column;
637+
if (indexTo == -1)
638+
indexTo = lineLength(range.end.line, false);
639+
QStringList remainderLines;
640+
std::copy(lineTextList.begin() + i, lineTextList.end(), std::back_inserter(remainderLines));
641+
editor->replaceRange(line, indexFrom, range.end.line, indexTo, remainderLines.join('\n'));
642+
break;
643+
} else {
644+
editor->replaceRange(line, indexFrom, line, indexTo, lineTextList[i]);
645+
}
620646
}
621647

622-
editor->replaceRange(range.start.line, range.start.column == -1 ? 0 : range.start.column,
623-
range.end.line, indexTo, newText);
648+
editor->endUndoAction();
624649
return true;
625650
}
626651

src/plugins/codegeex/copilot.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Copilot::Copilot(QObject *parent)
6262
completion = response;
6363
}
6464

65+
if (completion.endsWith('\n'))
66+
completion.chop(1);
67+
6568
generatedCode = completion;
6669
completionProvider->setInlineCompletions({ completion });
6770
emit completionProvider->finished();

0 commit comments

Comments
 (0)