@@ -87,16 +87,7 @@ void MarkdownHighlighter::highlightBlock(const QString &textBlock)
87
87
88
88
// check spelling of passed text block
89
89
if (spellingCheckEnabled) {
90
- QStringList wordList = textBlock.split (QRegExp (" \\ W+" ), QString::SkipEmptyParts);
91
- int index = 0 ;
92
- foreach (QString word, wordList) {
93
- index = textBlock.indexOf (word, index);
94
-
95
- if (!spellChecker->isCorrect (word)) {
96
- setFormat (index, word.length (), spellFormat);
97
- }
98
- index += word.length ();
99
- }
90
+ checkSpelling (textBlock);
100
91
}
101
92
102
93
QString text = document ()->toPlainText ();
@@ -176,6 +167,20 @@ void MarkdownHighlighter::applyFormat(unsigned long pos, unsigned long end,
176
167
}
177
168
}
178
169
170
+ void MarkdownHighlighter::checkSpelling (const QString &textBlock)
171
+ {
172
+ QStringList wordList = textBlock.split (QRegExp (" \\ W+" ), QString::SkipEmptyParts);
173
+ int index = 0 ;
174
+ foreach (QString word, wordList) {
175
+ index = textBlock.indexOf (word, index);
176
+
177
+ if (!spellChecker->isCorrect (word)) {
178
+ setFormat (index, word.length (), spellFormat);
179
+ }
180
+ index += word.length ();
181
+ }
182
+ }
183
+
179
184
void MarkdownHighlighter::resultReady (pmh_element **elements, unsigned long base_offset)
180
185
{
181
186
if (!elements) {
@@ -184,7 +189,9 @@ void MarkdownHighlighter::resultReady(pmh_element **elements, unsigned long base
184
189
}
185
190
186
191
// clear any format before base_offset
187
- applyFormat (0 , base_offset - 1 , QTextCharFormat (), false );
192
+ if (base_offset > 0 ) {
193
+ applyFormat (0 , base_offset - 1 , QTextCharFormat (), false );
194
+ }
188
195
189
196
// apply highlight results
190
197
for (int i = 0 ; i < highlightingStyles.size (); i++) {
0 commit comments