diff options
author | Patrick Luby <plubius@neooffice.org> | 2022-12-03 13:41:23 -0500 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-08 09:33:38 +0000 |
commit | 9ee57f36e26373ee7144d076c93c3462c4fc7110 (patch) | |
tree | f9d6436a1e8e70cfd1738fd7030c0a45a417f1b7 /vcl/osx/vclnsapp.mm | |
parent | 60d2dd11a73bf7a1269896f15b1ec7c98507571e (diff) |
tdf#82115 Commit uncommitted text when a popup menu is opened
The Windows implementation of the SalFrame::EndExtTextInput() method commits or discards the native input method session. It appears that most macOS applications discard the uncommitted text when cancelling a session so always commit the uncommitted text. This change also commits any uncommitted text and cancels the native input method session whenever a window loses focus like in Safari, Firefox, and Excel.
Note: if there is any marked text, SalEvent::EndExtTextInput may leave the cursor hidden so commit the marked range to force the cursor to be visible.
Dispatching SalEvent::EndExtTextInput in SalFrame::EndExtTextInput() creates some other related native input method handling bugs that have also been fixed in this patch:
- Whenever a SalEvent::EndExtTextInput event is dispatched, cancel the native input method session so that the native input context's state is in sync with LibreOffice's internal state. The only exceptions are in [SalFrameView insertText:replacementRange:] or [SalFrameView setMarkedText:selectedRange:replacementRange:] because when these two selectors commit text, the native input method session has already been cancelled and calling [SalFrameView endExtTextInput] will cause repeated text insertions from the native macOS Character Viewer dialog to overwrite previous insertions.
- Highlight all characters in the selected range. Normally uncommitted text is underlined but when an item is selected in the native input method popup or selecting a subblock of uncommitted text using the left or right arrow keys, the selection range is set and the selected range is either highlighted like in Excel or is bold underlined like in Safari. Highlighting the selected range was chosen because highlighting was used in LibreOffice 7.4.x and using bold and double underlines can get clipped making the selection range indistinguishable from the rest of the uncommitted text.
- The fix for ooo#106901 always returns a zero length range if [self markedRange] called outside of mbInKeyInput. If a zero length range is returned, macOS won't call [self firstRectForCharacterRange:actualRange:] for any newly appended uncommitted text and the native input method popup will appear in the bottom left corner of the screen. So, [self markedRange] now returns the marked range if is valid.
- Commit uncommitted text before dispatching menu item selections and key shortcuts. In certain cases such as selecting the Insert > Comment menu item or pressing Command-Option-C in a Writer document while there is uncommitted text will call AquaSalFrame::EndExtTextInput() which will dispatch a SalEvent::EndExtTextInput event. Writer's handler for that event will delete the uncommitted text and then insert the committed text but LibreOffice will crash when deleting the uncommitted text because deletion of the text also removes and deletes the newly inserted comment.
Change-Id: I4ff4682aeef7d42ce26059aa76f971a68128833c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143619
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/osx/vclnsapp.mm')
-rw-r--r-- | vcl/osx/vclnsapp.mm | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/vcl/osx/vclnsapp.mm b/vcl/osx/vclnsapp.mm index d31b41b5f1e6..5daf923ce105 100644 --- a/vcl/osx/vclnsapp.mm +++ b/vcl/osx/vclnsapp.mm @@ -96,6 +96,17 @@ NSWindow* pKeyWin = [NSApp keyWindow]; if( pKeyWin && [pKeyWin isKindOfClass: [SalFrameWindow class]] ) { + // Commit uncommitted text before dispatching key shortcuts. In + // certain cases such as pressing Command-Option-C in a Writer + // document while there is uncommitted text will call + // AquaSalFrame::EndExtTextInput() which will dispatch a + // SalEvent::EndExtTextInput event. Writer's handler for that event + // will delete the uncommitted text and then insert the committed + // text but LibreOffice will crash when deleting the uncommitted + // text because deletion of the text also removes and deletes the + // newly inserted comment. + [static_cast<SalFrameWindow*>(pKeyWin) endExtTextInput]; + AquaSalFrame* pFrame = [static_cast<SalFrameWindow*>(pKeyWin) getSalFrame]; unsigned int nModMask = ([pEvent modifierFlags] & (NSEventModifierFlagShift|NSEventModifierFlagControl|NSEventModifierFlagOption|NSEventModifierFlagCommand)); /* |