mirror of
https://github.com/wekan/wekan.git
synced 2026-11-07 02:52:33 -05:00
#4236 made every multi-line editor submit only on Ctrl/Cmd+Enter (plain Enter = newline) so titles could be multi-line, but that removed the fast Enter-to-save title workflow some users rely on (v10 email feedback). Add a per-user preference in the Member Settings (Change Settings) popup, saved to profile.submitOnEnter and OFF by default: when on, plain Enter submits the card title, description and other inlined forms, and Shift+Enter inserts a newline; when off, behaviour is unchanged (Ctrl/Cmd+Enter saves). The rule stays in the single pure isSubmitKey(event, {submitOnEnter}); the card title, the card-description override and the shared client/lib/inlinedform.js all route through it and read the preference from the current user. New toggle + helper + toggleSubmitOnEnter method + schema field, i18n (en, fi), and editorSubmitKey.test.cjs extended with positive + negative opt-in cases. Thanks to xet7 ! Related to #4236.
33 lines
1.4 KiB
JavaScript
33 lines
1.4 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 = {}) {
|
|
if (!event) 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);
|
|
}
|
|
|
|
module.exports = { isSubmitKey };
|