ui: Tab in search completes up to next ::, Delete erases to last ::
bug id = 133
This commit is contained in:
@@ -177,6 +177,17 @@ bool HierarchyCache::isChildOfVisibleNodeOrInvisible(Id nodeId) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HierarchyCache::nodeHasChildren(Id nodeId) const
|
||||
{
|
||||
HierarchyNode* node = getNode(nodeId);
|
||||
if (node)
|
||||
{
|
||||
return node->getChildren().size();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
HierarchyCache::HierarchyNode* HierarchyCache::getNode(Id nodeId) const
|
||||
{
|
||||
std::map<Id, std::shared_ptr<HierarchyNode>>::const_iterator it = m_nodes.find(nodeId);
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
void addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds) const;
|
||||
|
||||
bool isChildOfVisibleNodeOrInvisible(Id nodeId) const;
|
||||
bool nodeHasChildren(Id nodeId) const;
|
||||
|
||||
private:
|
||||
class HierarchyNode
|
||||
|
||||
@@ -589,6 +589,11 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
const StorageNode& node = storageNodesMap[elementId];
|
||||
match.nameHierarchies.push_back(NameHierarchy::deserialize(node.serializedName));
|
||||
|
||||
if (!match.hasChildren)
|
||||
{
|
||||
match.hasChildren = m_hierarchyCache.nodeHasChildren(node.id);
|
||||
}
|
||||
|
||||
if (!firstNode)
|
||||
{
|
||||
firstNode = &node;
|
||||
|
||||
@@ -91,6 +91,7 @@ SearchMatch::CommandType SearchMatch::getCommandType(const std::string& name)
|
||||
SearchMatch::SearchMatch()
|
||||
: typeName("")
|
||||
, searchType(SEARCH_NONE)
|
||||
, hasChildren(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -98,6 +99,7 @@ SearchMatch::SearchMatch(const std::string& query)
|
||||
: text(query)
|
||||
, typeName("")
|
||||
, searchType(SEARCH_NONE)
|
||||
, hasChildren(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ struct SearchMatch
|
||||
std::vector<size_t> indices;
|
||||
|
||||
std::vector<NameHierarchy> nameHierarchies;
|
||||
|
||||
bool hasChildren;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
std::string QtSmartSearchBox::s_delimiter = "::";
|
||||
|
||||
QtSearchElement::QtSearchElement(const QString& text, QWidget* parent)
|
||||
: QPushButton(text, parent)
|
||||
{
|
||||
@@ -144,7 +146,16 @@ bool QtSmartSearchBox::event(QEvent *event)
|
||||
{
|
||||
if (m_completer->popup()->isVisible())
|
||||
{
|
||||
addMatchAndUpdate(m_highlightedMatch);
|
||||
if (m_highlightedMatch.hasChildren)
|
||||
{
|
||||
setEditText((m_highlightedMatch.text + s_delimiter).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
setEditText(m_highlightedMatch.text.c_str());
|
||||
}
|
||||
|
||||
requestAutoCompletions();
|
||||
}
|
||||
else if (m_allowMultipleElements)
|
||||
{
|
||||
@@ -193,7 +204,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event->matches(QKeySequence::Delete))
|
||||
else if (event->matches(QKeySequence::Delete) || event->matches(QKeySequence::DeleteStartOfWord))
|
||||
{
|
||||
if (hasSelectedElements())
|
||||
{
|
||||
@@ -206,6 +217,27 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
|
||||
deleteSelectedElements();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> names = utility::splitToVector(text().toStdString(), s_delimiter);
|
||||
if (names.back() == "")
|
||||
{
|
||||
names.pop_back();
|
||||
}
|
||||
|
||||
if (names.size() < 2)
|
||||
{
|
||||
setEditText("");
|
||||
}
|
||||
else
|
||||
{
|
||||
names.back() = "";
|
||||
setEditText(utility::join(names, s_delimiter).c_str());
|
||||
}
|
||||
|
||||
requestAutoCompletions();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event->matches(QKeySequence::MoveToPreviousChar))
|
||||
{
|
||||
@@ -863,9 +895,16 @@ void QtSmartSearchBox::clearLineEdit()
|
||||
hideAutoCompletions();
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::requestAutoCompletions() const
|
||||
void QtSmartSearchBox::requestAutoCompletions()
|
||||
{
|
||||
MessageSearchAutocomplete(text().toStdString()).dispatch();
|
||||
if (text().size())
|
||||
{
|
||||
MessageSearchAutocomplete(text().toStdString()).dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
hideAutoCompletions();
|
||||
}
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::hideAutoCompletions()
|
||||
|
||||
@@ -66,6 +66,8 @@ private slots:
|
||||
void onElementSelected(QtSearchElement* element);
|
||||
|
||||
private:
|
||||
static std::string s_delimiter;
|
||||
|
||||
void moveCursor(int offset);
|
||||
void moveCursorTo(int goal);
|
||||
|
||||
@@ -90,7 +92,7 @@ private:
|
||||
void updatePlaceholder();
|
||||
void clearLineEdit();
|
||||
|
||||
void requestAutoCompletions() const;
|
||||
void requestAutoCompletions();
|
||||
void hideAutoCompletions();
|
||||
|
||||
std::deque<SearchMatch> getMatchesForInput(const std::string& text) const;
|
||||
|
||||
Reference in New Issue
Block a user