Skip to content

Commit

Permalink
feat: [codegeex] optimized reference dialog
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Oct 28, 2024
1 parent 645610c commit 4cebe9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/plugins/codegeex/widgets/inputeditwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,22 @@ void InputEditWidgetPrivate::initEdit()
if (cursorPos > 0 && edit->document()->characterAt(cursorPos - 1) == "@")
q->popupReference();

if (referencePopup->isVisible() && !currentText.endsWith('@')) {
if (!currentText.contains('@')) {
referencePopup->hide();
} else if (!currentText.endsWith('@')) {
auto start = currentText.indexOf('@');
auto firstSpace = currentText.indexOf(' ', start); // first space after `@`
if (start == -1 || (firstSpace != -1 && cursorPos > firstSpace))
if (start == -1 || (firstSpace != -1 && cursorPos > firstSpace)) {
referencePopup->hide();
return;
}

auto filterText = currentText.mid(start + 1, cursorPos - start - 1);
model.setFilterText(filterText);
if (model.getItems().isEmpty())
referencePopup->hide();
else
referencePopup->show();
} else {
model.setFilterText("");
}
Expand Down Expand Up @@ -394,6 +402,7 @@ bool InputEditWidget::eventFilter(QObject *watched, QEvent *event)
emit handleKey(keyEvent);
return true;
case Qt::Key_Space:
case Qt::Key_Escape:
d->referencePopup->hide();
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codegeex/widgets/referencepopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void ItemModel::setFilterText(const QString &filterText)
beginResetModel();
displayItems.clear();
for (auto item : items) {
if (item.displayName.startsWith(filterText))
if (item.displayName.startsWith(filterText, Qt::CaseInsensitive) || item.type.startsWith(filterText, Qt::CaseInsensitive))
displayItems.append(item);
}
endResetModel();
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/codegeex/widgets/referencepopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class DisplayItemDelegate : public DStyledItemDelegate

struct ItemInfo
{
QString type;
QString displayName;
QString extraInfo;
QString type { "" };
QString displayName { "" };
QString extraInfo { "" };
QIcon icon;
};

Expand Down

0 comments on commit 4cebe9b

Please sign in to comment.