Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 3160 Lines • ▼ Show 20 Line(s) | 3149 | { | |||
---|---|---|---|---|---|
3161 | uint col = qMax(c.column(), 0); | 3161 | uint col = qMax(c.column(), 0); | ||
3162 | uint line = qMax(c.line(), 0); | 3162 | uint line = qMax(c.line(), 0); | ||
3163 | 3163 | | |||
3164 | if ((col == 0) && (line == 0)) { | 3164 | if ((col == 0) && (line == 0)) { | ||
3165 | return; | 3165 | return; | ||
3166 | } | 3166 | } | ||
3167 | 3167 | | |||
3168 | if (col > 0) { | 3168 | if (col > 0) { | ||
3169 | if (!(config()->backspaceIndents())) { | 3169 | if (!(config()->backspaceIndents())) { | ||
3170 | // ordinary backspace | 3170 | // ordinary backspace | ||
3171 | KTextEditor::Cursor beginCursor(line, view->textLayout(c)->previousCursorPosition(c.column())); | 3171 | KTextEditor::Cursor beginCursor(line, 0); | ||
3172 | KTextEditor::Cursor endCursor(line, col); | 3172 | KTextEditor::Cursor endCursor(line, col); | ||
dhaumann: I would prefer to have this if() only once:
KTextEditor::Cursor beginCursor(line… | |||||
3173 | 3173 | if (!view->config()->backspaceRemoveComposed()) { // Normal backspace behavior | |||
3174 | // move to left of surrogate pair | ||||
3175 | if (!isValidTextPosition(beginCursor)) { | ||||
3176 | Q_ASSERT(col >= 2); | ||||
3177 | beginCursor.setColumn(col - 2); | ||||
3178 | } | ||||
3179 | beginCursor.setColumn(col - 1); | ||||
3180 | } else { | ||||
3181 | beginCursor.setColumn(view->textLayout(c)->previousCursorPosition(c.column())); | ||||
3182 | } | ||||
3174 | removeText(KTextEditor::Range(beginCursor, endCursor)); | 3183 | removeText(KTextEditor::Range(beginCursor, endCursor)); | ||
3175 | // in most cases cursor is moved by removeText, but we should do it manually | 3184 | // in most cases cursor is moved by removeText, but we should do it manually | ||
3176 | // for past-end-of-line cursors in block mode | 3185 | // for past-end-of-line cursors in block mode | ||
3177 | view->setCursorPosition(beginCursor); | 3186 | view->setCursorPosition(beginCursor); | ||
3178 | } else { | 3187 | } else { | ||
3179 | // backspace indents: erase to next indent position | 3188 | // backspace indents: erase to next indent position | ||
3180 | Kate::TextLine textLine = m_buffer->plainLine(line); | 3189 | Kate::TextLine textLine = m_buffer->plainLine(line); | ||
3181 | 3190 | | |||
3182 | // don't forget this check!!!! really!!!! | 3191 | // don't forget this check!!!! really!!!! | ||
3183 | if (!textLine) { | 3192 | if (!textLine) { | ||
3184 | return; | 3193 | return; | ||
3185 | } | 3194 | } | ||
3186 | 3195 | | |||
3187 | int colX = textLine->toVirtualColumn(col, config()->tabWidth()); | 3196 | int colX = textLine->toVirtualColumn(col, config()->tabWidth()); | ||
3188 | int pos = textLine->firstChar(); | 3197 | int pos = textLine->firstChar(); | ||
3189 | if (pos > 0) { | 3198 | if (pos > 0) { | ||
3190 | pos = textLine->toVirtualColumn(pos, config()->tabWidth()); | 3199 | pos = textLine->toVirtualColumn(pos, config()->tabWidth()); | ||
3191 | } | 3200 | } | ||
3192 | 3201 | | |||
3193 | if (pos < 0 || pos >= (int)colX) { | 3202 | if (pos < 0 || pos >= (int)colX) { | ||
3194 | // only spaces on left side of cursor | 3203 | // only spaces on left side of cursor | ||
3195 | indent(KTextEditor::Range(line, 0, line, 0), -1); | 3204 | indent(KTextEditor::Range(line, 0, line, 0), -1); | ||
3196 | } else { | 3205 | } else { | ||
3197 | KTextEditor::Cursor beginCursor(line, view->textLayout(c)->previousCursorPosition(c.column())); | 3206 | KTextEditor::Cursor beginCursor(line, 0); | ||
Same here: Please if() case only once, which leads to less convoluted code. dhaumann: Same here: Please if() case only once, which leads to less convoluted code. | |||||
3198 | KTextEditor::Cursor endCursor(line, col); | 3207 | KTextEditor::Cursor endCursor(line, col); | ||
brauch: pos is not defined at this place | |||||
3199 | 3208 | if (!view->config()->backspaceRemoveComposed()) { // Normal backspace behavior | |||
3209 | // move to left of surrogate pair | ||||
3210 | if (!isValidTextPosition(beginCursor)) { | ||||
3211 | Q_ASSERT(col >= 2); | ||||
3212 | beginCursor.setColumn(col - 2); | ||||
3213 | } | ||||
3214 | beginCursor.setColumn(col - 1); | ||||
3215 | } else { | ||||
3216 | beginCursor.setColumn(view->textLayout(c)->previousCursorPosition(c.column())); | ||||
3217 | } | ||||
3200 | removeText(KTextEditor::Range(beginCursor, endCursor)); | 3218 | removeText(KTextEditor::Range(beginCursor, endCursor)); | ||
3201 | // in most cases cursor is moved by removeText, but we should do it manually | 3219 | // in most cases cursor is moved by removeText, but we should do it manually | ||
3202 | // for past-end-of-line cursors in block mode | 3220 | // for past-end-of-line cursors in block mode | ||
3203 | view->setCursorPosition(beginCursor); | 3221 | view->setCursorPosition(beginCursor); | ||
3204 | } | 3222 | } | ||
3205 | } | 3223 | } | ||
This peace of code should be simplified, to not have code dublication. if (config()->backspaceIndents()) { // backspace indents: erase to next indent position Kate::TextLine textLine = m_buffer->plainLine(line); // don't forget this check!!!! really!!!! if (!textLine) { return; } int colX = textLine->toVirtualColumn(col, config()->tabWidth()); int pos = textLine->firstChar(); if (pos > 0) { pos = textLine->toVirtualColumn(pos, config()->tabWidth()); } if (pos < 0 || pos >= (int)colX) { // only spaces on left side of cursor indent(KTextEditor::Range(line, 0, line, 0), -1); } } Then validate pos and add 2 backspace behaviors. anthonyfieroni: This peace of code should be simplified, to not have code dublication.
```
if (config()… | |||||
3206 | } else { | 3224 | } else { | ||
3207 | // col == 0: wrap to previous line | 3225 | // col == 0: wrap to previous line | ||
3208 | if (line >= 1) { | 3226 | if (line >= 1) { | ||
3209 | Kate::TextLine textLine = m_buffer->plainLine(line - 1); | 3227 | Kate::TextLine textLine = m_buffer->plainLine(line - 1); | ||
3210 | 3228 | | |||
3211 | // don't forget this check!!!! really!!!! | 3229 | // don't forget this check!!!! really!!!! | ||
3212 | if (!textLine) { | 3230 | if (!textLine) { | ||
3213 | return; | 3231 | return; | ||
▲ Show 20 Lines • Show All 2783 Lines • Show Last 20 Lines |
I would prefer to have this if() only once: