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