Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateviewinternal.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 3239 | { | |||
---|---|---|---|---|---|
3243 | if (event->mimeData()->hasUrls()) { | 3243 | if (event->mimeData()->hasUrls()) { | ||
3244 | emit dropEventPass(event); | 3244 | emit dropEventPass(event); | ||
3245 | return; | 3245 | return; | ||
3246 | } | 3246 | } | ||
3247 | 3247 | | |||
3248 | if (event->mimeData()->hasText() && doc()->isReadWrite()) { | 3248 | if (event->mimeData()->hasText() && doc()->isReadWrite()) { | ||
3249 | 3249 | | |||
3250 | const QString text = event->mimeData()->text(); | 3250 | const QString text = event->mimeData()->text(); | ||
3251 | 3251 | const bool blockMode = view()->blockSelection(); | |||
3252 | // is the source our own document? | | |||
3253 | bool priv = false; | | |||
3254 | if (KateViewInternal *vi = qobject_cast<KateViewInternal *>(event->source())) { | | |||
3255 | priv = doc()->ownedView(vi->m_view); | | |||
3256 | } | | |||
3257 | | ||||
3258 | // dropped on a text selection area? | | |||
3259 | bool selected = view()->cursorSelected(m_cursor); | | |||
3260 | 3252 | | |||
3261 | fixDropEvent(event); | 3253 | fixDropEvent(event); | ||
3262 | 3254 | | |||
3263 | if (priv && selected && event->dropAction() != Qt::CopyAction) { | 3255 | // Remember where to paste/move... | ||
3264 | // this is a drag that we started and dropped on our selection | 3256 | KTextEditor::Cursor targetCursor(m_cursor); | ||
3265 | // ignore this case | 3257 | // Use powerful MovingCursor to track our changes we may do | ||
3266 | return; | 3258 | std::unique_ptr<KTextEditor::MovingCursor> targetCursor2(doc()->newMovingCursor(m_cursor)); | ||
3267 | } | | |||
3268 | 3259 | | |||
3269 | // fix the cursor position before editStart(), so that it is correctly | 3260 | // As always need the BlockMode some special treatment | ||
3270 | // stored for the undo action | 3261 | const KTextEditor::Range selRange(view()->selectionRange()); | ||
3271 | KTextEditor::Cursor targetCursor(m_cursor); // backup current cursor | 3262 | const KTextEditor::Cursor blockAdjust(selRange.numberOfLines(), selRange.columnWidth()); | ||
3272 | int selectionWidth = view()->selectionRange().columnWidth(); // for block selection | | |||
3273 | int selectionHeight = view()->selectionRange().numberOfLines(); // for block selection | | |||
3274 | 3263 | | |||
3264 | // Restore the cursor position before editStart(), so that it is correctly stored for the undo action | ||||
3275 | if (event->dropAction() != Qt::CopyAction) { | 3265 | if (event->dropAction() != Qt::CopyAction) { | ||
3276 | editSetCursor(view()->selectionRange().end()); | 3266 | editSetCursor(selRange.end()); | ||
3277 | } else { | 3267 | } else { | ||
3278 | view()->clearSelection(); | 3268 | view()->clearSelection(); | ||
3279 | } | 3269 | } | ||
3280 | 3270 | | |||
3281 | // use one transaction | 3271 | // use one transaction | ||
3282 | doc()->editStart(); | 3272 | doc()->editStart(); | ||
3283 | 3273 | | |||
3284 | // on move: remove selected text; on copy: duplicate text | | |||
3285 | doc()->insertText(targetCursor, text, view()->blockSelection()); | | |||
3286 | | ||||
3287 | KTextEditor::DocumentCursor startCursor(doc(), targetCursor); | | |||
3288 | KTextEditor::DocumentCursor endCursor1(doc(), targetCursor); | | |||
3289 | const int textLength = text.length(); | | |||
3290 | | ||||
3291 | if (event->dropAction() != Qt::CopyAction) { | 3274 | if (event->dropAction() != Qt::CopyAction) { | ||
3292 | view()->removeSelectedText(); | 3275 | view()->removeSelectedText(); | ||
3293 | if (m_cursor.toCursor() < startCursor.toCursor()) { | 3276 | if (targetCursor2->toCursor() != targetCursor) { | ||
3294 | startCursor.move(-textLength); | 3277 | // Hm, multi line selection moved down, we need to adjust our dumb cursor | ||
3295 | endCursor1.move(-textLength); | 3278 | targetCursor = targetCursor2->toCursor(); | ||
3296 | } | 3279 | } | ||
3297 | } | 3280 | doc()->insertText(targetCursor2->toCursor(), text, blockMode); | ||
3298 | 3281 | | |||
3299 | if (!view()->blockSelection()) { | | |||
3300 | endCursor1.move(textLength); | | |||
3301 | } else { | 3282 | } else { | ||
3302 | endCursor1.setColumn(startCursor.column() + selectionWidth); | 3283 | doc()->insertText(targetCursor, text, blockMode); | ||
3303 | endCursor1.setLine(startCursor.line() + selectionHeight); | | |||
3304 | } | 3284 | } | ||
3305 | 3285 | | |||
3306 | KTextEditor::Cursor endCursor(endCursor1); | 3286 | if (blockMode) { | ||
3307 | qCDebug(LOG_KTE) << startCursor << "---(" << textLength << ")---" << endCursor; | 3287 | setSelection(KTextEditor::Range(targetCursor, targetCursor + blockAdjust)); | ||
3308 | setSelection(KTextEditor::Range(startCursor, endCursor)); | 3288 | //editSetCursor(targetCursor); My preffered position | ||
3309 | editSetCursor(endCursor); | 3289 | editSetCursor(targetCursor + blockAdjust); | ||
3290 | } else { | ||||
3291 | setSelection(KTextEditor::Range(targetCursor, targetCursor2->toCursor())); | ||||
3292 | //editSetCursor(targetCursor); My preffered position | ||||
3293 | editSetCursor(targetCursor2->toCursor()); // Just to satisfy autotest | ||||
3294 | } | ||||
3310 | 3295 | | |||
3311 | doc()->editEnd(); | 3296 | doc()->editEnd(); | ||
3312 | 3297 | | |||
3313 | event->acceptProposedAction(); | 3298 | event->acceptProposedAction(); | ||
3314 | updateView(); | 3299 | updateView(); | ||
3315 | } | 3300 | } | ||
3316 | 3301 | | |||
3317 | // finally finish drag and drop mode | 3302 | // finally finish drag and drop mode | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |