diff options
author | michi_cc <michi_cc@openttd.org> | 2014-08-24 10:34:43 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2014-08-24 10:34:43 +0000 |
commit | 2b3b8c93e7b39154c130f5fc98a6f7ce24ea4cf7 (patch) | |
tree | e29c1eb806b4ada9c5efc4034b46f5ebeb5a2b0d /src | |
parent | 9c5530762990939dd3b71a69ed8644b06cb3b61b (diff) | |
download | openttd-2b3b8c93e7b39154c130f5fc98a6f7ce24ea4cf7.tar.xz |
(svn r26758) -Fix [FS#5972]: [OSX] Implement more of the text editing API to prevent crashes and improve IME support.
Diffstat (limited to 'src')
-rw-r--r-- | src/textbuf.cpp | 6 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.mm | 86 | ||||
-rw-r--r-- | src/video/cocoa/event.mm | 13 |
3 files changed, 98 insertions, 7 deletions
diff --git a/src/textbuf.cpp b/src/textbuf.cpp index 116d60ba8..3d219e916 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -477,16 +477,10 @@ HandleKeyPressResult Textbuf::HandleKeyPress(WChar key, uint16 keycode) case WKC_RETURN: case WKC_NUM_ENTER: return HKPR_CONFIRM; -#ifdef WITH_COCOA - case (WKC_META | 'V'): -#endif case (WKC_CTRL | 'V'): edited = this->InsertClipboard(); break; -#ifdef WITH_COCOA - case (WKC_META | 'U'): -#endif case (WKC_CTRL | 'U'): this->DeleteAll(); edited = true; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 5665abb5b..e9b4b5b8f 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -1088,6 +1088,92 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) return 0; } +/** Delete single character left of the cursor. */ +- (void)deleteBackward:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_BACKSPACE, 0); +} + +/** Delete word left of the cursor. */ +- (void)deleteWordBackward:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_BACKSPACE | WKC_CTRL, 0); +} + +/** Delete single character right of the cursor. */ +- (void)deleteForward:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_DELETE, 0); +} + +/** Delete word right of the cursor. */ +- (void)deleteWordForward:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_DELETE | WKC_CTRL, 0); +} + +/** Move cursor one character left. */ +- (void)moveLeft:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_LEFT, 0); +} + +/** Move cursor one word left. */ +- (void)moveWordLeft:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_LEFT | WKC_CTRL, 0); +} + +/** Move cursor one character right. */ +- (void)moveRight:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_RIGHT, 0); +} + +/** Move cursor one word right. */ +- (void)moveWordRight:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_RIGHT | WKC_CTRL, 0); +} + +/** Move cursor to the start of the line. */ +- (void)moveToBeginningOfLine:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_HOME, 0); +} + +/** Move cursor to the end of the line. */ +- (void)moveToEndOfLine:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_END, 0); +} + +/** Scroll to the beginning of the document. */ +- (void)scrollToBeginningOfDocument:(id)sender +{ + /* For compatibility with OTTD on Win/Linux. */ + [ self moveToBeginningOfLine:sender ]; +} + +/** Scroll to the end of the document. */ +- (void)scrollToEndOfDocument:(id)sender +{ + /* For compatibility with OTTD on Win/Linux. */ + [ self moveToEndOfLine:sender ]; +} + +/** Return was pressed. */ +- (void)insertNewline:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_RETURN, '\r'); +} + +/** Escape was pressed. */ +- (void)cancelOperation:(id)sender +{ + if (EditBoxInGlobalFocus()) HandleKeypress(WKC_ESC, 0); +} + /** Invoke the selector if we implement it. */ - (void)doCommandBySelector:(SEL)aSelector { diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm index 78785f8d0..39e6cc445 100644 --- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -290,6 +290,17 @@ static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen); } break; + + case QZ_v: + if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) { + HandleKeypress(WKC_CTRL | 'V', unicode); + } + break; + case QZ_u: + if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) { + HandleKeypress(WKC_CTRL | 'U', unicode); + } + break; } if (down) { @@ -310,7 +321,7 @@ static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow console = false; /* Don't handle normal characters if an edit box has the focus. */ - if (!EditBoxInGlobalFocus() || ((pressed_key & ~WKC_SPECIAL_KEYS) <= WKC_TAB) || IsInsideMM(pressed_key & ~WKC_SPECIAL_KEYS, WKC_F1, WKC_PAUSE + 1)) { + if (!EditBoxInGlobalFocus() || IsInsideMM(pressed_key & ~WKC_SPECIAL_KEYS, WKC_F1, WKC_PAUSE + 1)) { HandleKeypress(pressed_key, unicode); } DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key); |