From bb6b0d5477368a97ba5cc1c01bdb598dcbe68cd2 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 18 Jul 2026 18:14:33 +0300 Subject: [PATCH] Member Settings: optional "Submit editors with Enter" (per-user, off by default). #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. --- client/components/cards/cardDetails.js | 16 +++++++++------ client/components/users/userHeader.jade | 6 ++++++ client/components/users/userHeader.js | 10 +++++++++ client/lib/inlinedform.js | 7 ++++++- imports/i18n/data/en.i18n.json | 2 ++ imports/i18n/data/fi.i18n.json | 2 ++ models/lib/editorSubmitKey.js | 20 ++++++++++++++---- models/users.js | 14 +++++++++++++ server/models/users.js | 10 +++++++++ tests/editorSubmitKey.test.cjs | 27 +++++++++++++++++++++++++ 10 files changed, 103 insertions(+), 11 deletions(-) diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index fc905ad565..9494d6f24e 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -1418,7 +1418,10 @@ Template.inlinedCardDescription.events({ tpl.isOpen.set(true); }, 'keydown form textarea'(evt, tpl) { - if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) { + // Ctrl/Cmd+Enter submits by default; plain Enter when the user enabled + // "submit on Enter" in Member Settings (Shift+Enter then makes a newline). + const submitOnEnter = !!ReactiveCache.getCurrentUser()?.hasSubmitOnEnter?.(); + if (isSubmitKey(evt, { submitOnEnter })) { tpl.find('button[type=submit]').click(); } }, @@ -1529,11 +1532,12 @@ Template.editCardTitleForm.events({ Utils.showCopied(promise, $tooltip); }, 'keydown .js-edit-card-title'(event) { - // #4236: match the card description field — Ctrl/Cmd+Enter saves; plain - // Enter (and Shift+Enter) insert a new line instead of submitting. The old - // handler submitted on any Enter without Shift, so Enter could not add a - // newline in the title. - if (isSubmitKey(event)) { + // #4236: by default Ctrl/Cmd+Enter saves; plain Enter (and Shift+Enter) + // insert a new line. A user who turns on "submit on Enter" in Member + // Settings gets plain Enter to save (Shift+Enter for a newline) instead — + // the pre-#4236 fast title-editing workflow (#6480 email feedback). + const submitOnEnter = !!ReactiveCache.getCurrentUser()?.hasSubmitOnEnter?.(); + if (isSubmitKey(event, { submitOnEnter })) { $('.js-submit-edit-card-title-form').click(); } }, diff --git a/client/components/users/userHeader.jade b/client/components/users/userHeader.jade index 3b8bcc9013..167cbdadd2 100644 --- a/client/components/users/userHeader.jade +++ b/client/components/users/userHeader.jade @@ -231,6 +231,12 @@ template(name="changeSettingsPopup") | {{_ 'show-desktop-drag-handles'}} if isShowDesktopDragHandles i.fa.fa-check + li + a.js-toggle-submit-on-enter(title="{{_ 'submit-on-enter-description'}}") + i.fa.fa-level-down + | {{_ 'submit-on-enter'}} + if isSubmitOnEnter + i.fa.fa-check unless currentUser.isWorker li label.bold.clear diff --git a/client/components/users/userHeader.js b/client/components/users/userHeader.js index 2ca67cad34..940636cdbb 100644 --- a/client/components/users/userHeader.js +++ b/client/components/users/userHeader.js @@ -322,6 +322,10 @@ Template.changeLanguagePopup.events({ }); Template.changeSettingsPopup.helpers({ + isSubmitOnEnter() { + const currentUser = ReactiveCache.getCurrentUser(); + return currentUser ? currentUser.hasSubmitOnEnter() : false; + }, rescueCardDescription() { const currentUser = ReactiveCache.getCurrentUser(); if (currentUser) { @@ -381,6 +385,12 @@ Template.changeSettingsPopup.events({ window.localStorage.setItem('showDesktopDragHandles', 'true'); } }, + 'click .js-toggle-submit-on-enter'() { + // Saved to the user profile (Member Settings only; requires a logged-in user). + if (ReactiveCache.getCurrentUser()) { + Meteor.call('toggleSubmitOnEnter'); + } + }, 'click .js-rescue-card-description'() { Meteor.call('toggleRescueCardDescription') }, diff --git a/client/lib/inlinedform.js b/client/lib/inlinedform.js index 59078555e3..cbc2bf8d85 100644 --- a/client/lib/inlinedform.js +++ b/client/lib/inlinedform.js @@ -16,6 +16,8 @@ import { Template } from 'meteor/templating'; import { ReactiveVar } from 'meteor/reactive-var'; import { Tracker } from 'meteor/tracker'; import { EscapeActions } from '/client/lib/escapeActions'; +import { ReactiveCache } from '/imports/reactiveCache'; +import { isSubmitKey } from '/models/lib/editorSubmitKey'; import { openForm, closeForm, @@ -77,7 +79,10 @@ Template.inlinedForm.events({ openForm(currentlyOpenedForm, tpl); }, 'keydown form textarea'(evt, tpl) { - if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) { + // Ctrl/Cmd+Enter submits by default; a user who enabled "submit on Enter" + // in Member Settings submits on plain Enter (Shift+Enter for a newline). + const submitOnEnter = !!ReactiveCache.getCurrentUser()?.hasSubmitOnEnter?.(); + if (isSubmitKey(evt, { submitOnEnter })) { tpl.find('button[type=submit]').click(); } }, diff --git a/imports/i18n/data/en.i18n.json b/imports/i18n/data/en.i18n.json index 35adeeeb5b..9640b8238a 100644 --- a/imports/i18n/data/en.i18n.json +++ b/imports/i18n/data/en.i18n.json @@ -1290,6 +1290,8 @@ "accounts-allowUserDelete": "Allow users to self delete their account", "hide-minicard-label-text": "Hide minicard label text", "show-desktop-drag-handles": "Show desktop drag handles", + "submit-on-enter": "Submit editors with Enter", + "submit-on-enter-description": "When on, pressing Enter saves the card title, description and other inline editors; Shift+Enter inserts a new line. When off, Ctrl/Cmd+Enter saves and Enter inserts a new line.", "assignee": "Assignee", "assignees": "Assignees", "cardAssigneesPopup-title": "Assignee", diff --git a/imports/i18n/data/fi.i18n.json b/imports/i18n/data/fi.i18n.json index 8955b73d55..fa6bd17608 100644 --- a/imports/i18n/data/fi.i18n.json +++ b/imports/i18n/data/fi.i18n.json @@ -1290,6 +1290,8 @@ "accounts-allowUserDelete": "Salli käyttäjien poistaa tilinsä itse", "hide-minicard-label-text": "Piilota minikortin nimilappu teksti", "show-desktop-drag-handles": "Näytä työpöydän vedon kahvat", + "submit-on-enter": "Lähetä editorit Enterillä", + "submit-on-enter-description": "Kun päällä, Enter tallentaa kortin otsikon, kuvauksen ja muut sisäiset editorit; Vaihto+Enter lisää rivinvaihdon. Kun pois, Ctrl/Cmd+Enter tallentaa ja Enter lisää rivinvaihdon.", "assignee": "Käsittelijä", "assignees": "Käsittelijät", "cardAssigneesPopup-title": "Käsittelijä", diff --git a/models/lib/editorSubmitKey.js b/models/lib/editorSubmitKey.js index 4eb4b873db..ff0cd368ba 100644 --- a/models/lib/editorSubmitKey.js +++ b/models/lib/editorSubmitKey.js @@ -7,13 +7,25 @@ // 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: submit ONLY on Enter together -// with Ctrl or Cmd; plain Enter and Shift+Enter fall through to the textarea -// default (a newline). Meteor-free and unit tested. -function isSubmitKey(event) { +// 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); } diff --git a/models/users.js b/models/users.js index d4ff6328cc..e457943d3e 100644 --- a/models/users.js +++ b/models/users.js @@ -272,6 +272,15 @@ Users.attachSchema( type: Boolean, optional: true, }, + 'profile.submitOnEnter': { + /** + * per-user preference: in multi-line editors (card title/description and + * other inlined forms) submit on plain Enter (Shift+Enter for a newline) + * instead of the default Ctrl/Cmd+Enter. Off by default. See #4236/#6480. + */ + type: Boolean, + optional: true, + }, 'profile.GreyIcons': { /** * per-user preference to render unicode icons in grey @@ -1409,6 +1418,11 @@ Users.helpers({ return profile.showDesktopDragHandles || false; }, + hasSubmitOnEnter() { + const profile = this.profile || {}; + return profile.submitOnEnter || false; + }, + hasGreyIcons() { const profile = this.profile || {}; return profile.GreyIcons || false; diff --git a/server/models/users.js b/server/models/users.js index 4895809190..1299e16519 100644 --- a/server/models/users.js +++ b/server/models/users.js @@ -494,6 +494,16 @@ Meteor.methods({ user.toggleDesktopHandles(user.hasShowDesktopDragHandles()); }, + // Per-user "submit editors on plain Enter" preference (Member Settings). + // Off by default; when on, plain Enter submits and Shift+Enter is a newline. + async toggleSubmitOnEnter() { + if (!this.userId) throw new Meteor.Error('not-logged-in', 'User must be logged in'); + const user = await Users.findOneAsync(this.userId); + if (!user) throw new Meteor.Error('user-not-found', 'User not found'); + const current = !!((user.profile || {}).submitOnEnter); + await Users.updateAsync(this.userId, { $set: { 'profile.submitOnEnter': !current } }); + }, + async createWorkspace(params) { check(params, Object); const { parentId = null, name } = params; diff --git a/tests/editorSubmitKey.test.cjs b/tests/editorSubmitKey.test.cjs index 84cc52985c..fa832a8aef 100644 --- a/tests/editorSubmitKey.test.cjs +++ b/tests/editorSubmitKey.test.cjs @@ -56,4 +56,31 @@ test('NEGATIVE: null / undefined event does not throw and does not submit', () = assert.strictEqual(isSubmitKey(undefined), false); }); +// --- Per-user opt-in setting (Member Settings): submitOnEnter ----------------- +// When the user turns on "submit on Enter", plain Enter submits and Shift+Enter +// makes a newline. Default (off) keeps the #4236 Ctrl/Cmd+Enter behaviour above. +test('submitOnEnter: plain Enter submits', () => { + assert.strictEqual(isSubmitKey({ keyCode: 13 }, { submitOnEnter: true }), true); + assert.strictEqual(isSubmitKey({ key: 'Enter' }, { submitOnEnter: true }), true); +}); + +test('submitOnEnter: Ctrl/Cmd+Enter still submits', () => { + assert.strictEqual(isSubmitKey({ keyCode: 13, ctrlKey: true }, { submitOnEnter: true }), true); + assert.strictEqual(isSubmitKey({ keyCode: 13, metaKey: true }, { submitOnEnter: true }), true); +}); + +test('submitOnEnter NEGATIVE: Shift+Enter does NOT submit (it is a newline)', () => { + assert.strictEqual(isSubmitKey({ keyCode: 13, shiftKey: true }, { submitOnEnter: true }), false); +}); + +test('submitOnEnter NEGATIVE: a non-Enter key never submits', () => { + assert.strictEqual(isSubmitKey({ keyCode: 65 }, { submitOnEnter: true }), false); +}); + +test('submitOnEnter defaults off: explicit false and omitted both require Ctrl/Cmd', () => { + assert.strictEqual(isSubmitKey({ keyCode: 13 }, { submitOnEnter: false }), false); + assert.strictEqual(isSubmitKey({ keyCode: 13 }, {}), false); + assert.strictEqual(isSubmitKey({ keyCode: 13 }), false); +}); + console.log(`\n${passed} tests passed`);