Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 346 Lines • ▼ Show 20 Line(s) | |||||
347 | } | 347 | } | ||
348 | //END | 348 | //END | ||
349 | 349 | | |||
350 | void KTextEditor::DocumentPrivate::saveEditingPositions(KTextEditor::Document *, const KTextEditor::Range &range) | 350 | void KTextEditor::DocumentPrivate::saveEditingPositions(KTextEditor::Document *, const KTextEditor::Range &range) | ||
351 | { | 351 | { | ||
352 | if (m_editingStackPosition != m_editingStack.size() - 1) { | 352 | if (m_editingStackPosition != m_editingStack.size() - 1) { | ||
353 | m_editingStack.resize(m_editingStackPosition); | 353 | m_editingStack.resize(m_editingStackPosition); | ||
354 | } | 354 | } | ||
355 | KTextEditor::MovingInterface *moving = qobject_cast<KTextEditor::MovingInterface *>(this); | 355 | | ||
356 | const auto c = range.start(); | 356 | const auto c = range.start(); | ||
357 | QSharedPointer<KTextEditor::MovingCursor> mc (moving->newMovingCursor(c)); | 357 | | ||
358 | // try to be clever: reuse existing cursors if possible | ||||
359 | QSharedPointer<KTextEditor::MovingCursor> mc; | ||||
360 | | ||||
361 | // we might pop last one: reuse that | ||||
358 | if (!m_editingStack.isEmpty() && c.line() == m_editingStack.top()->line()) { | 362 | if (!m_editingStack.isEmpty() && c.line() == m_editingStack.top()->line()) { | ||
359 | m_editingStack.pop(); | 363 | mc = m_editingStack.pop(); | ||
360 | } | 364 | } | ||
361 | m_editingStack.push(mc); | 365 | | ||
362 | if (m_editingStack.size() > s_editingStackSizeLimit) { | 366 | // we might expire oldest one, reuse that one, if not already one there | ||
367 | // we prefer the other one for reuse, as already on the right line aka in the right block! | ||||
368 | if (m_editingStack.size() >= s_editingStackSizeLimit) { | ||||
369 | if (mc) { | ||||
363 | m_editingStack.removeFirst(); | 370 | m_editingStack.removeFirst(); | ||
371 | } else { | ||||
372 | mc = m_editingStack.takeFirst(); | ||||
373 | } | ||||
374 | } | ||||
375 | | ||||
376 | // new cursor needed? or adjust existing one? | ||||
377 | if (mc) { | ||||
378 | mc->setPosition(c); | ||||
379 | } else { | ||||
380 | mc = QSharedPointer<KTextEditor::MovingCursor> (newMovingCursor(c)); | ||||
364 | } | 381 | } | ||
382 | | ||||
383 | // add new one as top of stack | ||||
384 | m_editingStack.push(mc); | ||||
365 | m_editingStackPosition = m_editingStack.size() - 1; | 385 | m_editingStackPosition = m_editingStack.size() - 1; | ||
366 | } | 386 | } | ||
367 | 387 | | |||
368 | KTextEditor::Cursor KTextEditor::DocumentPrivate::lastEditingPosition(EditingPositionKind nextOrPrev, KTextEditor::Cursor currentCursor) | 388 | KTextEditor::Cursor KTextEditor::DocumentPrivate::lastEditingPosition(EditingPositionKind nextOrPrev, KTextEditor::Cursor currentCursor) | ||
369 | { | 389 | { | ||
370 | if (m_editingStack.isEmpty()) { | 390 | if (m_editingStack.isEmpty()) { | ||
371 | return KTextEditor::Cursor::invalid(); | 391 | return KTextEditor::Cursor::invalid(); | ||
372 | } | 392 | } | ||
▲ Show 20 Lines • Show All 350 Lines • ▼ Show 20 Line(s) | 726 | { | |||
723 | if (position.line() > lines()) { | 743 | if (position.line() > lines()) { | ||
724 | int line = lines(); | 744 | int line = lines(); | ||
725 | while (line <= position.line()) { | 745 | while (line <= position.line()) { | ||
726 | editInsertLine(line, QString()); | 746 | editInsertLine(line, QString()); | ||
727 | line++; | 747 | line++; | ||
728 | } | 748 | } | ||
729 | } | 749 | } | ||
730 | 750 | | |||
751 | // compute expanded column for block mode | ||||
752 | int positionColumnExpanded = insertColumn; | ||||
731 | const int tabWidth = config()->tabWidth(); | 753 | const int tabWidth = config()->tabWidth(); | ||
732 | 754 | if (block) { | |||
733 | static const QChar newLineChar(QLatin1Char('\n')); | 755 | if (auto l = plainKateTextLine(currentLine)) { | ||
734 | 756 | positionColumnExpanded = l->toVirtualColumn(insertColumn, tabWidth); | |||
735 | int insertColumnExpanded = insertColumn; | 757 | } | ||
736 | Kate::TextLine l = plainKateTextLine(currentLine); | | |||
737 | if (l) { | | |||
738 | insertColumnExpanded = l->toVirtualColumn(insertColumn, tabWidth); | | |||
739 | } | 758 | } | ||
740 | int positionColumnExpanded = insertColumnExpanded; | | |||
741 | 759 | | |||
742 | int pos = 0; | 760 | int pos = 0; | ||
743 | for (; pos < totalLength; pos++) { | 761 | for (; pos < totalLength; pos++) { | ||
744 | const QChar &ch = text.at(pos); | 762 | const QChar &ch = text.at(pos); | ||
745 | 763 | | |||
746 | if (ch == newLineChar) { | 764 | if (ch == QLatin1Char('\n')) { | ||
747 | // Only perform the text insert if there is text to insert | 765 | // Only perform the text insert if there is text to insert | ||
748 | if (currentLineStart < pos) { | 766 | if (currentLineStart < pos) { | ||
749 | editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart)); | 767 | editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart)); | ||
750 | } | 768 | } | ||
751 | 769 | | |||
752 | if (!block) { | 770 | if (!block) { | ||
753 | editWrapLine(currentLine, insertColumn + pos - currentLineStart); | 771 | editWrapLine(currentLine, insertColumn + pos - currentLineStart); | ||
754 | insertColumn = 0; | 772 | insertColumn = 0; | ||
755 | } | 773 | } | ||
756 | 774 | | |||
757 | currentLine++; | 775 | currentLine++; | ||
758 | l = plainKateTextLine(currentLine); | | |||
759 | 776 | | |||
760 | if (block) { | 777 | if (block) { | ||
778 | auto l = plainKateTextLine(currentLine); | ||||
761 | if (currentLine == lastLine() + 1) { | 779 | if (currentLine == lastLine() + 1) { | ||
762 | editInsertLine(currentLine, QString()); | 780 | editInsertLine(currentLine, QString()); | ||
763 | } | 781 | } | ||
764 | insertColumn = positionColumnExpanded; | 782 | insertColumn = positionColumnExpanded; | ||
765 | if (l) { | 783 | if (l) { | ||
766 | insertColumn = l->fromVirtualColumn(insertColumn, tabWidth); | 784 | insertColumn = l->fromVirtualColumn(insertColumn, tabWidth); | ||
767 | } | 785 | } | ||
768 | } | 786 | } | ||
769 | 787 | | |||
770 | currentLineStart = pos + 1; | 788 | currentLineStart = pos + 1; | ||
771 | if (l) { | | |||
772 | insertColumnExpanded = l->toVirtualColumn(insertColumn, tabWidth); | | |||
773 | } | | |||
774 | } | 789 | } | ||
775 | } | 790 | } | ||
776 | 791 | | |||
777 | // Only perform the text insert if there is text to insert | 792 | // Only perform the text insert if there is text to insert | ||
778 | if (currentLineStart < pos) { | 793 | if (currentLineStart < pos) { | ||
779 | editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart)); | 794 | editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - currentLineStart)); | ||
780 | } | 795 | } | ||
781 | 796 | | |||
▲ Show 20 Lines • Show All 5200 Lines • Show Last 20 Lines |