diff options
author | Neil Hodgson <nyamatongwe@gmail.com> | 2021-05-09 16:39:30 +1000 |
---|---|---|
committer | Neil Hodgson <nyamatongwe@gmail.com> | 2021-05-09 16:39:30 +1000 |
commit | 843ce05440fcd4ba7d19f8b612ab526c88296ad0 (patch) | |
tree | 964c741219c81d990ea9336c66a6803f16bf4a6b /cocoa | |
parent | 8827755d994e9ebb49097da51a4e460c56385774 (diff) | |
download | scintilla-mirror-843ce05440fcd4ba7d19f8b612ab526c88296ad0.tar.gz |
Change first responder / active handling so only treating as focussed when
both active and first responder.
This has no visual effect yet but allows greying the selection when not focussed.
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/ScintillaCocoa.h | 6 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 36 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 4 |
3 files changed, 34 insertions, 12 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index 841ba8f13..d07ffe758 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -97,6 +97,8 @@ private: intptr_t notifyObj; bool capturedMouse; + bool isFirstResponder; + bool isActive; bool enteredSetScrollingSize; @@ -242,7 +244,9 @@ public: NSMenu *CreateContextMenu(NSEvent *event); void HandleCommand(NSInteger command); - void ActiveStateChanged(bool isActive); + void SetFirstResponder(bool isFirstResponder_); + void ActiveStateChanged(bool isActive_); + void SetFocusActiveState(); void WindowWillMove(); // Find indicator diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 36ae35bd0..c4569144e 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -402,6 +402,8 @@ ScintillaCocoa::ScintillaCocoa(ScintillaView *sciView_, SCIContentView *viewCont notifyObj = NULL; notifyProc = NULL; capturedMouse = false; + isFirstResponder = false; + isActive = false; enteredSetScrollingSize = false; scrollSpeed = 1; scrollTicks = 2000; @@ -2494,15 +2496,31 @@ void ScintillaCocoa::HandleCommand(NSInteger command) { //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::ActiveStateChanged(bool isActive) { - // If the window is being deactivated, lose the focus and turn off the ticking - if (!isActive) { - DropCaret(); - //SetFocusState( false ); - FineTickerCancel(TickReason::caret); - } else { - ShowCaretAtCurrentPosition(); - } +/** + * Update 'isFirstResponder' and possibly change focus state. + */ +void ScintillaCocoa::SetFirstResponder(bool isFirstResponder_) { + isFirstResponder = isFirstResponder_; + SetFocusActiveState(); +} + +//-------------------------------------------------------------------------------------------------- + +/** + * Update 'isActive' and possibly change focus state. + */ +void ScintillaCocoa::ActiveStateChanged(bool isActive_) { + isActive = isActive_; + SetFocusActiveState(); +} + +//-------------------------------------------------------------------------------------------------- + +/** + * Update 'hasFocus' based on first responder and active status. + */ +void ScintillaCocoa::SetFocusActiveState() { + SetFocusState(isActive && isFirstResponder); } //-------------------------------------------------------------------------------------------------- diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index c0b2ee950..593722c1e 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -772,7 +772,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) { * The editor is getting the foreground control (the one getting the input focus). */ - (BOOL) becomeFirstResponder { - mOwner.backend->WndProc(SCI_SETFOCUS, 1, 0); + mOwner.backend->SetFirstResponder(true); return YES; } @@ -782,7 +782,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) { * The editor is losing the input focus. */ - (BOOL) resignFirstResponder { - mOwner.backend->WndProc(SCI_SETFOCUS, 0, 0); + mOwner.backend->SetFirstResponder(false); return YES; } |