diff --git a/src/app/qt/element/QtSmartSearchBox.cpp b/src/app/qt/element/QtSmartSearchBox.cpp index 718f1c23..c0ae161b 100644 --- a/src/app/qt/element/QtSmartSearchBox.cpp +++ b/src/app/qt/element/QtSmartSearchBox.cpp @@ -536,6 +536,7 @@ void QtSmartSearchBox::updateElements() setStyleSheet(TextAccess::createFromFile("data/gui/search_view/search_element.css")->getText().c_str()); updatePlaceholder(); + hideAutoCompletions(); layoutElements(); } @@ -544,36 +545,58 @@ void QtSmartSearchBox::layoutElements() { ensurePolished(); - int x = 7; bool hasSelected = hasSelectedElements(); + QString cursorText = text(); + cursorText.resize(cursorPosition()); + + int x = 7; + int editX = x; + int cursorX = fontMetrics().width(cursorText) + x + 5; + std::vector elementX; + for (size_t i = 0; i <= m_elements.size(); i++) { if (!hasSelected && i == m_cursorIndex) { - int left, top, right, bottom; - getTextMargins(&left, &top, &right, &bottom); - setTextMargins(x - 9, top, right, bottom); + editX = x - 9; + cursorX += editX; x += fontMetrics().width(text()); } if (i < m_elements.size()) { QtQueryElement* button = m_elements[i].get(); - QSize size = button->minimumSizeHint(); - int y = (rect().height() - size.height()) / 2.0; - button->setGeometry(x, y, size.width(), size.height()); - x += size.width() + 5; + elementX.push_back(x); + x += button->minimumSizeHint().width() + 5; } } + int offsetX = 0; + if (cursorX > width()) + { + offsetX = width() - cursorX; + } + + for (size_t i = 0; i < elementX.size(); i++) + { + QtQueryElement* button = m_elements[i].get(); + QSize size = button->minimumSizeHint(); + int y = (rect().height() - size.height()) / 2.0; + button->setGeometry(elementX[i] + offsetX, y, size.width(), size.height()); + } + if (hasSelected) { setTextMargins(width() + 10, 0, 0, 0); } + else + { + QMargins margins = textMargins(); + setTextMargins(editX + offsetX, margins.top(), margins.right(), margins.bottom()); + } } - bool QtSmartSearchBox::hasSelectedElements() const { for (const std::shared_ptr element : m_elements) @@ -672,11 +695,7 @@ void QtSmartSearchBox::updatePlaceholder() void QtSmartSearchBox::clearLineEdit() { setEditText(""); - - if (completer()) - { - completer()->popup()->hide(); - } + hideAutoCompletions(); } void QtSmartSearchBox::requestAutoCompletions() const @@ -690,3 +709,11 @@ void QtSmartSearchBox::requestAutoCompletions() const MessageSearchAutocomplete(query, text().toStdString()).dispatch(); } + +void QtSmartSearchBox::hideAutoCompletions() +{ + if (completer()) + { + completer()->popup()->hide(); + } +} diff --git a/src/app/qt/element/QtSmartSearchBox.h b/src/app/qt/element/QtSmartSearchBox.h index 9ab4a1d0..aa0db204 100644 --- a/src/app/qt/element/QtSmartSearchBox.h +++ b/src/app/qt/element/QtSmartSearchBox.h @@ -82,7 +82,9 @@ private: void updatePlaceholder(); void clearLineEdit(); + void requestAutoCompletions() const; + void hideAutoCompletions(); bool m_allowTextChange; QString m_oldText; diff --git a/src/lib/data/search/SearchNode.cpp b/src/lib/data/search/SearchNode.cpp index 2880c372..74fa7d54 100644 --- a/src/lib/data/search/SearchNode.cpp +++ b/src/lib/data/search/SearchNode.cpp @@ -169,10 +169,18 @@ SearchMatch SearchNode::fuzzyMatchData(const std::string& query, const SearchNod size_t pos = 0; size_t size = 0; + const SearchNode* root = parent; std::deque nodes = getNodesToParent(parent); if (!nodes.size()) { nodes.push_back(this); + root = root->getParent(); + } + + while (root && root->getNameId()) + { + size += root->getName().size() + SearchIndex::DELIMITER.size(); + root = root->getParent(); } for (const SearchNode* node : nodes)