[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kate] addons/search: S&R: Jump to the next/previous match from the cursor not list start/end
From: Kåre Särs <kare.sars () iki ! fi>
Date: 2016-07-03 11:39:58
Message-ID: E1bJfkk-0003C3-BC () code ! kde ! org
[Download RAW message or body]
Git commit ffaa27daf9a8eacb6be09595fc9eaf230245faa3 by Kåre Särs.
Committed on 02/07/2016 at 20:39.
Pushed by sars into branch 'master'.
S&R: Jump to the next/previous match from the cursor not list start/end
M +79 -7 addons/search/plugin_search.cpp
http://commits.kde.org/kate/ffaa27daf9a8eacb6be09595fc9eaf230245faa3
diff --git a/addons/search/plugin_search.cpp b/addons/search/plugin_search.cpp
index f6644f6..94614f1 100644
--- a/addons/search/plugin_search.cpp
+++ b/addons/search/plugin_search.cpp
@@ -634,7 +634,7 @@ QTreeWidgetItem * KatePluginSearchView::rootFileItem(const \
QString &url, const Q }
QUrl fullUrl = QUrl::fromUserInput(url);
- QString path = fullUrl.isLocalFile() ? localFileDirUp (fullUrl).path() : \
fullUrl.url(); + QString path = fullUrl.isLocalFile() ? \
localFileDirUp(fullUrl).path() : fullUrl.url(); if (!path.isEmpty() && \
!path.endsWith(QLatin1Char('/'))) { path += QLatin1Char('/');
}
@@ -901,6 +901,7 @@ void KatePluginSearchView::startSearch()
clearMarks();
m_curResults->tree->clear();
+ m_curResults->tree->setCurrentItem(nullptr);
m_curResults->matches = 0;
m_ui.resultTabWidget->setTabText(m_ui.resultTabWidget->currentIndex(),
@@ -1013,6 +1014,7 @@ void KatePluginSearchView::startSearchWhileTyping()
clearMarks();
m_curResults->tree->clear();
+ m_curResults->tree->setCurrentItem(nullptr);
m_curResults->matches = 0;
QRegularExpression::PatternOptions patternOptions = (m_ui.matchCase->isChecked() \
? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); \
@@ -1094,9 +1096,6 @@ void KatePluginSearchView::searchDone() }
}
- m_curResults->tree->setCurrentItem(root);
- m_curResults->tree->setFocus(Qt::OtherFocusReason);
-
if (root) {
switch (m_ui.searchPlaceCombo->currentIndex())
{
@@ -1466,28 +1465,66 @@ void KatePluginSearchView::itemSelected(QTreeWidgetItem \
*item)
void KatePluginSearchView::goToNextMatch()
{
- bool fromFirst = false;
+ bool wrapFromFirst = false;
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!res) {
return;
}
QTreeWidgetItem *curr = res->tree->currentItem();
if (!curr) {
+ // no item has been visited -> jump to the closest match after current \
cursor position + // check if current file is in the file
curr = res->tree->topLevelItem(0);
+ while (curr && curr->data(0, ReplaceMatches::FileUrlRole).toString() != \
m_mainWindow->activeView()->document()->url().toString()) { + curr = \
res->tree->itemBelow(curr); + }
+ // now we are either in this file or !curr
+ if (curr) {
+ QTreeWidgetItem *fileBefore = curr;
+ res->tree->expandItem(curr);
+
+ int lineNr = 0;
+ int columnNr = 0;
+ if (m_mainWindow->activeView()->cursorPosition().isValid()) {
+ lineNr = m_mainWindow->activeView()->cursorPosition().line();
+ columnNr = m_mainWindow->activeView()->cursorPosition().column();
+ }
+
+ if (!curr->data(0, ReplaceMatches::ColumnRole).isValid()) {
+ curr = res->tree->itemBelow(curr);
+ };
+
+ while (curr && curr->data(0, ReplaceMatches::LineRole).toInt() <= lineNr \
&& + curr->data(0, ReplaceMatches::FileUrlRole).toString() == \
m_mainWindow->activeView()->document()->url().toString()) + {
+ if (curr->data(0, ReplaceMatches::LineRole).toInt() == lineNr &&
+ curr->data(0, ReplaceMatches::ColumnRole).toInt() > columnNr)
+ {
+ break;
+ }
+ fileBefore = curr;
+ curr = res->tree->itemBelow(curr);
+ }
+ curr = fileBefore;
+ }
+
+ if (!curr) {
+ curr = res->tree->topLevelItem(0);
+ }
}
if (!curr) return;
if (!curr->data(0, ReplaceMatches::ColumnRole).toString().isEmpty()) {
curr = res->tree->itemBelow(curr);
if (!curr) {
- fromFirst = true;
+ wrapFromFirst = true;
curr = res->tree->topLevelItem(0);
}
}
itemSelected(curr);
- if (fromFirst) {
+ if (wrapFromFirst) {
delete m_infoMessage;
const QString msg = i18n("Continuing from first match");
m_infoMessage = new KTextEditor::Message(msg, \
KTextEditor::Message::Information); @@ -1511,6 +1548,41 @@ void \
KatePluginSearchView::goToPreviousMatch() }
QTreeWidgetItem *curr = res->tree->currentItem();
+ if (!curr) {
+ // no item has been visited -> jump to the closest match before current \
cursor position + // check if current file is in the file
+ curr = res->tree->topLevelItem(0);
+ while (curr && curr->data(0, ReplaceMatches::FileUrlRole).toString() != \
m_mainWindow->activeView()->document()->url().toString()) { + curr = \
res->tree->itemBelow(curr); + }
+ // now we are either in this file or !curr
+ if (curr) {
+ res->tree->expandItem(curr);
+
+ int lineNr = 0;
+ int columnNr = 0;
+ if (m_mainWindow->activeView()->cursorPosition().isValid()) {
+ lineNr = m_mainWindow->activeView()->cursorPosition().line();
+ columnNr = m_mainWindow->activeView()->cursorPosition().column()-1;
+ }
+
+ if (!curr->data(0, ReplaceMatches::ColumnRole).isValid()) {
+ curr = res->tree->itemBelow(curr);
+ };
+
+ while (curr && curr->data(0, ReplaceMatches::LineRole).toInt() <= lineNr \
&& + curr->data(0, ReplaceMatches::FileUrlRole).toString() == \
m_mainWindow->activeView()->document()->url().toString()) + {
+ if (curr->data(0, ReplaceMatches::LineRole).toInt() == lineNr &&
+ curr->data(0, ReplaceMatches::ColumnRole).toInt() > columnNr)
+ {
+ break;
+ }
+ curr = res->tree->itemBelow(curr);
+ }
+ }
+ }
+
// go to the item above. (curr == null is not a problem)
curr = res->tree->itemAbove(curr);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic