Summary: | Find previous does nothing sometimes | ||
---|---|---|---|
Product: | [Applications] kate | Reporter: | Brian DeRocher <brian.derocher> |
Component: | part | Assignee: | KWrite Developers <kwrite-bugs-null> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | mkaufmann |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Debian testing | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: |
sample text to distinguish working and broken cases
Possible patch |
Description
Brian DeRocher
2006-03-08 22:54:12 UTC
Created attachment 15018 [details]
sample text to distinguish working and broken cases
Created attachment 16905 [details]
Possible patch
This patch fixes the problem by doing two things:
* When searching backwards, and there is a selection, start search at the start
of the selection instead of at the cursor (because of how the previous match is
highlighted.)
* Start one character before the starting point, to avoid hitting the previous
match again.
I do admit, this doesn't feel very clean. Some input would be appreciated.
SVN commit 559493 by kling: Made backward searches work a lot better. BUG: 123307 BUG: 130252 M +26 -4 katesearch.cpp M +1 -1 katesearch.h --- branches/KDE/3.5/kdelibs/kate/part/katesearch.cpp #559492:559493 @@ -141,7 +141,7 @@ s.selEnd = KateTextCursor( m_view->selEndLine(), m_view->selEndCol() ); s.cursor = s.flags.backward ? s.selEnd : s.selBegin; } else { - s.cursor = getCursor(); + s.cursor = getCursor( searchFlags ); } s.wrappedEnd = s.cursor; @@ -207,7 +207,7 @@ s.selEnd = KateTextCursor( m_view->selEndLine(), m_view->selEndCol() ); s.cursor = s.flags.backward ? s.selEnd : s.selBegin; } else { - s.cursor = getCursor(); + s.cursor = getCursor( searchFlags ); } s.wrappedEnd = s.cursor; @@ -236,8 +236,8 @@ searchFlags.fromBeginning = false; searchFlags.prompt = true; // ### why is the above assignment there? - s.cursor = getCursor(); + s.cursor = getCursor( searchFlags ); search( searchFlags ); } @@ -547,8 +547,15 @@ return str; } -KateTextCursor KateSearch::getCursor() +KateTextCursor KateSearch::getCursor( SearchFlags flags ) { + if (flags.backward && !flags.selected && view()->hasSelection()) + { + // We're heading backwards (and not within a selection), + // the selection might start before the cursor. + return KMIN( KateTextCursor(view()->selStartLine(), view()->selStartCol()), + KateTextCursor(view()->cursorLine(), view()->cursorColumnReal())); + } return KateTextCursor(view()->cursorLine(), view()->cursorColumnReal()); } @@ -586,6 +593,21 @@ //kdDebug() << "Searching at " << line << ", " << col << endl; // kdDebug()<<"KateSearch::doSearch: "<<line<<", "<<col<<", "<<backward<<endl; + if (backward) + { + KateDocCursor docCursor(line, col, doc()); + + // If we're at the top of the document, we're not gonna find anything, so bail. + if (docCursor.line() == 0 && docCursor.col() == 0) + return false; + + // Move one step backward before searching, if this is a "find again", we don't + // want to find the same match. + docCursor.moveBackward(1); + line = docCursor.line(); + col = docCursor.col(); + } + do { if( regExp ) { m_re = QRegExp( text, caseSensitive ); --- branches/KDE/3.5/kdelibs/kate/part/katesearch.h #559492:559493 @@ -139,7 +139,7 @@ void skipOne(); QString getSearchText(); - KateTextCursor getCursor(); + KateTextCursor getCursor( SearchFlags flags ); bool doSearch( const QString& text ); void exposeFound( KateTextCursor &cursor, int slen ); *** Bug 119924 has been marked as a duplicate of this bug. *** |