[PATCH 6/8] SymbolView: Avoid unneeded update of current item II

loh.tar loh.tar at googlemail.com
Sun Jul 22 14:05:43 BST 2018


...by remember the item/symbol boundaries
---
 .../symbolviewer/plugin_katesymbolviewer.cpp  | 27 +++++++++++++++++++
 addons/symbolviewer/plugin_katesymbolviewer.h |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/addons/symbolviewer/plugin_katesymbolviewer.cpp b/addons/symbolviewer/plugin_katesymbolviewer.cpp
index 5db929b51..0994b1af3 100644
--- a/addons/symbolviewer/plugin_katesymbolviewer.cpp
+++ b/addons/symbolviewer/plugin_katesymbolviewer.cpp
@@ -236,14 +236,24 @@ void KatePluginSymbolViewerView::updateCurrTreeItem()
   if (!doc) {
     return;
   }
+
   int currLine = editView->cursorPositionVirtual().line();
 
+  if (currLine >= m_firstLine && currLine <= m_lastLine && m_firstLine != m_lastLine) {
+    // Gotcha! Nothing to do
+    return;
+  }
+
   int newItemLine = 0;
   QTreeWidgetItem *newItem = nullptr;
   QTreeWidgetItem *tmp = nullptr;
+  m_firstLine = std::numeric_limits<int>::max();
+  m_lastLine  = std::numeric_limits<int>::min();
+  m_stopSearch = false;
   for (int i=0; i<m_symbols->topLevelItemCount(); i++) {
     tmp = newActveItem(newItemLine, currLine, m_symbols->topLevelItem(i));
     if (tmp) newItem = tmp;
+    if (m_stopSearch) break;
   }
 
   if (newItem) {
@@ -255,16 +265,28 @@ void KatePluginSymbolViewerView::updateCurrTreeItem()
 
 QTreeWidgetItem *KatePluginSymbolViewerView::newActveItem(int &newItemLine, int currLine, QTreeWidgetItem *item)
 {
+  if (m_stopSearch) return nullptr;
+
   QTreeWidgetItem *newItem = nullptr;
   QTreeWidgetItem *tmp = nullptr;
   int itemLine = item->data(1, Qt::DisplayRole).toInt();
 
   if ((itemLine <= currLine) && (itemLine > newItemLine)) {
     newItemLine = itemLine;
+    m_firstLine = itemLine;
+    m_lastLine  = qMax(m_lastLine, m_firstLine);
     newItem = item;
   }
 
+  if (itemLine > currLine) { // Nested "if" to avoid unclear cluttered parentheses
+    if ( ((itemLine - 1) < m_lastLine) || (m_lastLine < currLine) || (m_lastLine == m_firstLine) ) {
+      m_lastLine = itemLine - 1;
+      if (m_firstLine == m_lastLine) m_stopSearch = true;
+    }
+  }
+
   for (int i=0; i<item->childCount(); i++) {
+    if (m_stopSearch) break;
     tmp = newActveItem(newItemLine, currLine, item->child(i));
     if (tmp) newItem = tmp;
   }
@@ -336,7 +358,12 @@ void KatePluginSymbolViewerView::parseSymbols(void)
   else
     new QTreeWidgetItem(m_symbols,  QStringList(i18n("Sorry. Language not supported yet") ) );
 
+  // To by-pass the check in updateCurrTreeItem()
+  m_firstLine = std::numeric_limits<int>::max();
+  m_lastLine  = std::numeric_limits<int>::min();
+
   updateCurrTreeItem();
+
   if (m_sort->isChecked())
     m_symbols->sortItems(0, Qt::AscendingOrder);
 }
diff --git a/addons/symbolviewer/plugin_katesymbolviewer.h b/addons/symbolviewer/plugin_katesymbolviewer.h
index f748fe613..1e4e34c47 100644
--- a/addons/symbolviewer/plugin_katesymbolviewer.h
+++ b/addons/symbolviewer/plugin_katesymbolviewer.h
@@ -116,6 +116,9 @@ class KatePluginSymbolViewerView :  public QObject, public KXMLGUIClient
     QMenu       *m_popup;
     QWidget     *m_toolview;
     QTreeWidget *m_symbols;
+    int          m_firstLine;
+    int          m_lastLine;
+    bool         m_stopSearch;
     QAction *m_macro, *m_struct, *m_func, *m_sort;
     bool macro_on, struct_on, func_on;
 
-- 
2.18.0



More information about the KWrite-Devel mailing list