Commit ac26bd47 authored by Robert Knight's avatar Robert Knight
Browse files

BUG: 159096 ('Find Next' does not always move to correct line)

Squashed commit of the following:

commit 17bd4aee3b20b3d36e0891dfd516d986430133c2
Author: Robert Knight <robertknight@gmail.com>
Date:   Sun Mar 30 03:39:07 2008 +0100

    Use a list of integers rather than a bitmap to record the character positions of new lines.  This allows for empty lines in the buffer which means that multiple lines may start at the same character position.

commit d8ee8002f6ee87257f70f94e1a77a44f668617d9
Author: Robert Knight <robertknight@gmail.com>
Date:   Sun Mar 30 03:22:24 2008 +0100

    Compute the line index of a match found during output search more accurately.  Add a method to record the positions of new lines within the output stream to TerminalCharacterDecoder and use that in SearchHistoryTask to count the number of lines offset from the start of the current block.  Unlike the previous method this works when there are wrapped lines in the output.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=791703
parent 60f0a0a5
......@@ -1276,6 +1276,7 @@ void SearchHistoryTask::executeOnScreenWindow( SessionPtr session , ScreenWindow
QTextStream searchStream(&string);
PlainTextDecoder decoder;
decoder.setRecordLinePositions(true);
//setup first and last lines depending on search direction
int line = startLine;
......@@ -1329,13 +1330,13 @@ void SearchHistoryTask::executeOnScreenWindow( SessionPtr session , ScreenWindow
}
}
//kDebug() << "Searching lines " << qMin(endLine,line) << " to " << qMax(endLine,line);
decoder.begin(&searchStream);
emulation->writeToStream(&decoder, qMin(endLine,line) , qMax(endLine,line) );
decoder.end();
//kDebug() << "Stream contents: " << string;
// line number search below assumes that the buffer ends with a new-line
string.append('\n');
pos = -1;
if (forwards)
pos = string.indexOf(_regExp);
......@@ -1345,7 +1346,16 @@ void SearchHistoryTask::executeOnScreenWindow( SessionPtr session , ScreenWindow
//if a match is found, position the cursor on that line and update the screen
if ( pos != -1 )
{
int findPos = qMin(line,endLine) + string.left(pos + 1).count(QChar('\n'));
int newLines = 0;
QList<int> linePositions = decoder.linePositions();
while (newLines < linePositions.count() && linePositions[newLines] <= pos)
newLines++;
// ignore the new line at the start of the buffer
newLines--;
int findPos = qMin(line,endLine) + newLines;
highlightResult(window,findPos);
emit completed(true);
......@@ -1366,7 +1376,6 @@ void SearchHistoryTask::executeOnScreenWindow( SessionPtr session , ScreenWindow
emit completed(false);
}
void SearchHistoryTask::highlightResult(ScreenWindowPtr window , int findPos)
{
//work out how many lines into the current block of text the search result was found
......
......@@ -46,17 +46,34 @@ bool PlainTextDecoder::trailingWhitespace() const
}
void PlainTextDecoder::begin(QTextStream* output)
{
_output = output;
_output = output;
if (!_linePositions.isEmpty())
_linePositions.clear();
}
void PlainTextDecoder::end()
{
_output = 0;
}
void PlainTextDecoder::setRecordLinePositions(bool record)
{
_recordLinePositions = record;
}
QList<int> PlainTextDecoder::linePositions() const
{
return _linePositions;
}
void PlainTextDecoder::decodeLine(const Character* const characters, int count, LineProperty /*properties*/
)
{
Q_ASSERT( _output );
if (_recordLinePositions && _output->string())
{
int pos = _output->string()->count();
_linePositions << pos;
}
//TODO should we ignore or respect the LINE_WRAPPED line property?
//note: we build up a QString and send it to the text stream rather writing into the text
......@@ -210,7 +227,6 @@ void HTMLDecoder::decodeLine(const Character* const characters, int count, LineP
*_output << text;
}
void HTMLDecoder::openSpan(QString& text , const QString& style)
{
text.append( QString("<span style=\"%1\">").arg(style) );
......
......@@ -24,6 +24,8 @@
#include "Character.h"
#include <QList>
class QTextStream;
namespace Konsole
......@@ -81,6 +83,14 @@ public:
* in the output.
*/
bool trailingWhitespace() const;
/**
* Returns of character positions in the output stream
* at which new lines where added. Returns an empty if setTrackLinePositions() is false or if
* the output device is not a string.
*/
QList<int> linePositions() const;
/** Enables recording of character positions at which new lines are added. See linePositions() */
void setRecordLinePositions(bool record);
virtual void begin(QTextStream* output);
virtual void end();
......@@ -93,6 +103,9 @@ public:
private:
QTextStream* _output;
bool _includeTrailingWhitespace;
bool _recordLinePositions;
QList<int> _linePositions;
};
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment