r17541 by jghali - #3730: impossible to search and replace "fl" in text area
scribus-commit
scribus-commit at lists.scribus.net
Tue Jun 5 21:51:46 UTC 2012
Author: jghali
Date: Tue Jun 5 21:51:45 2012
New Revision: 17541
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17541
Log:
#3730: impossible to search and replace "fl" in text area
Modified:
trunk/Scribus/scribus/text/storytext.cpp
trunk/Scribus/scribus/text/storytext.h
trunk/Scribus/scribus/ui/search.cpp
Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17541&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp (original)
+++ trunk/Scribus/scribus/text/storytext.cpp Tue Jun 5 21:51:45 2012
@@ -203,6 +203,95 @@
d->clear();
d->len = 0;
invalidateAll();
+}
+
+int StoryText::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const
+{
+ int foundIndex = -1;
+
+ if (str.isEmpty() || (from < 0))
+ return -1;
+
+ int strLen = str.length();
+ int storyLen = length();
+
+ QString qStr = str;
+ if (cs == Qt::CaseInsensitive)
+ qStr = qStr.toLower();
+ QChar ch = qStr.at(0);
+
+ if (cs == Qt::CaseSensitive)
+ {
+ int i = indexOf(ch, from, cs);
+ while (i >= 0 && i < (int) d->len)
+ {
+ int index = 0;
+ while ((index < strLen) && ((index + i) < storyLen))
+ {
+ if (qStr.at(index) != d->at(index + i)->ch)
+ break;
+ ++index;
+ }
+ if (index == strLen)
+ {
+ foundIndex = i;
+ break;
+ }
+ i = indexOf(ch, i + 1, cs);
+ }
+ }
+ else
+ {
+ int i = indexOf(ch, from, cs);
+ while (i >= 0 && i < (int) d->len)
+ {
+ int index = 0;
+ while ((index < strLen) && ((index + i) < storyLen))
+ {
+ if (qStr.at(index) != d->at(index + i)->ch.toLower())
+ break;
+ ++index;
+ }
+ if (index == strLen)
+ {
+ foundIndex = i;
+ break;
+ }
+ i = indexOf(ch, i + 1, cs);
+ }
+ }
+
+ return foundIndex;
+}
+
+int StoryText::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
+{
+ int foundIndex = -1;
+ int textLength = length();
+
+ if (cs == Qt::CaseSensitive)
+ {
+ for (int i = from; i < textLength; ++i)
+ {
+ if (d->at(i)->ch == ch)
+ {
+ foundIndex = i;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (int i = from; i < textLength; ++i)
+ {
+ if (d->at(i)->ch.toLower() == ch)
+ {
+ foundIndex = i;
+ break;
+ }
+ }
+ }
+ return foundIndex;
}
void StoryText::insert(const StoryText& other, bool onlySelection)
Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17541&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h (original)
+++ trunk/Scribus/scribus/text/storytext.h Tue Jun 5 21:51:45 2012
@@ -110,6 +110,10 @@
void clear();
StoryText copy() const;
+
+ // Find text in story
+ int indexOf(const QString &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
+ int indexOf(QChar ch, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
// Add, change, replace
// Insert chars from another StoryText object at current cursor position
Modified: trunk/Scribus/scribus/ui/search.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17541&path=/trunk/Scribus/scribus/ui/search.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/search.cpp (original)
+++ trunk/Scribus/scribus/ui/search.cpp Tue Jun 5 21:51:45 2012
@@ -419,25 +419,34 @@
sSize = qRound(SSizeVal->value() * 10);
if (sText.length() > 0)
found = false;
- int inde = 0;
+
uint as = Item->itemText.cursorPosition();
ReplStart = as;
int a;
if (SMode)
{
+ Qt::CaseSensitivity cs = Qt::CaseSensitive;
+ if (CaseIgnore->isChecked())
+ cs = Qt::CaseInsensitive;
+
for (a = as; a < Item->itemText.length(); ++a)
{
+ found = true;
if (SText->isChecked())
{
- QString chstr = Item->itemText.text(a,1);
- if (CaseIgnore->isChecked())
- chstr = chstr.toLower();
- found = chstr == sText.mid(inde, 1) ? true : false;
- if ((Word->isChecked()) && (inde == 0) && (chstr[0].isSpace()))
- found = true;
- }
- else
- found = true;
+ a = Item->itemText.indexOf(sText, a, cs);
+ found = (a >= 0);
+ if (!found) break;
+
+ if (Word->isChecked() && (a > 0) && !Item->itemText.text(a - 1).isSpace())
+ found = false;
+ if (Word->isChecked())
+ {
+ int lastChar = qMin(a + sText.length(), maxChar);
+ found = ((lastChar == maxChar) || Item->itemText.text(lastChar).isSpace());
+ }
+ if (!found) continue;
+ }
if (SSize->isChecked())
{
if (Item->itemText.charStyle(a).fontSize() != sSize)
@@ -487,41 +496,20 @@
}
if (found)
{
- Item->itemText.select(a,1);
+ Item->itemText.select(a, sText.length());
Item->HasSel = true;
if (rep)
{
DoReplace->setEnabled(true);
AllReplace->setEnabled(true);
}
- Item->itemText.setCursorPosition(a+1);
- if (SText->isChecked())
- {
- if (inde == 0)
- ReplStart = a;
- inde++;
- if ((Word->isChecked()) && (inde == 1) && (Item->itemText.text(a).isSpace()))
- {
- inde--;
- Item->itemText.select(a, 1, false);
- }
- if ( Word->isChecked() && inde == sText.length() &&
- ! Item->itemText.text(qMin(a+1, maxChar)).isSpace() )
- {
- for (int xx = ReplStart; xx < a+1; ++xx)
- Item->itemText.select(qMin(xx, maxChar), 1, false);
- Item->HasSel = false;
- inde = 0;
- found = false;
- }
- else
- {
- if (inde == sText.length())
- break;
- }
- }
- else
+ Item->itemText.setCursorPosition(a + sText.length());
+
+ if (!SText->isChecked())
break;
+
+ ReplStart = a;
+ break;
}
else
{
@@ -531,7 +519,6 @@
Item->itemText.select(qMin(xx, maxChar), 1, false);
Item->HasSel = false;
}
- inde = 0;
}
}
if ((!found) || (a == Item->itemText.length()))
More information about the scribus-commit
mailing list