diff --git a/src/plugins/codeeditor/gui/private/texteditor_p.cpp b/src/plugins/codeeditor/gui/private/texteditor_p.cpp index 6055199f8..b9a39627b 100644 --- a/src/plugins/codeeditor/gui/private/texteditor_p.cpp +++ b/src/plugins/codeeditor/gui/private/texteditor_p.cpp @@ -583,11 +583,10 @@ void TextEditorPrivate::updateCacheInfo(int pos, int added) q->lineIndexFromPosition(pos, &line, &index); editor.lineChanged(fileName, line, added); if (lineWidgetContainer->isVisible()) { - if (showAtLine > line && q->lines() != 1) { - if (added != q->lines() - 1) { - showAtLine += added; - showAtLine = qMax(showAtLine, 1); - } + if (showAtLine > line) { + showAtLine += added; + showAtLine = qMax(showAtLine, 1); + updateLineWidgetPosition(); } } diff --git a/src/plugins/codeeditor/gui/tabwidget.cpp b/src/plugins/codeeditor/gui/tabwidget.cpp index c64c78bfe..e0e71544e 100644 --- a/src/plugins/codeeditor/gui/tabwidget.cpp +++ b/src/plugins/codeeditor/gui/tabwidget.cpp @@ -613,14 +613,39 @@ bool TabWidget::replaceRange(const QString &fileName, const dpfservice::Edit::Ra if (auto editor = d->findEditor(fileName)) { // When using the `lineLength()` function to get the length, it is calculated in bytes. // When there are Chinese characters in the text, the length obtained is not correct. - int indexTo = range.end.column; - if (indexTo == -1) { - auto lineText = editor->text(range.end.line); - indexTo = lineText.length(); + auto lineLength = [editor](int line, bool rmN) { + auto lineText = editor->text(line); + int len = lineText.length(); + if (rmN && lineText.endsWith('\n')) + len -= 1; + return len; + }; + + editor->beginUndoAction(); + auto lineTextList = newText.split('\n'); + for (int i = 0; i < lineTextList.size(); ++i) { + int line = range.start.line + i; + int indexFrom = 0; + if (i == 0) + indexFrom = range.start.column == -1 ? 0 : range.start.column; + int indexTo = lineLength(line, true); + if (line == range.end.line && indexTo != range.end.column) + indexTo = range.end.column; + + if (i == lineTextList.size() - 1 || line == range.end.line) { + indexTo = range.end.column; + if (indexTo == -1) + indexTo = lineLength(range.end.line, false); + QStringList remainderLines; + std::copy(lineTextList.begin() + i, lineTextList.end(), std::back_inserter(remainderLines)); + editor->replaceRange(line, indexFrom, range.end.line, indexTo, remainderLines.join('\n')); + break; + } else { + editor->replaceRange(line, indexFrom, line, indexTo, lineTextList[i]); + } } - editor->replaceRange(range.start.line, range.start.column == -1 ? 0 : range.start.column, - range.end.line, indexTo, newText); + editor->endUndoAction(); return true; } diff --git a/src/plugins/codegeex/copilot.cpp b/src/plugins/codegeex/copilot.cpp index cee796a3b..30088a1b2 100644 --- a/src/plugins/codegeex/copilot.cpp +++ b/src/plugins/codegeex/copilot.cpp @@ -62,6 +62,9 @@ Copilot::Copilot(QObject *parent) completion = response; } + if (completion.endsWith('\n')) + completion.chop(1); + generatedCode = completion; completionProvider->setInlineCompletions({ completion }); emit completionProvider->finished();