[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kate
From:       Bernhard Beschow <bbeschow () cs ! tu-berlin ! de>
Date:       2010-10-28 11:44:51
Message-ID: 20101028114451.90F1EAC89C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1190633 by beschow:

also add history in incremental search mode

 M  +14 -7     search/katesearchbar.cpp  
 M  +36 -0     tests/searchbar_test.cpp  
 M  +2 -0      tests/searchbar_test.h  


--- trunk/KDE/kdelibs/kate/search/katesearchbar.cpp #1190632:1190633
@@ -244,9 +244,11 @@
 void KateSearchBar::findNext() {
     const bool found = find();
 
-    if (found && m_powerUi != NULL) {
+    if (found) {
+        QComboBox *combo = m_powerUi != 0 ? m_powerUi->pattern : m_incUi->pattern;
+
         // Add to search history
-        addCurrentTextToHistory(m_powerUi->pattern);
+        addCurrentTextToHistory(combo);
     }
 }
 
@@ -255,9 +257,11 @@
 void KateSearchBar::findPrevious() {
     const bool found = find(SearchBackward);
 
-    if (found && m_powerUi != NULL) {
+    if (found) {
+        QComboBox *combo = m_powerUi != 0 ? m_powerUi->pattern : m_incUi->pattern;
+
         // Add to search history
-        addCurrentTextToHistory(m_powerUi->pattern);
+        addCurrentTextToHistory(combo);
     }
 }
 
@@ -654,11 +658,11 @@
 void KateSearchBar::addCurrentTextToHistory(QComboBox * combo) {
     const QString text = combo->currentText();
     const int index = combo->findText(text);
-    if (index != -1) {
+
+    if (index > 0)
         combo->removeItem(index);
-    }
+    if (index != 0)
     combo->insertItem(0, text);
-    combo->setCurrentIndex(0);
 }
 
 
@@ -1255,9 +1259,11 @@
         m_layout->addWidget(m_widget);
 
         // Bind to shared history models
+        m_powerUi->pattern->setDuplicatesEnabled(false);
         m_powerUi->pattern->setInsertPolicy(QComboBox::InsertAtTop);
         m_powerUi->pattern->setMaxCount(m_config->maxHistorySize());
         m_powerUi->pattern->setModel(m_config->patternHistoryModel());
+        m_powerUi->replacement->setDuplicatesEnabled(false);
         m_powerUi->replacement->setInsertPolicy(QComboBox::InsertAtTop);
         m_powerUi->replacement->setMaxCount(m_config->maxHistorySize());
         m_powerUi->replacement->setModel(m_config->replacementHistoryModel());
@@ -1418,6 +1424,7 @@
         // Focus proxy
         centralWidget()->setFocusProxy(m_incUi->pattern);
 
+        m_incUi->pattern->setDuplicatesEnabled(false);
         m_incUi->pattern->setInsertPolicy(QComboBox::InsertAtTop);
         m_incUi->pattern->setMaxCount(m_config->maxHistorySize());
         m_incUi->pattern->setModel(m_config->patternHistoryModel());
--- trunk/KDE/kdelibs/kate/tests/searchbar_test.cpp #1190632:1190633
@@ -72,6 +72,42 @@
 }
 
 
+void SearchBarTest::testFindNextIncremental()
+{
+  KateDocument doc(false, false, false);
+  doc.setText("a a a b b");
+
+  KateView view(&doc, 0);
+  KateViewConfig config(&view);
+
+  KateSearchBar bar(false, &view, &config);
+
+  bar.setSearchPattern("b");
+
+  QCOMPARE(view.selectionRange(), Range(0, 6, 0, 7));
+
+  bar.findNext();
+
+  QCOMPARE(view.selectionRange(), Range(0, 8, 0, 9));
+
+  bar.setSearchPattern("a");
+
+  QCOMPARE(view.selectionRange(), Range(0, 0, 0, 1));
+
+  bar.findNext();
+
+  QCOMPARE(view.selectionRange(), Range(0, 2, 0, 3));
+
+  bar.findNext();
+
+  QCOMPARE(view.selectionRange(), Range(0, 4, 0, 5));
+
+  bar.findNext();
+
+  QCOMPARE(view.selectionRange(), Range(0, 0, 0, 1));
+}
+
+
 void SearchBarTest::testSetMatchCaseIncremental()
 {
   KateDocument doc(false, false, false);
--- trunk/KDE/kdelibs/kate/tests/searchbar_test.h #1190632:1190633
@@ -31,6 +31,8 @@
   ~SearchBarTest();
 
 private Q_SLOTS:
+  void testFindNextIncremental();
+
   void testSetMatchCaseIncremental();
 
   void testSetMatchCasePower();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic