Fix Alt+Enter newline not registering on Mac: add Cmd+Enter fallback
macOS's Option key is a compose key (used to type accented/special
characters), which can make it unreliable as a plain modifier in some
browser/layout combinations -- Alt+Enter alone wasn't reaching the handler
for this user on Mac. Microsoft's own Mac Excel shortcut for this is
inconsistent across versions too (Control+Option+Return traditionally,
plain Option+Return only in 365).
- onEditKeydown now accepts Enter with either altKey OR metaKey (Cmd),
giving a Mac-safe alternative that doesn't depend on Option's compose
behavior.
- Also checks e.code ('Enter'/'NumpadEnter') alongside e.key, in case
composition ever alters what .key reports for the combination (.code
reflects the physical key regardless).
Verified interactively: Alt+Enter, Cmd+Enter, and plain Enter (still
commits normally) all produce the expected value/behavior.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -650,10 +650,16 @@ function cancelEdit() {
|
||||
focusRoot();
|
||||
}
|
||||
function onEditKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter' && e.altKey) {
|
||||
// Alt+Enter (Windows/Excel-365-Mac) or Cmd+Enter (a macOS-safe fallback --
|
||||
// Option is a compose key there, e.g. for Control+Option+Return, the
|
||||
// traditional Mac Excel shortcut, or some layouts/browsers, so `altKey`
|
||||
// alone isn't fully reliable; `e.code` sidesteps `key` being altered by
|
||||
// that composition, since Enter itself never composes into another char).
|
||||
const isEnter = e.key === 'Enter' || e.code === 'Enter' || e.code === 'NumpadEnter';
|
||||
if (isEnter && (e.altKey || e.metaKey)) {
|
||||
// insert a literal newline at the caret ourselves rather than relying on
|
||||
// the textarea's native Enter handling, which some browsers/OSes divert
|
||||
// Alt+Enter away from (e.g. as a window/fullscreen shortcut)
|
||||
// this combination away from (e.g. as a window/fullscreen shortcut)
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const el = editInput.value;
|
||||
|
||||
Reference in New Issue
Block a user