diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-02-15 20:49:24 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-02-15 22:51:30 -0800 |
commit | b06ae5e6b71674a6fcd4ee78e120674668267465 (patch) | |
tree | e0c5492d9a501b623ec2da38127f31d5e541cbd5 | |
parent | d8bdc7307d77b73651ec1a81b33c4fb4ace60e7c (diff) | |
download | qtlocation-mapboxgl-b06ae5e6b71674a6fcd4ee78e120674668267465.tar.gz |
[macos] Make ± key bindings respect tab order, zoomEnabled
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 98f4a0569d..2bdd17934f 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1633,16 +1633,40 @@ public: #pragma mark Keyboard events - (void)keyDown:(NSEvent *)event { + // This is the recommended way to handle arrow key presses, causing + // methods like -moveUp: and -moveToBeginningOfParagraph: to be called + // for various standard keybindings. [self interpretKeyEvents:@[event]]; } -- (void)insertText:(NSString *)text { - BOOL textIsZoomCharacter = [@[@"-", @"=", @"+"] containsObject:text]; +// The following action methods are declared in NSResponder.h. - if (textIsZoomCharacter) { - [self adjustZoomLevelForKey:text]; - } else { - [super insertText:text]; +- (void)insertTab:(id)sender { + if (self.window.firstResponder == self) { + [self.window selectNextKeyView:self]; + } +} + +- (void)insertBacktab:(id)sender { + if (self.window.firstResponder == self) { + [self.window selectPreviousKeyView:self]; + } +} + +- (void)insertText:(NSString *)insertString { + switch (insertString.length == 1 ? [insertString characterAtIndex:0] : 0) { + case '-': + [self moveToEndOfParagraph:nil]; + break; + + case '+': + case '=': + [self moveToBeginningOfParagraph:nil]; + break; + + default: + [super insertText:insertString]; + break; } } @@ -1698,23 +1722,6 @@ public: _compass.hidden = !rotateEnabled; } -- (void)adjustZoomLevelForKey:(NSString *)key { - double newZoomLevel = self.zoomLevel; - unichar keyUnichar = [key characterAtIndex:0]; - switch(keyUnichar) { - case '-': { - newZoomLevel -= 1; - break; - } - case '=': - case '+': { - newZoomLevel += 1; - } - } - - [self setZoomLevel:newZoomLevel animated:YES]; -} - #pragma mark Ornaments /// Updates the zoom controls’ enabled state based on the current zoom level. |