Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 3007 Lines • ▼ Show 20 Line(s) | 3005 | { | |||
---|---|---|---|---|---|
3008 | */ | 3008 | */ | ||
3009 | const auto realUcs4Chars = realChars.toUcs4(); | 3009 | const auto realUcs4Chars = realChars.toUcs4(); | ||
3010 | QVector<uint> ucs4Chars; | 3010 | QVector<uint> ucs4Chars; | ||
3011 | Q_FOREACH (auto c, realUcs4Chars) | 3011 | Q_FOREACH (auto c, realUcs4Chars) | ||
3012 | if (QChar::isPrint(c) || c == QChar::fromLatin1('\t') || c == QChar::fromLatin1('\n') || c == QChar::fromLatin1('\r')) { | 3012 | if (QChar::isPrint(c) || c == QChar::fromLatin1('\t') || c == QChar::fromLatin1('\n') || c == QChar::fromLatin1('\r')) { | ||
3013 | ucs4Chars.append(c); | 3013 | ucs4Chars.append(c); | ||
3014 | } | 3014 | } | ||
3015 | 3015 | | |||
3016 | QString chars = QString::fromUcs4(ucs4Chars.data(), ucs4Chars.size()); | | |||
3017 | /** | 3016 | /** | ||
3018 | * no printable chars => nothing to insert! | 3017 | * no printable chars => nothing to insert! | ||
3019 | */ | 3018 | */ | ||
3019 | QString chars = QString::fromUcs4(ucs4Chars.data(), ucs4Chars.size()); | ||||
3020 | if (chars.isEmpty()) { | 3020 | if (chars.isEmpty()) { | ||
3021 | return false; | 3021 | return false; | ||
3022 | } | 3022 | } | ||
3023 | 3023 | | |||
3024 | // auto bracket handling | ||||
3025 | QChar closingBracket; | ||||
3026 | if (view->config()->autoBrackets()) { | ||||
3024 | // Check if entered closing bracket is already balanced | 3027 | // Check if entered closing bracket is already balanced | ||
3025 | const QChar typedChar = chars.at(0); | 3028 | const QChar typedChar = chars.at(0); | ||
3026 | const QChar openBracket = matchingStartBracket(typedChar); | 3029 | const QChar openBracket = matchingStartBracket(typedChar); | ||
3027 | if (!openBracket.isNull()) { | 3030 | if (!openBracket.isNull()) { | ||
3028 | KTextEditor::Cursor curPos = view->cursorPosition(); | 3031 | KTextEditor::Cursor curPos = view->cursorPosition(); | ||
3029 | if ((characterAt(curPos) == typedChar) && findMatchingBracket(curPos, 123/*Which value may best?*/).isValid()) { | 3032 | if ((characterAt(curPos) == typedChar) && findMatchingBracket(curPos, 123/*Which value may best?*/).isValid()) { | ||
3030 | // Do nothing | 3033 | // Do nothing | ||
3031 | view->cursorRight(); | 3034 | view->cursorRight(); | ||
3032 | return true; | 3035 | return true; | ||
3033 | } | 3036 | } | ||
3034 | } | 3037 | } | ||
3035 | 3038 | | |||
3036 | /** | 3039 | // for newly inserted text: remember if we should auto add some bracket | ||
3037 | * auto bracket handling for newly inserted text | 3040 | if (chars.size() == 1) { | ||
3038 | * remember if we should auto add some | | |||
3039 | */ | | |||
3040 | QChar closingBracket; | | |||
3041 | if (view->config()->autoBrackets() && chars.size() == 1) { | | |||
3042 | const QChar typedChar = chars.at(0); | 3041 | const QChar typedChar = chars.at(0); | ||
3043 | /** | 3042 | // we inserted a bracket? => remember the matching closing one | ||
3044 | * we inserted a bracket? | | |||
3045 | * => remember the matching closing one | | |||
3046 | */ | | |||
3047 | closingBracket = matchingEndBracket(typedChar); | 3043 | closingBracket = matchingEndBracket(typedChar); | ||
3048 | 3044 | | |||
3049 | /** | 3045 | // closing bracket for the autobracket we inserted earlier? | ||
3050 | * closing bracket for the autobracket we inserted earlier? | | |||
3051 | */ | | |||
3052 | if (m_currentAutobraceClosingChar == typedChar && m_currentAutobraceRange) { | 3046 | if (m_currentAutobraceClosingChar == typedChar && m_currentAutobraceRange) { | ||
3053 | // do nothing | 3047 | // do nothing | ||
3054 | m_currentAutobraceRange.reset(nullptr); | 3048 | m_currentAutobraceRange.reset(nullptr); | ||
3055 | view->cursorRight(); | 3049 | view->cursorRight(); | ||
3056 | return true; | 3050 | return true; | ||
3057 | } | 3051 | } | ||
3058 | } | 3052 | } | ||
3053 | } | ||||
3059 | 3054 | | |||
3060 | editStart(); | 3055 | editStart(); | ||
3061 | 3056 | | |||
3062 | /** | 3057 | /** | ||
3063 | * special handling if we want to add auto brackets to a selection | 3058 | * special handling if we want to add auto brackets to a selection | ||
3064 | */ | 3059 | */ | ||
3065 | if (view->selection() && !closingBracket.isNull()) { | 3060 | if (view->selection() && !closingBracket.isNull()) { | ||
3066 | std::unique_ptr<KTextEditor::MovingRange> selectionRange(newMovingRange(view->selectionRange())); | 3061 | std::unique_ptr<KTextEditor::MovingRange> selectionRange(newMovingRange(view->selectionRange())); | ||
▲ Show 20 Lines • Show All 3045 Lines • Show Last 20 Lines |