Changeset View
Changeset View
Standalone View
Standalone View
src/buffer/katetextblock.cpp
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 92 | { | |||
---|---|---|---|---|---|
145 | 145 | | |||
146 | // no cursors in this block, no work to do.. | 146 | // no cursors in this block, no work to do.. | ||
147 | if (m_cursors.empty()) { | 147 | if (m_cursors.empty()) { | ||
148 | return; | 148 | return; | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | // move all cursors on the line which has the text inserted | 151 | // move all cursors on the line which has the text inserted | ||
152 | // remember all ranges modified | 152 | // remember all ranges modified | ||
153 | QSet<TextRange *> changedRanges; | 153 | QSet<TextRange *> changedRanges; | ||
anthonyfieroni: You can use unordered_set, so you don't need m_isCheckValidityRequired any more. It can be… | |||||
Actually no, that will be again a lot more expensive. cullmann: Actually no, that will be again a lot more expensive.
With the vector, you get one allocation… | |||||
154 | foreach (TextCursor *cursor, m_cursors) { | 154 | foreach (TextCursor *cursor, m_cursors) { | ||
155 | // skip cursors on lines in front of the wrapped one! | 155 | // skip cursors on lines in front of the wrapped one! | ||
156 | if (cursor->lineInBlock() < line) { | 156 | if (cursor->lineInBlock() < line) { | ||
157 | continue; | 157 | continue; | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | // either this is simple, line behind the wrapped one | 160 | // either this is simple, line behind the wrapped one | ||
161 | if (cursor->lineInBlock() > line) { | 161 | if (cursor->lineInBlock() > line) { | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 282 | foreach (TextRange *range, changedRanges) { | |||
283 | // update both blocks | 283 | // update both blocks | ||
284 | updateRange(range); | 284 | updateRange(range); | ||
285 | previousBlock->updateRange(range); | 285 | previousBlock->updateRange(range); | ||
286 | } | 286 | } | ||
287 | 287 | | |||
288 | // check validity of all ranges, might invalidate them... | 288 | // check validity of all ranges, might invalidate them... | ||
289 | foreach (TextRange *range, changedRanges) { | 289 | foreach (TextRange *range, changedRanges) { | ||
290 | range->checkValidity(); | 290 | range->checkValidity(); | ||
291 | } | 291 | } | ||
This loop now crash in the unit test ./bin/bug313759 )It works again, if I use a QSet, at that one location. cullmann: This loop now crash in the unit test
./bin/bug313759
=)
It works again, if I use a QSet, at… | |||||
Ok, doesn't work due to the issue that we might delete the range via notifier in checkValidity() :P cullmann: Ok, doesn't work due to the issue that we might delete the range via notifier in checkValidity… | |||||
Noob question: Would QPointer help? if (range && range->isValidityCheckRequired()) { loh.tar: Noob question: Would QPointer help?
if (range && range->isValidityCheckRequired()) { | |||||
As it is no QObject, no ;=) Actually, I think all workaround might be even more expensive than the QSet. cullmann: As it is no QObject, no ;=) Actually, I think all workaround might be even more expensive than… | |||||
292 | 292 | | |||
293 | // be done | 293 | // be done | ||
294 | return; | 294 | return; | ||
295 | } | 295 | } | ||
296 | 296 | | |||
297 | // easy: just move text to previous line and remove current one | 297 | // easy: just move text to previous line and remove current one | ||
298 | const int oldSizeOfPreviousLine = m_lines.at(line - 1)->length(); | 298 | const int oldSizeOfPreviousLine = m_lines.at(line - 1)->length(); | ||
299 | const int sizeOfCurrentLine = m_lines.at(line)->length(); | 299 | const int sizeOfCurrentLine = m_lines.at(line)->length(); | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 412 | if (cursor->m_column <= oldLength) { | |||
413 | cursor->m_column += text.size(); | 413 | cursor->m_column += text.size(); | ||
414 | } | 414 | } | ||
415 | 415 | | |||
416 | // special handling if cursor behind the real line, e.g. non-wrapping cursor in block selection mode | 416 | // special handling if cursor behind the real line, e.g. non-wrapping cursor in block selection mode | ||
417 | else if (cursor->m_column < textOfLine.size()) { | 417 | else if (cursor->m_column < textOfLine.size()) { | ||
418 | cursor->m_column = textOfLine.size(); | 418 | cursor->m_column = textOfLine.size(); | ||
419 | } | 419 | } | ||
420 | 420 | | |||
421 | // remember range, if any | 421 | // we only need to trigger checkValidity later if the range has feedback or might be invalidated | ||
422 | if (cursor->kateRange()) { | 422 | if (cursor->kateRange() && (cursor->kateRange()->feedback() || cursor->kateRange()->start().line() == cursor->kateRange()->end().line())) { | ||
423 | changedRanges.insert(cursor->kateRange()); | 423 | changedRanges.insert(cursor->kateRange()); | ||
424 | } | 424 | } | ||
425 | } | 425 | } | ||
426 | 426 | | |||
427 | // check validity of all ranges, might invalidate them... | 427 | // we might need to invalidate ranges or notify about their changes | ||
428 | foreach (TextRange *range, changedRanges) { | 428 | foreach (TextRange *range, changedRanges) { | ||
429 | range->checkValidity(); | 429 | range->checkValidity(); | ||
430 | } | 430 | } | ||
431 | } | 431 | } | ||
432 | 432 | | |||
433 | void TextBlock::removeText(const KTextEditor::Range &range, QString &removedText) | 433 | void TextBlock::removeText(const KTextEditor::Range &range, QString &removedText) | ||
434 | { | 434 | { | ||
435 | // calc internal line | 435 | // calc internal line | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 472 | foreach (TextCursor *cursor, m_cursors) { | |||
482 | 482 | | |||
483 | // patch column of cursor | 483 | // patch column of cursor | ||
484 | if (cursor->column() <= range.end().column()) { | 484 | if (cursor->column() <= range.end().column()) { | ||
485 | cursor->m_column = range.start().column(); | 485 | cursor->m_column = range.start().column(); | ||
486 | } else { | 486 | } else { | ||
487 | cursor->m_column -= (range.end().column() - range.start().column()); | 487 | cursor->m_column -= (range.end().column() - range.start().column()); | ||
488 | } | 488 | } | ||
489 | 489 | | |||
490 | // remember range, if any | 490 | // we only need to trigger checkValidity later if the range has feedback or might be invalidated | ||
491 | if (cursor->kateRange()) { | 491 | if (cursor->kateRange() && (cursor->kateRange()->feedback() || cursor->kateRange()->start().line() == cursor->kateRange()->end().line())) { | ||
492 | changedRanges.insert(cursor->kateRange()); | 492 | changedRanges.insert(cursor->kateRange()); | ||
493 | } | 493 | } | ||
494 | } | 494 | } | ||
495 | 495 | | |||
496 | // check validity of all ranges, might invalidate them... | 496 | // we might need to invalidate ranges or notify about their changes | ||
497 | foreach (TextRange *range, changedRanges) { | 497 | foreach (TextRange *range, changedRanges) { | ||
498 | range->checkValidity(); | 498 | range->checkValidity(); | ||
499 | } | 499 | } | ||
500 | } | 500 | } | ||
501 | 501 | | |||
502 | void TextBlock::debugPrint(int blockIndex) const | 502 | void TextBlock::debugPrint(int blockIndex) const | ||
503 | { | 503 | { | ||
504 | // print all blocks | 504 | // print all blocks | ||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |
You can use unordered_set, so you don't need m_isCheckValidityRequired any more. It can be applied to other places as well.