forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user