QLineEdit: Disable standard key 'cut' when there is no selection.
Task-number: QTBUG-40477 Change-Id: I0741a1a769c9e7e0d19e8aec231acc29461d44ea Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
9b599c6cea
commit
0aa84a619e
@ -1678,7 +1678,7 @@ void QWidgetLineControl::processKeyEvent(QKeyEvent* event)
|
||||
}
|
||||
}
|
||||
else if (event == QKeySequence::Cut) {
|
||||
if (!isReadOnly()) {
|
||||
if (!isReadOnly() && hasSelectedText()) {
|
||||
copy();
|
||||
del();
|
||||
}
|
||||
|
@ -244,6 +244,7 @@ private slots:
|
||||
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
void cut();
|
||||
void cutWithoutSelection();
|
||||
#endif
|
||||
void maxLengthAndInputMask();
|
||||
void returnPressedKeyEvent();
|
||||
@ -2977,7 +2978,37 @@ void tst_QLineEdit::cut()
|
||||
testWidget->cut();
|
||||
QCOMPARE(testWidget->text(), QString("Abcdefg defg hijklmno"));
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QLineEdit::cutWithoutSelection()
|
||||
{
|
||||
enum { selectionLength = 1 };
|
||||
|
||||
if (QKeySequence(QKeySequence::Cut).toString() != QLatin1String("Ctrl+X"))
|
||||
QSKIP("Platform with non-standard keybindings");
|
||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||
if (!PlatformClipboard::isAvailable()
|
||||
|| !QGuiApplication::platformName().compare("xcb", Qt::CaseInsensitive)) { // Avoid unstable X11 clipboard
|
||||
clipboard = Q_NULLPTR;
|
||||
}
|
||||
|
||||
if (clipboard)
|
||||
clipboard->clear();
|
||||
const QString origText = QStringLiteral("test");
|
||||
QLineEdit lineEdit(origText);
|
||||
lineEdit.setCursorPosition(0);
|
||||
QVERIFY(!lineEdit.hasSelectedText());
|
||||
QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
|
||||
QCOMPARE(lineEdit.text(), origText); // No selection, unmodified.
|
||||
if (clipboard)
|
||||
QVERIFY(clipboard->text().isEmpty());
|
||||
lineEdit.setSelection(0, selectionLength);
|
||||
QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier);
|
||||
QCOMPARE(lineEdit.text(), origText.right(origText.size() - selectionLength));
|
||||
if (clipboard)
|
||||
QCOMPARE(clipboard->text(), origText.left(selectionLength));
|
||||
}
|
||||
|
||||
#endif // !QT_NO_CLIPBOARD
|
||||
|
||||
class InputMaskValidator : public QValidator
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user