Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 799 Lines • ▼ Show 20 Line(s) | 799 | { | |||
---|---|---|---|---|---|
800 | if (!isReadWrite()) { | 800 | if (!isReadWrite()) { | ||
801 | return false; | 801 | return false; | ||
802 | } | 802 | } | ||
803 | 803 | | |||
804 | // just reuse normal function | 804 | // just reuse normal function | ||
805 | return insertText(position, textLines.join(QStringLiteral("\n")), block); | 805 | return insertText(position, textLines.join(QStringLiteral("\n")), block); | ||
806 | } | 806 | } | ||
807 | 807 | | |||
808 | bool KTextEditor::DocumentPrivate::insertTextInBlock(KTextEditor::ViewPrivate *view, const QString &s) | ||||
809 | { | ||||
810 | if (!isReadWrite()) { | ||||
811 | return false; | ||||
812 | } | ||||
813 | | ||||
814 | KTextEditor::Range selectionRange = view->selectionRange(); | ||||
815 | | ||||
816 | const int startLine = qMax(0, selectionRange.start().line()); | ||||
817 | const int endLine = qMin(selectionRange.end().line(), lastLine()); | ||||
818 | const int column = toVirtualColumn(selectionRange.end()); | ||||
819 | for (int line = endLine; line >= startLine; --line) { | ||||
820 | editInsertText(line, fromVirtualColumn(line, column), s); | ||||
821 | } | ||||
822 | | ||||
823 | const int newSelectionColumn = toVirtualColumn(view->cursorPosition()); | ||||
824 | const int startColumn = fromVirtualColumn(selectionRange.start().line(), newSelectionColumn); | ||||
825 | const int endColumn = fromVirtualColumn(selectionRange.end().line(), newSelectionColumn); | ||||
826 | | ||||
827 | selectionRange.setRange(KTextEditor::Cursor(selectionRange.start().line(), startColumn), | ||||
828 | KTextEditor::Cursor(selectionRange.end().line(), endColumn)); | ||||
829 | view->setSelection(selectionRange); | ||||
830 | return true; | ||||
831 | } | ||||
832 | | ||||
808 | bool KTextEditor::DocumentPrivate::removeText(const KTextEditor::Range &_range, bool block) | 833 | bool KTextEditor::DocumentPrivate::removeText(const KTextEditor::Range &_range, bool block) | ||
809 | { | 834 | { | ||
810 | KTextEditor::Range range = _range; | 835 | KTextEditor::Range range = _range; | ||
811 | 836 | | |||
812 | if (!isReadWrite()) { | 837 | if (!isReadWrite()) { | ||
813 | return false; | 838 | return false; | ||
814 | } | 839 | } | ||
815 | 840 | | |||
▲ Show 20 Lines • Show All 2276 Lines • ▼ Show 20 Line(s) | 3115 | if (oldCur.column() < lineLength(line)) { | |||
3092 | view->currentInputMode()->overwrittenChar(removed); | 3117 | view->currentInputMode()->overwrittenChar(removed); | ||
3093 | } | 3118 | } | ||
3094 | 3119 | | |||
3095 | removeText(r); | 3120 | removeText(r); | ||
3096 | } | 3121 | } | ||
3097 | } | 3122 | } | ||
3098 | 3123 | | |||
3099 | if (multiLineBlockMode) { | 3124 | if (multiLineBlockMode) { | ||
3100 | KTextEditor::Range selectionRange = view->selectionRange(); | 3125 | insertTextInBlock(view, chars); | ||
3101 | const int startLine = qMax(0, selectionRange.start().line()); | | |||
3102 | const int endLine = qMin(selectionRange.end().line(), lastLine()); | | |||
3103 | const int column = toVirtualColumn(selectionRange.end()); | | |||
3104 | for (int line = endLine; line >= startLine; --line) { | | |||
3105 | editInsertText(line, fromVirtualColumn(line, column), chars); | | |||
3106 | } | | |||
3107 | int newSelectionColumn = toVirtualColumn(view->cursorPosition()); | | |||
3108 | selectionRange.setRange(KTextEditor::Cursor(selectionRange.start().line(), fromVirtualColumn(selectionRange.start().line(), newSelectionColumn)) | | |||
3109 | , KTextEditor::Cursor(selectionRange.end().line(), fromVirtualColumn(selectionRange.end().line(), newSelectionColumn))); | | |||
3110 | view->setSelection(selectionRange); | | |||
3111 | } else { | 3126 | } else { | ||
3112 | chars = eventuallyReplaceTabs(view->cursorPosition(), chars); | 3127 | chars = eventuallyReplaceTabs(view->cursorPosition(), chars); | ||
3113 | insertText(view->cursorPosition(), chars); | 3128 | insertText(view->cursorPosition(), chars); | ||
3114 | } | 3129 | } | ||
3115 | 3130 | | |||
3116 | /** | 3131 | /** | ||
3117 | * auto bracket handling for newly inserted text | 3132 | * auto bracket handling for newly inserted text | ||
3118 | * we inserted a bracket? | 3133 | * we inserted a bracket? | ||
▲ Show 20 Lines • Show All 2051 Lines • ▼ Show 20 Line(s) | 5184 | { | |||
5170 | return KTextEditor::Cursor(lastLine(), lineLength(lastLine())); | 5185 | return KTextEditor::Cursor(lastLine(), lineLength(lastLine())); | ||
5171 | } | 5186 | } | ||
5172 | 5187 | | |||
5173 | bool KTextEditor::DocumentPrivate::replaceText(const KTextEditor::Range &range, const QString &s, bool block) | 5188 | bool KTextEditor::DocumentPrivate::replaceText(const KTextEditor::Range &range, const QString &s, bool block) | ||
5174 | { | 5189 | { | ||
5175 | // TODO more efficient? | 5190 | // TODO more efficient? | ||
5176 | editStart(); | 5191 | editStart(); | ||
5177 | bool changed = removeText(range, block); | 5192 | bool changed = removeText(range, block); | ||
5193 | | ||||
5194 | if (block && activeView() != nullptr && activeView()->selection()) { | ||||
5195 | changed |= insertTextInBlock(static_cast<KTextEditor::ViewPrivate *>(activeView()), s); | ||||
5196 | } else { | ||||
5178 | changed |= insertText(range.start(), s, block); | 5197 | changed |= insertText(range.start(), s, block); | ||
5198 | } | ||||
5199 | | ||||
5179 | editEnd(); | 5200 | editEnd(); | ||
5180 | return changed; | 5201 | return changed; | ||
5181 | } | 5202 | } | ||
5182 | 5203 | | |||
5183 | KateHighlighting *KTextEditor::DocumentPrivate::highlight() const | 5204 | KateHighlighting *KTextEditor::DocumentPrivate::highlight() const | ||
5184 | { | 5205 | { | ||
5185 | return m_buffer->highlight(); | 5206 | return m_buffer->highlight(); | ||
5186 | } | 5207 | } | ||
▲ Show 20 Lines • Show All 813 Lines • Show Last 20 Lines |