ui: Fixed search related issues
* select elements when clicking into search bar * fixed crash and single file mode clearing when fulltext search yields no results
This commit is contained in:
@@ -402,6 +402,11 @@ void CodeController::expandVisibleSnippets(std::vector<CodeSnippetParams>* snipp
|
||||
{
|
||||
TRACE();
|
||||
|
||||
if (!snippets->size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool inListMode = getView()->isInListMode();
|
||||
|
||||
size_t filesToExpand = inListMode ? std::min(int(snippets->size()), 3) : 1;
|
||||
|
||||
@@ -76,9 +76,14 @@ QAbstractScrollArea* QtCodeFileSingle::getScrollArea()
|
||||
return m_area;
|
||||
}
|
||||
|
||||
void QtCodeFileSingle::clearCache()
|
||||
void QtCodeFileSingle::clearFile()
|
||||
{
|
||||
setFileData(FileData());
|
||||
}
|
||||
|
||||
void QtCodeFileSingle::clearCache()
|
||||
{
|
||||
clearFile();
|
||||
|
||||
m_fileDatas.clear();
|
||||
m_filePaths.clear();
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent = nullptr);
|
||||
virtual ~QtCodeFileSingle();
|
||||
|
||||
void clearFile();
|
||||
void clearCache();
|
||||
|
||||
// QtCodeNaviatebale implementation
|
||||
|
||||
@@ -257,6 +257,11 @@ void QtCodeNavigator::clearCodeSnippets()
|
||||
m_singleHasNewFile = false;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::clearFile()
|
||||
{
|
||||
m_single->clearFile();
|
||||
}
|
||||
|
||||
void QtCodeNavigator::clearCaches()
|
||||
{
|
||||
m_single->clearCache();
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
void clear();
|
||||
void clearCodeSnippets();
|
||||
void clearFile();
|
||||
void clearCaches();
|
||||
|
||||
const std::set<Id>& getCurrentActiveTokenIds() const;
|
||||
|
||||
@@ -88,6 +88,7 @@ QtSmartSearchBox::QtSmartSearchBox(QWidget* parent)
|
||||
, m_cursorIndex(0)
|
||||
, m_shiftKeyDown(false)
|
||||
, m_mousePressed(false)
|
||||
, m_ignoreNextMousePress(false)
|
||||
{
|
||||
m_highlightRect = new QWidget(this);
|
||||
m_highlightRect->setGeometry(0, 0, 0, 0);
|
||||
@@ -150,17 +151,6 @@ void QtSmartSearchBox::setMatches(const std::vector<SearchMatch>& matches)
|
||||
void QtSmartSearchBox::setFocus()
|
||||
{
|
||||
QLineEdit::setFocus(Qt::ShortcutFocusReason);
|
||||
|
||||
if (text().size() == 1 && text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER))
|
||||
{
|
||||
setEditText("");
|
||||
}
|
||||
else
|
||||
{
|
||||
editTextToElement();
|
||||
selectAllElementsWith(true);
|
||||
layoutElements();
|
||||
}
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::findFulltext()
|
||||
@@ -214,6 +204,32 @@ void QtSmartSearchBox::resizeEvent(QResizeEvent* event)
|
||||
layoutElements();
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::focusInEvent(QFocusEvent* event)
|
||||
{
|
||||
QLineEdit::focusInEvent(event);
|
||||
|
||||
if (event->reason() != Qt::MouseFocusReason && event->reason() != Qt::ShortcutFocusReason)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (text().size() == 1 && text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER))
|
||||
{
|
||||
setEditText("");
|
||||
}
|
||||
else
|
||||
{
|
||||
editTextToElement();
|
||||
selectAllElementsWith(true);
|
||||
layoutElements();
|
||||
}
|
||||
|
||||
if (event->reason() == Qt::MouseFocusReason)
|
||||
{
|
||||
m_ignoreNextMousePress = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
m_shiftKeyDown = event->modifiers() & Qt::ShiftModifier;
|
||||
@@ -436,14 +452,24 @@ void QtSmartSearchBox::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QLineEdit::mousePressEvent(event);
|
||||
|
||||
m_mousePressed = true;
|
||||
m_mouseX = event->x();
|
||||
if (!m_ignoreNextMousePress)
|
||||
{
|
||||
m_mousePressed = true;
|
||||
m_mouseX = event->x();
|
||||
}
|
||||
|
||||
m_ignoreNextMousePress = false;
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QLineEdit::mouseReleaseEvent(event);
|
||||
|
||||
if (!m_mousePressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_mousePressed = false;
|
||||
|
||||
if (abs(event->x() - m_mouseX) > 5)
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
protected:
|
||||
virtual bool event(QEvent *event);
|
||||
virtual void resizeEvent(QResizeEvent* event);
|
||||
virtual void focusInEvent(QFocusEvent* event);
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* event);
|
||||
virtual void keyReleaseEvent(QKeyEvent* event);
|
||||
|
||||
@@ -112,6 +114,7 @@ private:
|
||||
bool m_shiftKeyDown;
|
||||
bool m_mousePressed;
|
||||
int m_mouseX;
|
||||
bool m_ignoreNextMousePress;
|
||||
|
||||
QWidget* m_highlightRect;
|
||||
QtAutocompletionList* m_completer;
|
||||
|
||||
@@ -72,6 +72,11 @@ void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets
|
||||
|
||||
m_widget->setActiveTokenIds(params.activeTokenIds);
|
||||
m_widget->setErrorInfos(params.errorInfos);
|
||||
|
||||
if (!snippets.size())
|
||||
{
|
||||
m_widget->clearFile();
|
||||
}
|
||||
}
|
||||
|
||||
bool addedFiles = false;
|
||||
|
||||
Reference in New Issue
Block a user