Commit 9bc892ef authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg

Paste urls of local files as a list of quoted strings

When pasting urls of local files, remove the the scheme part, "file://",
and paste the urls as a space-separated list of local file paths, which
are quoted as needed.

Commands such as cp, mv, ls... etc, don't understand/parse the file://
bit of local urls, therefore it's more useful to strip the scheme for local

CCBUG: 408813
parent c83bb19a
......@@ -3332,7 +3332,27 @@ void TerminalDisplay::copyToClipboard()
void TerminalDisplay::pasteFromClipboard(bool appendEnter)
QString text = QApplication::clipboard()->text(QClipboard::Clipboard);
QString text;
const QMimeData *mimeData = QApplication::clipboard()->mimeData(QClipboard::Clipboard);
// When pasting urls of local files:
// - remove the scheme part, "file://"
// - paste the path(s) as a space-separated list of strings, which are quoted if needed
if (!mimeData->hasUrls()) { // fast path if there are no urls
text = mimeData->text();
} else { // handle local file urls
const QList<QUrl> list = mimeData->urls();
for (const QUrl &url : list) {
if (url.isLocalFile()) {
text += KShell::quoteArg(url.toLocalFile());
text += QLatin1Char(' ');
} else { // can users copy urls of both local and remote files at the same time?
text = mimeData->text();
doPaste(text, appendEnter);
......@@ -392,8 +392,11 @@ public Q_SLOTS:
void copyToClipboard();
* Pastes the content of the clipboard into the
* display.
* Pastes the content of the clipboard into the display.
* URLs of local files are treated specially:
* - The scheme part, "file://", is removed from each URL
* - The URLs are pasted as a space-separated list of file paths
void pasteFromClipboard(bool appendEnter = false);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment