Skip to content

Commit

Permalink
fix: Fix some issues of Inline Chat
Browse files Browse the repository at this point in the history
1.Fixed app crash when asking questions
2.Fix shortcut invalid issue

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Sep 30, 2024
1 parent 5b67699 commit 2fc3d88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/plugins/codeeditor/gui/private/texteditor_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 14 additions & 9 deletions src/plugins/codegeex/widgets/inlinechatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -462,7 +466,11 @@ QList<Diff> 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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2fc3d88

Please sign in to comment.