[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: Re: [rfc] New KTextEditor search interface in action (patch attached)
From: Christoph Cullmann <cullmann () babylon2k ! de>
Date: 2007-04-30 21:41:04
Message-ID: 200704302341.04626.cullmann () babylon2k ! de
[Download RAW message or body]
On Monday 30 April 2007 23:39:25 Christoph Cullmann wrote:
> On Monday 30 April 2007 23:27:45 Christoph Cullmann wrote:
> > > > Currently the starting point is the start of the range itself.
> > > > The end of the range is either the end of the document or
> > > > the end of the selection, depending on the value of
> > > > the selection-only-checkbox. Do you see a problem with this?
> > >
> > > I think a additional start cursor would make sense, that way, you can
> > > make it even more easy and provide later a "wrap around" search option,
> > > too.
> >
> > Forget it, I think the interface is ok the way it is....
> > I have no time here to compile + checkin, could somebody do it?
>
> Got time ;)
> But the katesearchbar.cpp didn't apply correct, have commented out the
> doSearch, somebody with more time should reapply the patch there.
Here is the .rej file, btw.
--
Christoph Cullmann
KDE Developer, Kate Maintainer
http://babylon2k.de, cullmann@kde.org
["katesearchbar.cpp.rej" (text/x-csrc)]
***************
*** 155,227 ****
{
QString expression = _expression;
- bool selected = d->selectionOnlyBox->checkState();
// If we're starting search for the first time, begin at the current cursor \
position. // ### there may be cases when this should happen, but does not
if ( init )
{
- d->startCursor = d->fromCursorBox->checkState() ==
- Qt::Checked ? m_view->cursorPosition() :
- selected ? m_view->selectionRange().start() :
- KTextEditor::Cursor( 0, 0 );
d->searching = true;
// clear
d->topRange->deleteChildRanges();
}
- const bool escapeSequences = true; // TODO make checkbox for that
- // abuse regex for whole word plaintext search
- bool regexMode = d->regExpBox->checkState() == Qt::Checked;
- const bool wholeWords = !d->wholeWordsBox->checkState() == Qt::Checked;
- if (!regexMode && wholeWords)
{
- // resolve escape sequences like \t
- if (escapeSequences)
{
- KateDocument::escapePlaintext(expression);
}
-
- // escape dot and friends
- expression = "\\b" + QRegExp::escape(expression) + "\\b";
- regexMode = true;
}
- // run search engine
- const bool caseSensitive = d->caseSensitiveBox->checkState() == Qt::Checked;
- if (regexMode)
- {
- d->regExp.setPattern(expression);
- if (!d->regExp.isValid())
{
- return;
}
- d->regExp.setCaseSensitivity(caseSensitive
- ? Qt::CaseSensitive
- : Qt::CaseInsensitive);
- d->match = m_view->doc()->searchText(d->startCursor, d->regExp, backwards);
}
- else
{
- // resolve escape sequences like \t
- if (escapeSequences)
{
- KateDocument::escapePlaintext(expression);
}
- d->match = m_view->doc()->searchText(d->startCursor, expression, \
caseSensitive, backwards); }
bool foundMatch = d->match.isValid() && d->match != d->lastMatch && d->match != \
m_view->selectionRange(); bool wrapped = false;
if (d->wrapAround && !foundMatch)
{
// We found nothing, so wrap.
- d->startCursor = selected?
backwards ? m_view->selectionRange().end() : \
m_view->selectionRange().start() :
backwards ? m_view->doc()->documentEnd() : KTextEditor::Cursor(0, 0);
--- 155,285 ----
{
QString expression = _expression;
+ const bool selectionOnly = d->selectionOnlyBox->checkState() == Qt::Checked;
+ const bool fromCursor = d->fromCursorBox->checkState() == Qt::Checked;
// If we're starting search for the first time, begin at the current cursor \
position. // ### there may be cases when this should happen, but does not
if ( init )
{
+ d->startCursor = fromCursor ? m_view->cursorPosition()
+ : selectionOnly ? \
m_view->selectionRange().start() + \
: KTextEditor::Cursor(0, 0); d->searching = true;
// clear
d->topRange->deleteChildRanges();
}
+ // combine options
+ const KTextEditor::Search::SearchOptions supportedOptions = \
m_view->doc()->supportedSearchOptions(); + KTextEditor::Search::SearchOptions \
enabledOptions(KTextEditor::Search::Default);
+ // which mode?
+ const bool regexChecked = d->regExpBox->checkState() == Qt::Checked;
+ if (regexChecked && supportedOptions.testFlag(KTextEditor::Search::Regex))
{
+ // regex
+ enabledOptions |= KTextEditor::Search::Regex;
+
+ // TODO
+ // dot matches newline?
+ const bool dotMatchesNewline = false;
+ if (dotMatchesNewline && \
supportedOptions.testFlag(KTextEditor::Search::DotMatchesNewline)) {
+ enabledOptions |= KTextEditor::Search::DotMatchesNewline;
}
}
+ else
+ {
+ // plaintext
+ // whole words?
+ const bool wholeWordsChecked = d->wholeWordsBox->checkState() == Qt::Checked;
+ if (wholeWordsChecked && \
supportedOptions.testFlag(KTextEditor::Search::WholeWords)) {
+ enabledOptions |= KTextEditor::Search::WholeWords;
}
+ // TODO make configurable
+ // escape sequences?
+ const bool escapeSequences = true;
+ if (escapeSequences && \
supportedOptions.testFlag(KTextEditor::Search::EscapeSequences)) + {
+ enabledOptions |= KTextEditor::Search::EscapeSequences;
+ }
+ }
+ // case insensitive?
+ const bool caseSensitiveChecked = d->caseSensitiveBox->checkState() == \
Qt::Checked; + if (!caseSensitiveChecked && \
supportedOptions.testFlag(KTextEditor::Search::CaseInsensitive)) + {
+ enabledOptions |= KTextEditor::Search::CaseInsensitive;
}
+
+ // backwards?
+ if (backwards && supportedOptions.testFlag(KTextEditor::Search::Backwards))
{
+ enabledOptions |= KTextEditor::Search::Backwards;
+ }
+
+ // find input range
+ KTextEditor::Range inputRange;
+ if (selectionOnly)
+ {
+ if (m_view->selection())
{
+ // selection found
+ // TODO skip part before cursor if cursor within selection
+ inputRange = m_view->selectionRange();
+
+ // block input range?
+ if (m_view->blockSelection())
+ {
+ if (supportedOptions.testFlag(KTextEditor::Search::BlockInputRange))
+ {
+ enabledOptions |= KTextEditor::Search::BlockInputRange;
+ }
+ else
+ {
+ // TODO KTextEditor in use cannot handle this. What do we do?
+ // TODO Stop whole search?
+ inputRange = m_view->doc()->documentRange();
+ }
+ }
}
+ else
+ {
+ // no selection
+ if (fromCursor)
+ {
+ // from cursor on
+ inputRange.setRange(d->startCursor, m_view->doc()->documentEnd());
+ }
+ else
+ {
+ // whole document
+ inputRange = m_view->doc()->documentRange();
+ }
+ }
}
+ else
+ {
+ // whole document
+ inputRange = m_view->doc()->documentRange();
+ }
+ // run engine
+ QVector<KTextEditor::Range> resultRanges = \
m_view->doc()->searchText(inputRange, expression, enabledOptions); + d->match = \
resultRanges[0]; +
bool foundMatch = d->match.isValid() && d->match != d->lastMatch && d->match != \
m_view->selectionRange(); bool wrapped = false;
if (d->wrapAround && !foundMatch)
{
// We found nothing, so wrap.
+ d->startCursor = selectionOnly?
backwards ? m_view->selectionRange().end() : \
m_view->selectionRange().start() :
backwards ? m_view->doc()->documentEnd() : KTextEditor::Cursor(0, 0);
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic