summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tests/listitem_test.cpp3
-rw-r--r--src/urlbar/listitem.cpp25
2 files changed, 16 insertions, 12 deletions
diff --git a/src/tests/listitem_test.cpp b/src/tests/listitem_test.cpp
index 961f4b6a..fc0b62ec 100644
--- a/src/tests/listitem_test.cpp
+++ b/src/tests/listitem_test.cpp
@@ -74,7 +74,8 @@ void ListItemTest::wordHighLighting_data()
QTest::newRow("<") << "Subject < Section < Wiki" << "<" << "Subject <b>&lt;</b> Section <b>&lt;</b> Wiki";
QTest::newRow("&") << "<i>http://www.google.com/search?q=qt test&ie=UTF-8&oe=UTF-8</i>" << "&"
<< "<i>http://www.google.com/search?q=qt test<b>&amp;</b>ie=UTF-8<b>&amp;</b>oe=UTF-8</i>";
-
+ QTest::newRow("ciao") << "ciao" << "ciao" << "<b>ciao</b>";
+ QTest::newRow("http://ciao") << "http://ciao" << "ciao" << "http://<b>ciao</b>";
}
void ListItemTest::wordHighLighting()
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 8b908149..df9ef286 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -211,28 +211,31 @@ static QString highlightWordsInText(const QString &text, const QStringList &word
foreach (const QString &wordToPointOut, words) {
int index = ret.indexOf(wordToPointOut, 0, Qt::CaseInsensitive);
while(index > -1) {
- boldSections.fill(true,index + 1, index + wordToPointOut.size() + 1);
+ boldSections.fill(true, index, index + wordToPointOut.size());
index = ret.indexOf(wordToPointOut, index + wordToPointOut.size(), Qt::CaseInsensitive);
}
}
int numSections = 0;
- bool bold = false;
- for(int i=0; i < boldSections.size() - 1; ++i ) {
- if (boldSections.testBit(i) && (i == boldSections.size() || !boldSections.testBit(i+1)))
- numSections++;
+ for (int i = 0; i < boldSections.size() - 1; ++i){
+ if (boldSections.testBit(i) && !boldSections.testBit(i + 1))
+ ++numSections;
}
+ if (boldSections.testBit(boldSections.size() - 1)) //last char was still part of a bold section
+ ++numSections;
const int tagLength = 7; // length of "<b>" and "</b>" we're going to add for each bold section.
ret.reserve(ret.size() + numSections * tagLength);
- bold = false;
- for (int i = boldSections.size() - 1; i >= 0; --i) {
- if (!bold && boldSections.testBit(i)) {
- ret.insert(i, QL1S("</b>"));
+ bool bold = false;
+ for (int i = boldSections.size() - 1; i >= 0; --i){
+ if (!bold && boldSections.testBit(i)){
+ ret.insert(i + 1, QL1S("</b>"));
bold = true;
- } else if (bold && !boldSections.testBit(i)) {
- ret.insert(i, QL1S("<b>"));
+ } else if (bold && !boldSections.testBit(i)){
+ ret.insert(i + 1, QL1S("<b>"));
bold = false;
}
}
+ if (bold)
+ ret.insert(0, QL1S("<b>"));
return ret;
}