From 2fc3d885d6cb82a1764144f962d9d8a3d0b29a34 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 30 Sep 2024 11:44:08 +0800 Subject: [PATCH] fix: Fix some issues of Inline Chat 1.Fixed app crash when asking questions 2.Fix shortcut invalid issue Log: fix issue --- .../codeeditor/gui/private/texteditor_p.cpp | 6 +++++ .../codegeex/widgets/inlinechatwidget.cpp | 23 +++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/plugins/codeeditor/gui/private/texteditor_p.cpp b/src/plugins/codeeditor/gui/private/texteditor_p.cpp index f0dad5e7e..21a3e930f 100644 --- a/src/plugins/codeeditor/gui/private/texteditor_p.cpp +++ b/src/plugins/codeeditor/gui/private/texteditor_p.cpp @@ -602,6 +602,12 @@ void TextEditorPrivate::onModified(int pos, int mtype, const QString &text, int if (eolStr.isEmpty() || !cpCache.second.contains(eolStr)) cpCache.first += added; } + + // update eolannotation line + for (auto it = eOLAnnotationRecords.begin(); it != eOLAnnotationRecords.end(); ++it) { + if (it.value() >= line) + it.value() += added; + } } if (mtype & TextEditor::SC_MOD_INSERTTEXT) { diff --git a/src/plugins/codegeex/widgets/inlinechatwidget.cpp b/src/plugins/codegeex/widgets/inlinechatwidget.cpp index bd8a42073..309feef15 100644 --- a/src/plugins/codegeex/widgets/inlinechatwidget.cpp +++ b/src/plugins/codegeex/widgets/inlinechatwidget.cpp @@ -335,14 +335,18 @@ void InlineChatWidgetPrivate::handleAskFinished(const QString &msgID, const QStr setState(QuestionComplete); } else if (state == SubmitStart && event == "finish") { // Extract the code block in `response` + QString codePart; QRegularExpression regex(R"(```\w*\n((.*\n)*.*)\n```)"); QRegularExpressionMatch match = regex.match(response); - if (!match.hasMatch()) { + if (match.hasMatch()) + codePart = match.captured(1); + + if (codePart.isEmpty()) { setState(Original); return; } - processGeneratedData(match.captured(1)); + processGeneratedData(codePart); setState(SubmitComplete); } } @@ -462,7 +466,11 @@ QList InlineChatWidgetPrivate::diffText(const QString &str1, const QString void InlineChatWidgetPrivate::processGeneratedData(const QString &data) { chatInfo.operationRange.clear(); - chatInfo.diffList = diffText(chatInfo.originalText, data); + if (chatInfo.originalText.isEmpty()) + chatInfo.diffList << Diff { INSERT, data }; + else + chatInfo.diffList = diffText(chatInfo.originalText, data); + int startLine = chatInfo.originalRange.start.line; int endLine = 0; QString tempText; @@ -612,12 +620,6 @@ void InlineChatWidget::showEvent(QShowEvent *e) void InlineChatWidget::keyPressEvent(QKeyEvent *e) { switch (e->modifiers()) { - case Qt::ControlModifier: - if (e->key() == Qt::Key_Backspace && d->stopBtn->isVisible()) { - d->handleStop(); - return; - } - break; case Qt::NoModifier: if (e->key() == Qt::Key_Escape) { d->handleReject(); @@ -672,6 +674,9 @@ bool InlineChatWidget::eventFilter(QObject *obj, QEvent *e) if (d->rejectBtn->isVisible()) { d->handleReject(); return true; + } else if (d->stopBtn->isVisible()) { + d->handleStop(); + return true; } break; default: