Assign macOS text navigation key bindings - #1125
Merged
dail8859 merged 1 commit intoSep 12, 2026
Merged
Conversation
Scintilla's macOS key bindings are gated on PLAT_GTK_MACOSX, which is never defined for the Qt platform layer because Platform.h takes the SCINTILLA_QT branch, so those bindings are never applied. Scintilla also routes word-wise movement through SCI_META, but the Qt layer's ModifierFlags() only reports shift, ctrl and alt, so that modifier is never delivered either. The result on macOS is that Command and arrow keys scroll the view or move by word rather than moving to the start/end of the line and of the document, and Option and arrow keys do nothing at all. Assign the standard macOS bindings from setupEditor() rather than patching the bundled Scintilla, so that updating Scintilla cannot silently revert them. Command + Shift + Up/Down are left alone since the Move Selected Lines Up/Down actions already use them and receive the key press before the editor does. Fixes dail8859#712
Owner
|
Appreciate your explanation as at the time when I took a shot at it, I wasn't exactly sure what the root problem was. Ultimately, it sounds like Scintilla is not quite configured right when compiling for Qt on Mac. This approach is clean and straightforward so I do not see a problem with it. Ideally in the future it is likely that all shortcut keys will be handled through actions and not let Scintilla do any of the shortcut handling, that way the app can rely on Qt's Standard Key and allow for more customizations. But for now I think this is the best approach. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause
Scintilla's macOS key bindings live behind
OS_X_KEYSinKeyMap.cxx, which is gated onPLAT_GTK_MACOSX.Platform.htakes the#elif defined(SCINTILLA_QT)branch, soPLAT_GTK_MACOSXis always0and those bindings never apply.Enabling that flag alone isn't sufficient, which is why the earlier attempt in this issue
didn't behave as expected: under
OS_X_KEYS, Scintilla routes word-wise movement throughSCI_CTRL_META=SCI_META, butScintillaEditBasecallsModifierFlags(shift, ctrl, alt)and never reports meta at all — so word movement would have become unreachable entirely.
The effect today on macOS is that Command + arrow keys scroll the view or move by word
instead of moving to the start/end of the line and document, and Option + arrow keys do
nothing at all.
Approach
The bindings are assigned from
EditorManager::setupEditor()underQ_OS_MACOSrather thanby patching the bundled Scintilla, so that updating Scintilla cannot silently revert them.
On macOS Qt reports Command as
Qt::ControlModifier(SCMOD_CTRL) and Option asQt::AltModifier(SCMOD_ALT).VCHome/LineEnd(+ Shift to extend)DocumentStart/DocumentEndWordLeft/WordRight(+ Shift to extend)DelWordLeftDelLineLeftRedoThese follow the macOS system conventions and VS Code's defaults. Since Option + Shift +
Left/Right now select by word, Cmd + Option + Shift + arrows are added for rectangular
selection (also matching VS Code); Option + Shift + Up/Down keep Scintilla's default
rectangular behaviour as nothing else uses them.
Three notes:
actionMoveSelectedLinesUp/Downalready use
Ctrl+Shift+Up/Downand QActions receive the key press before the editor does.Happy to relocate those on macOS instead if you'd prefer.
Ctrl+Y. Let me know if you'd rather the menu shortcut changed on macOS too.BetterMultiSelectionhandles these keys before theeditor's key bindings, so Cmd + Left/Right moves by word there rather than to the line
start/end. That path is unchanged by this PR and matches VS Code's behaviour for
multi-caret editing.
Testing
Built and tested by hand on macOS 26.6 with Qt 6.11.2. Every binding in the table above
behaves as expected, including the smart-home toggle on an indented line (first press moves
to the first non-whitespace character, second to column 1) and correct column alignment for
rectangular selections. Verified that Cmd + Shift + Up/Down still moves selected lines, and
all changes are inside
#ifdef Q_OS_MACOSso other platforms are unaffected.The failing
codespellcheck is pre-existing onmaster(see #1124) and unrelated to thischange.
Fixes #712