mirror of
https://github.com/wekan/wekan.git
synced 2026-11-07 11:02:33 -05:00
Honor Submit editors with Enter across textarea editors, retain composition and mention handling, and route shortcuts through existing scoped save actions. Preserve manual resize dimensions after typing and retain single-line structured fields. Keep the typography reset from overriding themed button foregrounds, including Board Settings column actions. Verify blue, green, dark and Clean Light buttons and chart actions. Thanks to xet7.
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
// #4236 "The processing strategy for the enter key is different". The card
|
|
// TITLE textarea submitted on PLAIN Enter (only Shift+Enter made a newline),
|
|
// while the card DESCRIPTION textarea — and the shared inlinedForm — insert a
|
|
// newline on plain Enter and only submit on Ctrl/Cmd+Enter. That inconsistency
|
|
// meant Enter could not add a new line in the title.
|
|
//
|
|
// isSubmitKey centralizes the "does this keydown submit the editor?" rule so
|
|
// every multi-line editor field behaves the same.
|
|
//
|
|
// Default (submitOnEnter off): submit ONLY on Enter together with Ctrl or Cmd;
|
|
// plain Enter and Shift+Enter fall through to the textarea default (a newline).
|
|
//
|
|
// Opt-in per-user setting (submitOnEnter on, Member Settings): plain Enter
|
|
// submits and Shift+Enter inserts a newline — restoring the pre-#4236 fast
|
|
// title-editing workflow for users who prefer it, without affecting anyone else.
|
|
//
|
|
// Meteor-free and unit tested. The caller passes the current user's preference
|
|
// as opts.submitOnEnter so this stays a pure function.
|
|
function isSubmitKey(event, opts = {}) {
|
|
// Enter used to finish an IME composition or select a mention is not Save.
|
|
if (!event || event.defaultPrevented || event.isComposing ||
|
|
event.originalEvent?.isComposing || event.keyCode === 229 ||
|
|
event.isDefaultPrevented?.()) return false;
|
|
const isEnter = event.keyCode === 13 || event.key === 'Enter';
|
|
if (!isEnter) return false;
|
|
if (opts.submitOnEnter) {
|
|
// plain Enter submits; Shift+Enter is a newline (Ctrl/Cmd+Enter also submits)
|
|
return !event.shiftKey;
|
|
}
|
|
return !!(event.ctrlKey || event.metaKey);
|
|
}
|
|
|
|
export { isSubmitKey };
|