Skip to content

Commit 9a2c9eb

Browse files
authored
refactor: move tryAliasFastTrack into root-view-host (#1703)
1 parent 60ef177 commit 9a2c9eb

5 files changed

Lines changed: 18 additions & 31 deletions

File tree

src/server/src/qml/qml/SearchBar.qml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ Item {
285285
} else if (event.key === Qt.Key_Backspace && searchInput.text === "" && !event.isAutoRepeat && launcher.showBackButton && launcher.popOnBackspace) {
286286
launcher.goBack();
287287
event.accepted = true;
288-
} else if (event.key === Qt.Key_Space && event.modifiers === Qt.NoModifier && searchInput.text.length > 0 && launcher.commandViewHost?.tryAliasFastTrack()) {
289-
event.accepted = true;
290288
} else if (launcher.forwardKey(event.key, event.modifiers)) {
291289
if (launcher.compacted)
292290
launcher.expand();

src/server/src/qml/root-search-model.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,6 @@ const RootItem *RootSearchModel::selectedRootItem() const {
210210
return section ? section->rootItem(itemIdx) : nullptr;
211211
}
212212

213-
bool RootSearchModel::tryAliasFastTrack() {
214-
int sourceIdx = -1;
215-
int itemIdx = -1;
216-
if (!dataItemAt(selectedIndex(), sourceIdx, itemIdx)) return false;
217-
218-
auto *src = sources()[sourceIdx];
219-
const RootItem *item = nullptr;
220-
221-
if (src == m_resultsSource) {
222-
item = m_resultsSource->rootItem(itemIdx);
223-
} else if (src == m_favoritesSource) {
224-
item = m_favoritesSource->rootItem(itemIdx);
225-
}
226-
227-
if (!item || !item->supportsAliasSpaceShortcut()) return false;
228-
auto meta = m_manager->itemMetadata(item->uniqueId());
229-
if (!meta.alias || !meta.alias->starts_with(m_query)) return false;
230-
231-
activateSelected();
232-
return true;
233-
}
234-
235213
void RootSearchModel::startCalculator() {
236214
if (m_calcWatcher.isRunning()) {
237215
m_calculator->backend()->abort();

src/server/src/qml/root-search-model.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class RootSearchModel : public SectionListModel {
2727

2828
Q_INVOKABLE void setFilter(const QString &text);
2929
void setSelectedIndex(int index) override;
30-
Q_INVOKABLE bool tryAliasFastTrack();
3130

3231
const RootItem *selectedRootItem() const;
3332

src/server/src/qml/root-view-host.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,28 @@ void RootViewHost::beforeActionExecuted(const AbstractAction *action) {
4444
if (auto item = m_model->selectedRootItem()) { manager->registerVisit(item->uniqueId()); }
4545
}
4646

47+
bool RootViewHost::tryAliasFastTrack() {
48+
const auto manager = context()->services->rootItemManager();
49+
const auto item = m_model->selectedRootItem();
50+
51+
if (!item || !item->supportsAliasSpaceShortcut()) return false;
52+
53+
const auto query = context()->navigation->searchText(this).toStdString();
54+
const auto meta = manager->itemMetadata(item->uniqueId());
55+
56+
if (!meta.alias || !meta.alias->starts_with(query)) return false;
57+
58+
m_model->activateSelected();
59+
return true;
60+
}
61+
4762
bool RootViewHost::inputFilter(QKeyEvent *event) {
4863
auto manager = context()->services->rootItemManager();
4964
auto &nav = context()->navigation;
5065
auto &cfg = context()->services->config()->value();
5166

67+
if (!event->modifiers() && event->key() == Qt::Key_Space) { return tryAliasFastTrack(); }
68+
5269
// wrapped navigation is incompatible with overriding key up, so we disable history in that case
5370
const bool activatableHistory =
5471
!cfg.wrapNavigation && m_model->selectedIndex() == m_model->nextSelectableIndex(-1, 1);
@@ -100,8 +117,3 @@ void RootViewHost::beforePop() {
100117
}
101118

102119
QObject *RootViewHost::listModel() const { return m_model; }
103-
104-
bool RootViewHost::tryAliasFastTrack() {
105-
if (!m_model) return false;
106-
return m_model->tryAliasFastTrack();
107-
}

src/server/src/qml/root-view-host.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class RootViewHost : public ViewHostBase {
2121
void beforePop() override;
2222

2323
QObject *listModel() const;
24-
Q_INVOKABLE bool tryAliasFastTrack();
2524

2625
protected:
2726
bool inputFilter(QKeyEvent *) override;
2827
void refreshClock();
2928
void beforeActionExecuted(const AbstractAction *action) override;
29+
bool tryAliasFastTrack();
3030

3131
private:
3232
bool m_textChangedByHistory = false;

0 commit comments

Comments
 (0)