diff options
author | Yuya Nishihara <yuya@tcha.org> | 2020-04-20 22:48:43 +0900 |
---|---|---|
committer | Yuya Nishihara <yuya@tcha.org> | 2020-04-22 10:46:30 +0000 |
commit | a112f029753f3255032695be9aacfceb6a730682 (patch) | |
tree | 2707dd62d6544e5097df1435f8135465603bd1f1 /src/plugins/emacskeys | |
parent | f51f3c897ed34156c652f768ba55a577ff7c87bf (diff) |
EmacsKeys: Replace U+2029 with LF when copying text to clipboard
Otherwise '\n' would be represented as U+2029 in clipboard, which is
useless.
Some of the cursor.selectedText() calls could be replaced with
QPlainTextEdit::copy(), which is backed by createMimeDataFromSelection(),
but there's a slight behavior difference such as EmacsKeysPlugin::copy()
does clear the selection. So I think it's better to consistently use the
lower-layer function.
Change-Id: Ida06b0c250774d80fb729224fd9492a35ea59b7d
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/emacskeys')
-rw-r--r-- | src/plugins/emacskeys/emacskeysplugin.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/plugins/emacskeys/emacskeysplugin.cpp b/src/plugins/emacskeys/emacskeysplugin.cpp index d1259d7eb7..300326f21d 100644 --- a/src/plugins/emacskeys/emacskeysplugin.cpp +++ b/src/plugins/emacskeys/emacskeysplugin.cpp @@ -49,6 +49,14 @@ QT_END_NAMESPACE using namespace Core; +namespace { +QString plainSelectedText(const QTextCursor &cursor) +{ + // selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline + return cursor.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n')); +} +} + namespace EmacsKeys { namespace Internal { @@ -216,7 +224,7 @@ void EmacsKeysPlugin::copy() m_currentState->beginOwnAction(); QTextCursor cursor = m_currentEditorWidget->textCursor(); - QApplication::clipboard()->setText(cursor.selectedText()); + QApplication::clipboard()->setText(plainSelectedText(cursor)); cursor.clearSelection(); m_currentEditorWidget->setTextCursor(cursor); m_currentState->setMark(-1); @@ -230,7 +238,7 @@ void EmacsKeysPlugin::cut() m_currentState->beginOwnAction(); QTextCursor cursor = m_currentEditorWidget->textCursor(); - QApplication::clipboard()->setText(cursor.selectedText()); + QApplication::clipboard()->setText(plainSelectedText(cursor)); cursor.removeSelectedText(); m_currentState->setMark(-1); m_currentState->endOwnAction(KeysActionOther); @@ -268,9 +276,9 @@ void EmacsKeysPlugin::killWord() cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); if (m_currentState->lastAction() == KeysActionKillWord) { QApplication::clipboard()->setText( - QApplication::clipboard()->text() + cursor.selectedText()); + QApplication::clipboard()->text() + plainSelectedText(cursor)); } else { - QApplication::clipboard()->setText(cursor.selectedText()); + QApplication::clipboard()->setText(plainSelectedText(cursor)); } cursor.removeSelectedText(); m_currentState->endOwnAction(KeysActionKillWord); @@ -291,9 +299,9 @@ void EmacsKeysPlugin::killLine() } if (m_currentState->lastAction() == KeysActionKillLine) { QApplication::clipboard()->setText( - QApplication::clipboard()->text() + cursor.selectedText()); + QApplication::clipboard()->text() + plainSelectedText(cursor)); } else { - QApplication::clipboard()->setText(cursor.selectedText()); + QApplication::clipboard()->setText(plainSelectedText(cursor)); } cursor.removeSelectedText(); m_currentState->endOwnAction(KeysActionKillLine); |