]> git.lyx.org Git - features.git/commitdiff
Do not change outliner tree depth when not appropriate
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 22 Feb 2023 13:23:04 +0000 (14:23 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 22 Feb 2023 13:23:04 +0000 (14:23 +0100)
This fixes expansion/collapsing on double-click (#12672)

src/frontends/qt/TocWidget.cpp
src/frontends/qt/TocWidget.h

index fcbd605848125e64840138b116e1a1ecb860fc7f..ef1a28936eaeba3d158467b052e625c7a0ca7e9b 100644 (file)
@@ -47,8 +47,8 @@ namespace lyx {
 namespace frontend {
 
 TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
-       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view),
-         timer_(new QTimer(this))
+       : QWidget(parent), depth_(0), persistent_(false), keep_expanded_(false),
+         gui_view_(gui_view), timer_(new QTimer(this))
 {
        setupUi(this);
 
@@ -263,7 +263,8 @@ void TocWidget::on_tocTV_activated(QModelIndex const & index)
 
 void TocWidget::on_tocTV_pressed(QModelIndex const & index)
 {
-
+       DocIterator const & dit = gui_view_.documentBufferView()->cursor();
+       keep_expanded_ = gui_view_.tocModels().currentIndex(current_type_, dit) == index;
        Qt::MouseButtons const button = QApplication::mouseButtons();
        if (button & Qt::LeftButton) {
                goTo(index);
@@ -273,6 +274,12 @@ void TocWidget::on_tocTV_pressed(QModelIndex const & index)
 }
 
 
+void TocWidget::on_tocTV_doubleClicked(QModelIndex const &)
+{
+       keep_expanded_ = true;
+}
+
+
 void TocWidget::goTo(QModelIndex const & index)
 {
        LYXERR(Debug::GUI, "goto " << index.row()
@@ -492,7 +499,7 @@ void TocWidget::updateView()
        // Expensive operations are on a timer.  We finish the update immediately
        // for sparse edition actions, i.e. there was no edition/cursor movement
        // recently, then every 300ms.
-       if (!timer_->isActive()) {
+       if (!timer_->isActive() && !keep_expanded_) {
                finishUpdateView();
                timer_->start(300);
        }
@@ -512,8 +519,9 @@ void TocWidget::finishUpdateView()
        // text and moving with arrows. For bigger operations, this is negligible,
        // and outweighted by TocModels::reset() anyway.
        if (canNavigate()) {
-               if (!persistent_)
+               if (!persistent_ && !keep_expanded_)
                        setTreeDepth(depth_);
+               keep_expanded_ = false;
                persistentCB->setChecked(persistent_);
                // select the item at current cursor location
                if (gui_view_.documentBufferView()) {
index 2838adbee9e7cacb7733cdfc66c6e0b0548566f1..079fd24deb3e3dbab9b8ae231147d307cd5b7f48 100644 (file)
@@ -69,6 +69,7 @@ protected Q_SLOTS:
 
        void on_tocTV_activated(QModelIndex const &);
        void on_tocTV_pressed(QModelIndex const &);
+       void on_tocTV_doubleClicked(QModelIndex const &);
        void on_updateTB_clicked();
        void on_sortCB_stateChanged(int state);
        void on_persistentCB_stateChanged(int state);
@@ -115,6 +116,8 @@ private:
        int depth_;
        /// persistence of uncollapsed nodes in toc view
        bool persistent_;
+       /// keep uncollapsed nodes in this event
+       bool keep_expanded_;
        ///
        GuiView & gui_view_;
        // Timer for scheduling expensive update operations