Skip to content

Commit

Permalink
QTBUG-57933 Cocoa: Check if charactersIgnoringModifiers is not empty too
Browse files Browse the repository at this point in the history
If a dead key occurs as a result of pressing a key combination then
characters will have 0 length, but charactersIgnoringModifiers will
have a valid character in it. This enables key combinations such as
ALT+E to be used as a shortcut with an English keyboard even though
pressing ALT+E will give a dead key while doing normal text input.
  • Loading branch information
Felix Bourbonnais committed Apr 26, 2018
1 parent b80dbec commit b48948c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/plugins/platforms/cocoa/qnsview.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1574,10 +1574,16 @@ - (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType

QChar ch = QChar::ReplacementCharacter;
int keyCode = Qt::Key_unknown;
if ([characters length] != 0) {

// If a dead key occurs as a result of pressing a key combination then
// characters will have 0 length, but charactersIgnoringModifiers will
// have a valid character in it. This enables key combinations such as
// ALT+E to be used as a shortcut with an English keyboard even though
// pressing ALT+E will give a dead key while doing normal text input.
if ([characters length] != 0 || [charactersIgnoringModifiers length] != 0) {
if (((modifiers & Qt::MetaModifier) || (modifiers & Qt::AltModifier)) && ([charactersIgnoringModifiers length] != 0))
ch = QChar([charactersIgnoringModifiers characterAtIndex:0]);
else
else if ([characters length] != 0)
ch = QChar([characters characterAtIndex:0]);
keyCode = [self convertKeyCode:ch];
}
Expand Down

0 comments on commit b48948c

Please sign in to comment.