Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 3020 Lines • ▼ Show 20 Line(s) | 3018 | if (view->config()->autoBrackets() && chars.size() == 1) { | |||
---|---|---|---|---|---|
3021 | * we inserted a bracket? | 3021 | * we inserted a bracket? | ||
3022 | * => remember the matching closing one | 3022 | * => remember the matching closing one | ||
3023 | */ | 3023 | */ | ||
3024 | closingBracket = matchingEndBracket(typedChar); | 3024 | closingBracket = matchingEndBracket(typedChar); | ||
3025 | 3025 | | |||
3026 | /** | 3026 | /** | ||
3027 | * closing bracket for the autobracket we inserted earlier? | 3027 | * closing bracket for the autobracket we inserted earlier? | ||
3028 | */ | 3028 | */ | ||
3029 | if (m_currentAutobraceClosingChar == typedChar && m_currentAutobraceRange) { | 3029 | if (m_currentAutobraceClosingChars.back() == typedChar && !m_currentAutobraceRanges.empty()) { | ||
3030 | // do nothing | 3030 | // do nothing | ||
3031 | m_currentAutobraceRange.reset(nullptr); | 3031 | m_currentAutobraceRanges.pop_back(); | ||
3032 | m_currentAutobraceClosingChars.pop_back(); | ||||
3032 | view->cursorRight(); | 3033 | view->cursorRight(); | ||
3033 | return true; | 3034 | return true; | ||
3034 | } | 3035 | } | ||
3035 | } | 3036 | } | ||
3036 | 3037 | | |||
3037 | /** | 3038 | /** | ||
3038 | * selection around => special handling if we want to add auto brackets | 3039 | * selection around => special handling if we want to add auto brackets | ||
3039 | */ | 3040 | */ | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 3065 | else { | |||
3141 | 3142 | | |||
3142 | if (!closingBracket.isNull() && !skipAutobrace) { | 3143 | if (!closingBracket.isNull() && !skipAutobrace) { | ||
3143 | // add bracket to the view | 3144 | // add bracket to the view | ||
3144 | const auto nextChar = view->document()->text({cursorPos, cursorPos + Cursor{0, 1}}).trimmed(); | 3145 | const auto nextChar = view->document()->text({cursorPos, cursorPos + Cursor{0, 1}}).trimmed(); | ||
3145 | if (nextChar.isEmpty() || !nextChar.at(0).isLetterOrNumber()) { | 3146 | if (nextChar.isEmpty() || !nextChar.at(0).isLetterOrNumber()) { | ||
3146 | insertText(view->cursorPosition(), QString(closingBracket)); | 3147 | insertText(view->cursorPosition(), QString(closingBracket)); | ||
3147 | const auto insertedAt(view->cursorPosition()); | 3148 | const auto insertedAt(view->cursorPosition()); | ||
3148 | view->setCursorPosition(cursorPos); | 3149 | view->setCursorPosition(cursorPos); | ||
3149 | m_currentAutobraceRange.reset(newMovingRange({cursorPos - Cursor{0, 1}, insertedAt}, | 3150 | QSharedPointer<KTextEditor::MovingRange> newRange(newMovingRange({cursorPos - Cursor{0, 1}, insertedAt}, | ||
3150 | KTextEditor::MovingRange::DoNotExpand)); | 3151 | KTextEditor::MovingRange::DoNotExpand)); | ||
3152 | m_currentAutobraceRanges.push_back(newRange); | ||||
3151 | connect(view, &View::cursorPositionChanged, | 3153 | connect(view, &View::cursorPositionChanged, | ||
3152 | this, &DocumentPrivate::checkCursorForAutobrace, Qt::UniqueConnection); | 3154 | this, &DocumentPrivate::checkCursorForAutobrace, Qt::UniqueConnection); | ||
3153 | 3155 | | |||
3154 | // add bracket to chars inserted! needed for correct signals + indent | 3156 | // add bracket to chars inserted! needed for correct signals + indent | ||
3155 | chars.append(closingBracket); | 3157 | chars.append(closingBracket); | ||
3156 | } | 3158 | } | ||
3157 | m_currentAutobraceClosingChar = closingBracket; | 3159 | m_currentAutobraceClosingChars.push_back(closingBracket); | ||
3158 | } | 3160 | } | ||
3159 | 3161 | | |||
3160 | // end edit session here, to have updated HL in userTypedChar! | 3162 | // end edit session here, to have updated HL in userTypedChar! | ||
3161 | editEnd(); | 3163 | editEnd(); | ||
3162 | 3164 | | |||
3163 | // trigger indentation | 3165 | // trigger indentation | ||
3164 | KTextEditor::Cursor b(view->cursorPosition()); | 3166 | KTextEditor::Cursor b(view->cursorPosition()); | ||
3165 | m_indenter->userTypedChar(view, b, chars.isEmpty() ? QChar() : chars.at(chars.length() - 1)); | 3167 | m_indenter->userTypedChar(view, b, chars.isEmpty() ? QChar() : chars.at(chars.length() - 1)); | ||
3166 | 3168 | | |||
3167 | /** | 3169 | /** | ||
3168 | * inform the view about the original inserted chars | 3170 | * inform the view about the original inserted chars | ||
3169 | */ | 3171 | */ | ||
3170 | view->slotTextInserted(view, oldCur, chars); | 3172 | view->slotTextInserted(view, oldCur, chars); | ||
3171 | } | 3173 | } | ||
3172 | 3174 | | |||
3173 | /** | 3175 | /** | ||
3174 | * be done | 3176 | * be done | ||
3175 | */ | 3177 | */ | ||
3176 | return true; | 3178 | return true; | ||
3177 | } | 3179 | } | ||
3178 | 3180 | | |||
3179 | void KTextEditor::DocumentPrivate::checkCursorForAutobrace(KTextEditor::View*, const KTextEditor::Cursor& newPos) { | 3181 | void KTextEditor::DocumentPrivate::checkCursorForAutobrace(KTextEditor::View*, const KTextEditor::Cursor& newPos) { | ||
3180 | if ( m_currentAutobraceRange && ! m_currentAutobraceRange->toRange().contains(newPos) ) { | 3182 | while ( !m_currentAutobraceRanges.empty() && !m_currentAutobraceRanges.back()->toRange().contains(newPos) ) { | ||
3181 | m_currentAutobraceRange.clear(); | 3183 | m_currentAutobraceRanges.pop_back(); | ||
3184 | m_currentAutobraceClosingChars.pop_back(); | ||||
3182 | } | 3185 | } | ||
3183 | } | 3186 | } | ||
3184 | 3187 | | |||
3185 | void KTextEditor::DocumentPrivate::newLine(KTextEditor::ViewPrivate *v) | 3188 | void KTextEditor::DocumentPrivate::newLine(KTextEditor::ViewPrivate *v) | ||
3186 | { | 3189 | { | ||
3187 | editStart(); | 3190 | editStart(); | ||
3188 | 3191 | | |||
3189 | if (!v->config()->persistentSelection() && v->selection()) { | 3192 | if (!v->config()->persistentSelection() && v->selection()) { | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 3325 | if (line >= 1) { | |||
3330 | if (config()->wordWrap() && textLine->endsWith(QLatin1String(" "))) { | 3333 | if (config()->wordWrap() && textLine->endsWith(QLatin1String(" "))) { | ||
3331 | // gg: in hard wordwrap mode, backspace must also eat the trailing space | 3334 | // gg: in hard wordwrap mode, backspace must also eat the trailing space | ||
3332 | removeText(KTextEditor::Range(line - 1, textLine->length() - 1, line, 0)); | 3335 | removeText(KTextEditor::Range(line - 1, textLine->length() - 1, line, 0)); | ||
3333 | } else { | 3336 | } else { | ||
3334 | removeText(KTextEditor::Range(line - 1, textLine->length(), line, 0)); | 3337 | removeText(KTextEditor::Range(line - 1, textLine->length(), line, 0)); | ||
3335 | } | 3338 | } | ||
3336 | } | 3339 | } | ||
3337 | } | 3340 | } | ||
3338 | if ( m_currentAutobraceRange ) { | 3341 | if ( !m_currentAutobraceRanges.empty() ) { | ||
3339 | const auto r = m_currentAutobraceRange->toRange(); | 3342 | const auto r = m_currentAutobraceRanges.back()->toRange(); | ||
3340 | if ( r.columnWidth() == 1 && view->cursorPosition() == r.start() ) { | 3343 | if ( r.columnWidth() == 1 && view->cursorPosition() == r.start() ) { | ||
3341 | // start parenthesis removed and range length is 1, remove end as well | 3344 | // start parenthesis removed and range length is 1, remove end as well | ||
3342 | del(view, view->cursorPosition()); | 3345 | del(view, view->cursorPosition()); | ||
3343 | m_currentAutobraceRange.clear(); | | |||
3344 | } | 3346 | } | ||
3345 | } | 3347 | } | ||
3346 | } | 3348 | } | ||
3347 | 3349 | | |||
3348 | void KTextEditor::DocumentPrivate::del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | 3350 | void KTextEditor::DocumentPrivate::del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | ||
3349 | { | 3351 | { | ||
3350 | if (!view->config()->persistentSelection() && view->selection()) { | 3352 | if (!view->config()->persistentSelection() && view->selection()) { | ||
3351 | if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) { | 3353 | if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) { | ||
▲ Show 20 Lines • Show All 2662 Lines • Show Last 20 Lines |