Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 3210 | { | |||
---|---|---|---|---|---|
3238 | editRemoveText(line, col, 2); | 3238 | editRemoveText(line, col, 2); | ||
3239 | editInsertText(line, col, s); | 3239 | editInsertText(line, col, s); | ||
3240 | editEnd(); | 3240 | editEnd(); | ||
3241 | } | 3241 | } | ||
3242 | 3242 | | |||
3243 | void KTextEditor::DocumentPrivate::backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | 3243 | void KTextEditor::DocumentPrivate::backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | ||
3244 | { | 3244 | { | ||
3245 | if (!view->config()->persistentSelection() && view->selection()) { | 3245 | if (!view->config()->persistentSelection() && view->selection()) { | ||
3246 | if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) { | 3246 | KTextEditor::Range range = view->selectionRange(); | ||
3247 | // Remove one character after selection line | 3247 | editStart(); // Avoid bad selection in case of undo | ||
3248 | KTextEditor::Range range = view->selectionRange(); | 3248 | if (view->blockSelection() && view->selection() && range.start().column() > 0 | ||
3249 | && toVirtualColumn(range.start()) == toVirtualColumn(range.end())) { | ||||
3250 | // Remove one character before vertical selection line by expanding the selection | ||||
3249 | range.setStart(KTextEditor::Cursor(range.start().line(), range.start().column() - 1)); | 3251 | range.setStart(KTextEditor::Cursor(range.start().line(), range.start().column() - 1)); | ||
3250 | view->setSelection(range); | 3252 | view->setSelection(range); | ||
3251 | } | 3253 | } | ||
3252 | view->removeSelectedText(); | 3254 | view->removeSelectedText(); | ||
3255 | editEnd(); | ||||
3253 | return; | 3256 | return; | ||
3254 | } | 3257 | } | ||
3255 | 3258 | | |||
3256 | uint col = qMax(c.column(), 0); | 3259 | uint col = qMax(c.column(), 0); | ||
3257 | uint line = qMax(c.line(), 0); | 3260 | uint line = qMax(c.line(), 0); | ||
3258 | | ||||
3259 | if ((col == 0) && (line == 0)) { | 3261 | if ((col == 0) && (line == 0)) { | ||
3260 | return; | 3262 | return; | ||
3261 | } | 3263 | } | ||
3262 | 3264 | | |||
3265 | const Kate::TextLine textLine = m_buffer->plainLine(line); | ||||
3266 | // don't forget this check!!!! really!!!! | ||||
3267 | if (!textLine) { | ||||
3268 | return; | ||||
3269 | } | ||||
3270 | | ||||
3263 | if (col > 0) { | 3271 | if (col > 0) { | ||
3264 | bool useNextBlock = false; | 3272 | bool useNextBlock = false; | ||
3265 | if (config()->backspaceIndents()) { | 3273 | if (config()->backspaceIndents()) { | ||
3266 | // backspace indents: erase to next indent position | 3274 | // backspace indents: erase to next indent position | ||
3267 | Kate::TextLine textLine = m_buffer->plainLine(line); | | |||
3268 | | ||||
3269 | // don't forget this check!!!! really!!!! | | |||
3270 | if (!textLine) { | | |||
3271 | return; | | |||
3272 | } | | |||
3273 | | ||||
3274 | int colX = textLine->toVirtualColumn(col, config()->tabWidth()); | 3275 | int colX = textLine->toVirtualColumn(col, config()->tabWidth()); | ||
3275 | int pos = textLine->firstChar(); | 3276 | int pos = textLine->firstChar(); | ||
3276 | if (pos > 0) { | 3277 | if (pos > 0) { | ||
3277 | pos = textLine->toVirtualColumn(pos, config()->tabWidth()); | 3278 | pos = textLine->toVirtualColumn(pos, config()->tabWidth()); | ||
3278 | } | 3279 | } | ||
3279 | | ||||
3280 | if (pos < 0 || pos >= (int)colX) { | 3280 | if (pos < 0 || pos >= (int)colX) { | ||
3281 | // only spaces on left side of cursor | 3281 | // only spaces on left side of cursor | ||
3282 | indent(KTextEditor::Range(line, 0, line, 0), -1); | 3282 | indent(KTextEditor::Range(line, 0, line, 0), -1); | ||
3283 | } | 3283 | } else { | ||
3284 | else { | | |||
3285 | useNextBlock = true; | 3284 | useNextBlock = true; | ||
3286 | } | 3285 | } | ||
3287 | } | 3286 | } | ||
3288 | if (!config()->backspaceIndents() || useNextBlock) { | 3287 | if (!config()->backspaceIndents() || useNextBlock) { | ||
3289 | KTextEditor::Cursor beginCursor(line, 0); | 3288 | KTextEditor::Cursor beginCursor(line, 0); | ||
3290 | KTextEditor::Cursor endCursor(line, col); | 3289 | KTextEditor::Cursor endCursor(line, col); | ||
3291 | if (!view->config()->backspaceRemoveComposed()) { // Normal backspace behavior | 3290 | if (!view->config()->backspaceRemoveComposed()) { // Normal backspace behavior | ||
3292 | beginCursor.setColumn(col - 1); | 3291 | beginCursor.setColumn(col - 1); | ||
3293 | // move to left of surrogate pair | 3292 | // move to left of surrogate pair | ||
3294 | if (!isValidTextPosition(beginCursor)) { | 3293 | if (!isValidTextPosition(beginCursor)) { | ||
3295 | Q_ASSERT(col >= 2); | 3294 | Q_ASSERT(col >= 2); | ||
3296 | beginCursor.setColumn(col - 2); | 3295 | beginCursor.setColumn(col - 2); | ||
3297 | } | 3296 | } | ||
3298 | } else { | 3297 | } else { | ||
3299 | beginCursor.setColumn(view->textLayout(c)->previousCursorPosition(c.column())); | 3298 | beginCursor.setColumn(view->textLayout(c)->previousCursorPosition(c.column())); | ||
3300 | } | 3299 | } | ||
3301 | removeText(KTextEditor::Range(beginCursor, endCursor)); | 3300 | removeText(KTextEditor::Range(beginCursor, endCursor)); | ||
3302 | // in most cases cursor is moved by removeText, but we should do it manually | 3301 | // in most cases cursor is moved by removeText, but we should do it manually | ||
3303 | // for past-end-of-line cursors in block mode | 3302 | // for past-end-of-line cursors in block mode | ||
3304 | view->setCursorPosition(beginCursor); | 3303 | view->setCursorPosition(beginCursor); | ||
3305 | } | 3304 | } | ||
3305 | | ||||
3306 | } else { | 3306 | } else { | ||
3307 | // col == 0: wrap to previous line | 3307 | // col == 0: wrap to previous line | ||
3308 | if (line >= 1) { | 3308 | if (line > 0) { | ||
3309 | Kate::TextLine textLine = m_buffer->plainLine(line - 1); | | |||
3310 | | ||||
3311 | // don't forget this check!!!! really!!!! | | |||
3312 | if (!textLine) { | | |||
3313 | return; | | |||
3314 | } | | |||
3315 | | ||||
3316 | if (config()->wordWrap() && textLine->endsWith(QLatin1String(" "))) { | 3309 | if (config()->wordWrap() && textLine->endsWith(QLatin1String(" "))) { | ||
3317 | // gg: in hard wordwrap mode, backspace must also eat the trailing space | 3310 | // gg: in hard wordwrap mode, backspace must also eat the trailing space | ||
3318 | removeText(KTextEditor::Range(line - 1, textLine->length() - 1, line, 0)); | 3311 | removeText(KTextEditor::Range(line - 1, textLine->length() - 1, line, 0)); | ||
3319 | } else { | 3312 | } else { | ||
3320 | removeText(KTextEditor::Range(line - 1, textLine->length(), line, 0)); | 3313 | removeText(KTextEditor::Range(line - 1, textLine->length(), line, 0)); | ||
3321 | } | 3314 | } | ||
3322 | } | 3315 | } | ||
3323 | } | 3316 | } | ||
3324 | if ( m_currentAutobraceRange ) { | 3317 | | ||
3318 | if (m_currentAutobraceRange) { | ||||
3325 | const auto r = m_currentAutobraceRange->toRange(); | 3319 | const auto r = m_currentAutobraceRange->toRange(); | ||
3326 | if ( r.columnWidth() == 1 && view->cursorPosition() == r.start() ) { | 3320 | if (r.columnWidth() == 1 && view->cursorPosition() == r.start()) { | ||
3327 | // start parenthesis removed and range length is 1, remove end as well | 3321 | // start parenthesis removed and range length is 1, remove end as well | ||
3328 | del(view, view->cursorPosition()); | 3322 | del(view, view->cursorPosition()); | ||
3329 | m_currentAutobraceRange.clear(); | 3323 | m_currentAutobraceRange.clear(); | ||
3330 | } | 3324 | } | ||
3331 | } | 3325 | } | ||
3332 | } | 3326 | } | ||
3333 | 3327 | | |||
3334 | void KTextEditor::DocumentPrivate::del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | 3328 | void KTextEditor::DocumentPrivate::del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &c) | ||
3335 | { | 3329 | { | ||
3336 | if (!view->config()->persistentSelection() && view->selection()) { | 3330 | if (!view->config()->persistentSelection() && view->selection()) { | ||
3337 | if (view->blockSelection() && view->selection() && toVirtualColumn(view->selectionRange().start()) == toVirtualColumn(view->selectionRange().end())) { | 3331 | KTextEditor::Range range = view->selectionRange(); | ||
3338 | // Remove one character after selection line | 3332 | editStart(); // Avoid bad selection in case of undo | ||
3339 | KTextEditor::Range range = view->selectionRange(); | 3333 | if (view->blockSelection() && toVirtualColumn(range.start()) == toVirtualColumn(range.end())) { | ||
3334 | // Remove one character after vertical selection line by expanding the selection | ||||
3340 | range.setEnd(KTextEditor::Cursor(range.end().line(), range.end().column() + 1)); | 3335 | range.setEnd(KTextEditor::Cursor(range.end().line(), range.end().column() + 1)); | ||
3341 | view->setSelection(range); | 3336 | view->setSelection(range); | ||
3342 | } | 3337 | } | ||
3343 | view->removeSelectedText(); | 3338 | view->removeSelectedText(); | ||
3339 | editEnd(); | ||||
3344 | return; | 3340 | return; | ||
3345 | } | 3341 | } | ||
3346 | 3342 | | |||
3347 | if (c.column() < (int) m_buffer->plainLine(c.line())->length()) { | 3343 | if (c.column() < (int) m_buffer->plainLine(c.line())->length()) { | ||
3348 | KTextEditor::Cursor endCursor(c.line(), view->textLayout(c)->nextCursorPosition(c.column())); | 3344 | KTextEditor::Cursor endCursor(c.line(), view->textLayout(c)->nextCursorPosition(c.column())); | ||
3349 | | ||||
3350 | removeText(KTextEditor::Range(c, endCursor)); | 3345 | removeText(KTextEditor::Range(c, endCursor)); | ||
3351 | } else if (c.line() < lastLine()) { | 3346 | } else if (c.line() < lastLine()) { | ||
3352 | removeText(KTextEditor::Range(c.line(), c.column(), c.line() + 1, 0)); | 3347 | removeText(KTextEditor::Range(c.line(), c.column(), c.line() + 1, 0)); | ||
3353 | } | 3348 | } | ||
3354 | } | 3349 | } | ||
3355 | 3350 | | |||
3356 | void KTextEditor::DocumentPrivate::paste(KTextEditor::ViewPrivate *view, const QString &text) | 3351 | void KTextEditor::DocumentPrivate::paste(KTextEditor::ViewPrivate *view, const QString &text) | ||
3357 | { | 3352 | { | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |