Keep the user's shift; trust the text guess less
- A tapped shift (on or off) survives the field re-reporting its context: it lasts until a character is typed, the hint changes or a field is focused - An input-method reset forgets the guessed text and pending dead key, so double-space can't delete a character the keyboard never saw - Fields that state typing preferences only get capitals if they ask - Trackpad moves in fields without surrounding text make the guess unknown; Backspace removes a whole grapheme cluster from it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -150,6 +150,46 @@ private Q_SLOTS:
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Once);
|
||||
}
|
||||
|
||||
void fieldHintsCanOptOutOfCapitalization()
|
||||
{
|
||||
TextContext context = Field;
|
||||
context.hints = TextContext::AutoCompletion; // states preferences, no capitals among them
|
||||
controller->setContext(context);
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Off);
|
||||
context.hints |= TextContext::AutoCapitalization;
|
||||
controller->setContext(context);
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Once);
|
||||
}
|
||||
|
||||
void cursorMovesForgetTheGuessedText()
|
||||
{
|
||||
controller->resetContext(Field); // reports no text: we only know what we typed
|
||||
for (const char *c : {"h", "i", "."})
|
||||
tap(makeKey(KeyType::Character, QString::fromLatin1(c)));
|
||||
controller->moveCursor({-2, 0}); // now somewhere inside "Hi."
|
||||
tap(makeKey(KeyType::Space));
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Off);
|
||||
}
|
||||
|
||||
void contextReportKeepsTappedShift()
|
||||
{
|
||||
tap(makeKey(KeyType::Shift));
|
||||
controller->setContext(MidSentence); // unchanged text, re-reported
|
||||
tap(makeKey(KeyType::Character, u"a"_s));
|
||||
QCOMPARE(engine.output, u"A");
|
||||
}
|
||||
|
||||
void resetForgetsTextBefore()
|
||||
{
|
||||
TextContext context = MidSentence;
|
||||
context.textBeforeCursor = u"word "_s;
|
||||
controller->setContext(context);
|
||||
controller->setContext(Field); // input-method reset: no surrounding text
|
||||
tap(makeKey(KeyType::Space));
|
||||
QCOMPARE(engine.output, u" ");
|
||||
QCOMPARE(engine.mismatchedReplacements, 0);
|
||||
}
|
||||
|
||||
void doubleSpacePeriodCanBeTurnedOff()
|
||||
{
|
||||
controller->setOptions({.doubleSpacePeriod = false});
|
||||
|
||||
@@ -111,6 +111,46 @@ private Q_SLOTS:
|
||||
shift.characterTyped();
|
||||
QCOMPARE(shift.mode(), Mode::Off);
|
||||
}
|
||||
|
||||
void repeatedHintKeepsUserShift()
|
||||
{
|
||||
ShiftState shift;
|
||||
shift.setAutomatic(false);
|
||||
shift.press(0);
|
||||
shift.release();
|
||||
shift.setAutomatic(false); // the field re-reported
|
||||
QCOMPARE(shift.mode(), Mode::Once);
|
||||
}
|
||||
|
||||
void repeatedHintKeepsUserUnshift()
|
||||
{
|
||||
ShiftState shift;
|
||||
shift.setAutomatic(true);
|
||||
shift.press(0); // off at a sentence start
|
||||
shift.release();
|
||||
shift.setAutomatic(true);
|
||||
QCOMPARE(shift.mode(), Mode::Off);
|
||||
}
|
||||
|
||||
void changedHintOverridesUserShift()
|
||||
{
|
||||
ShiftState shift;
|
||||
shift.setAutomatic(true);
|
||||
shift.press(0);
|
||||
shift.release();
|
||||
shift.setAutomatic(false);
|
||||
shift.setAutomatic(true); // e.g. backspaced to a sentence start
|
||||
QCOMPARE(shift.mode(), Mode::Once);
|
||||
}
|
||||
|
||||
void hintAppliesAgainAfterTyping()
|
||||
{
|
||||
ShiftState shift;
|
||||
shift.setAutomatic(true);
|
||||
shift.characterTyped(); // e.g. a space at a sentence start
|
||||
shift.setAutomatic(true);
|
||||
QCOMPARE(shift.mode(), Mode::Once);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(TestShiftState)
|
||||
|
||||
@@ -44,6 +44,9 @@ private Q_SLOTS:
|
||||
{
|
||||
QCOMPARE(TextRules::withoutLastCharacter(u"ab"_s), u"a");
|
||||
QCOMPARE(TextRules::withoutLastCharacter(u"a👍"_s), u"a");
|
||||
QCOMPARE(TextRules::withoutLastCharacter(u"ae\u0301"_s), u"a"); // e + combining acute
|
||||
QCOMPARE(TextRules::withoutLastCharacter(u"a👍🏽"_s), u"a"); // with a skin tone
|
||||
QCOMPARE(TextRules::withoutLastCharacter(QString()), QString());
|
||||
QCOMPARE(TextRules::withoutLastWord(u"one two "_s), u"one ");
|
||||
QCOMPARE(TextRules::withoutLastWord(u"one"_s), QString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user