Skip to content

Commit

Permalink
fix: Optimize symbolic interaction logic
Browse files Browse the repository at this point in the history
as title

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Jul 22, 2024
1 parent 563c6e5 commit 32d4971
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
28 changes: 12 additions & 16 deletions src/plugins/codeeditor/symbol/symbollocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SymbolLocatorPrivate
explicit SymbolLocatorPrivate(SymbolLocator *qq);

TextEditor *currentEditor();
SymbolLocatorItem createSymbolItem(const newlsp::DocumentSymbol &symbol);
SymbolLocatorItem createSymbolItem(const newlsp::SymbolInformation &info);
void createSymbolItem(const newlsp::DocumentSymbol &symbol);
void createSymbolItem(const newlsp::SymbolInformation &info);

public:
SymbolLocator *q;
Expand All @@ -50,7 +50,7 @@ TextEditor *SymbolLocatorPrivate::currentEditor()
return qobject_cast<TextEditor *>(tabWidget->currentWidget());
}

SymbolLocatorItem SymbolLocatorPrivate::createSymbolItem(const newlsp::DocumentSymbol &symbol)
void SymbolLocatorPrivate::createSymbolItem(const newlsp::DocumentSymbol &symbol)
{
SymbolLocatorItem item(q);
item.id = QUuid::createUuid().toString();
Expand All @@ -62,11 +62,15 @@ SymbolLocatorItem SymbolLocatorPrivate::createSymbolItem(const newlsp::DocumentS
item.line = symbol.range.start.line;
item.column = symbol.range.start.character;
item.icon = SymbolManager::instance()->iconFromKind(static_cast<SymbolManager::SymbolKind>(symbol.kind));
itemList.append(item);

return item;
auto children = symbol.children.value_or(QList<newlsp::DocumentSymbol>());
for (const auto &child : children) {
createSymbolItem(child);
}
}

SymbolLocatorItem SymbolLocatorPrivate::createSymbolItem(const newlsp::SymbolInformation &info)
void SymbolLocatorPrivate::createSymbolItem(const newlsp::SymbolInformation &info)
{
SymbolLocatorItem item(q);
item.id = QUuid::createUuid().toString();
Expand All @@ -75,7 +79,7 @@ SymbolLocatorItem SymbolLocatorPrivate::createSymbolItem(const newlsp::SymbolInf
item.column = info.location.range.start.character;
item.icon = SymbolManager::instance()->iconFromKind(static_cast<SymbolManager::SymbolKind>(info.kind));

return item;
itemList.append(item);
}

SymbolLocator::SymbolLocator(QObject *parent)
Expand Down Expand Up @@ -109,20 +113,12 @@ void SymbolLocator::prepareSearch(const QString &searchText)
const auto &symbolList = SymbolManager::instance()->documentSymbols(editor->getFile());
if (!symbolList.isEmpty()) {
for (const auto &symbol : symbolList) {
auto item = d->createSymbolItem(symbol);
d->itemList.append(item);

auto children = symbol.children.value_or(QList<newlsp::DocumentSymbol>());
for (const auto &child : children) {
auto item = d->createSymbolItem(child);
d->itemList.append(item);
}
d->createSymbolItem(symbol);
}
} else {
const auto &infoList = SymbolManager::instance()->symbolInformations(editor->getFile());
for (const auto &info : infoList) {
auto item = d->createSymbolItem(info);
d->itemList.append(item);
d->createSymbolItem(info);
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/plugins/codeeditor/symbol/symbolview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QFileSystemModel>
#include <QStandardItemModel>
#include <QVBoxLayout>
#include <QKeyEvent>

DWIDGET_USE_NAMESPACE

Expand Down Expand Up @@ -57,6 +58,8 @@ void SymbolViewPrivate::initUI()
view->setFrameShape(QFrame::NoFrame);
view->setEditTriggers(QTreeView::NoEditTriggers);
view->setIconSize({ 16, 16 });
view->installEventFilter(q);
view->viewport()->installEventFilter(q);

layout->addWidget(view);
}
Expand Down Expand Up @@ -101,7 +104,7 @@ void SymbolViewPrivate::handleItemClicked(const QModelIndex &index)
editor.gotoPosition(path, line + 1, col);
} else {
if (QFileInfo(path).isDir()) {
view->expand(index);
view->setExpanded(index, !view->isExpanded(index));
return;
}

Expand Down Expand Up @@ -173,3 +176,19 @@ void SymbolView::hideEvent(QHideEvent *event)
Q_EMIT hidden();
DFrame::hideEvent(event);
}

bool SymbolView::eventFilter(QObject *watched, QEvent *event)
{
if (watched == d->view && event->type() == QEvent::KeyPress) {
auto keyEvent = dynamic_cast<QKeyEvent *>(event);
if (keyEvent && (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)) {
d->handleItemClicked(d->view->currentIndex());
return true;
}
}

if (watched == d->view->viewport() && event->type() == QEvent::MouseButtonDblClick)
return true;

return DFrame::eventFilter(watched, event);
}
1 change: 1 addition & 0 deletions src/plugins/codeeditor/symbol/symbolview.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SymbolView : public DTK_WIDGET_NAMESPACE::DFrame

protected:
void hideEvent(QHideEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;

private:
SymbolViewPrivate *const d;
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/find/findplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ void FindPlugin::registerToSidebar()
{
QAction *action = new QAction(MWNA_ADVANCEDSEARCH, this);
action->setIcon(QIcon::fromTheme("search"));
windowService->addNavigationItem(new AbstractAction(action), Priority::highest);
auto actionImpl = new AbstractAction(action);
windowService->addNavigationItem(actionImpl, Priority::highest);

advSearchWidget = new AdvancedSearchWidget;
windowService->registerWidget(MWNA_ADVANCEDSEARCH, new AbstractWidget(advSearchWidget));
windowService->setDockHeaderName(MWNA_ADVANCEDSEARCH, tr("ADVANCED SEARCH"));
windowService->bindWidgetToNavigation(MWNA_ADVANCEDSEARCH, actionImpl);
advSearchWidget->initOperator();

connect(action, &QAction::triggered, this, &FindPlugin::switchToSearch, Qt::DirectConnection);
Expand Down

0 comments on commit 32d4971

Please sign in to comment.