]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/TocWidget.cpp
Show suggestions containing the input in the command buffer
[features.git] / src / frontends / qt / TocWidget.cpp
index 8e32774d017dc15fd7d2f6c4b2d94a8e2570ebc2..573e232993d80705f92e33134343f8b70984d752 100644 (file)
@@ -346,9 +346,8 @@ void TocWidget::setTreeDepth(int depth)
 }
 
 
-void TocWidget::on_typeCO_currentIndexChanged(int index)
+void TocWidget::on_typeCO_activated(int index)
 {
-
        if (index == -1)
                return;
        current_type_ = typeCO->itemData(index).toString();
@@ -366,7 +365,7 @@ void TocWidget::outline(FuncCode func_code)
 
        //if another window is active, this attempt will fail,
        //but it will work at least for the second attempt
-       gui_view_.activateWindow(); 
+       gui_view_.activateWindow();
 
        enableControls(false);
        goTo(list[0]);
@@ -380,7 +379,22 @@ void TocWidget::sendDispatch(FuncRequest fr)
 {
 
        fr.setViewOrigin(&gui_view_);
+       GuiWorkArea * old_wa = gui_view_.currentWorkArea();
+       GuiWorkArea * doc_wa = gui_view_.currentMainWorkArea();
+       /* The ToC command should be dispatched to the document work area,
+        * not the Adv. Find&Replace (which is the only other know
+        * possibility.
+        */
+       if (doc_wa != nullptr && doc_wa != old_wa)
+               gui_view_.setCurrentWorkArea(doc_wa);
        DispatchResult const & dr = dispatch(fr);
+       /* If the current workarea has not explicitely changed, and the
+        * original one is still visible, let's reset it.
+        */
+       if (gui_view_.currentWorkArea() == doc_wa
+            && gui_view_.hasVisibleWorkArea(old_wa)
+            && doc_wa != old_wa)
+               gui_view_.setCurrentWorkArea(old_wa);
        if (dr.error())
                gui_view_.message(dr.message());
 }
@@ -523,8 +537,13 @@ void TocWidget::filterContents()
 
        QModelIndexList indices = tocTV->model()->match(
                tocTV->model()->index(0, 0),
-               Qt::DisplayRole, "*", -1,
-               Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive));
+               Qt::DisplayRole, ".*", -1,
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+               Qt::MatchFlags(Qt::MatchRegularExpression|Qt::MatchRecursive));
+#else
+               // deprecated in Qt 5.15.
+               Qt::MatchFlags(Qt::MatchRegExp|Qt::MatchRecursive));
+#endif
 
        bool const show_active =
                activeFilterCO->currentIndex() != 2;
@@ -532,11 +551,11 @@ void TocWidget::filterContents()
                activeFilterCO->currentIndex() != 1;
 
        int size = indices.size();
+       QString const matchstring = filter_ ? filter_->text() : QString();
        for (int i = 0; i < size; i++) {
                QModelIndex index = indices[i];
-               bool matches =
-                       index.data().toString().contains(
-                               filter_->text(), Qt::CaseInsensitive);
+               bool matches = index.data().toString().contains(
+                                       matchstring, Qt::CaseInsensitive);
                TocItem const & item =
                        gui_view_.tocModels().currentItem(current_type_, index);
                matches &= (show_active && item.isOutput()) || (show_inactive && !item.isOutput());