fix(ui): erroneous list continuation on Cmd+Enter on macOS (#8153) (#8170)

The line continuation code in the Markdown editor ignored Enter presses if Ctrl, Alt or Shift were being held. This now also accounts for Cmd on macOS (which browsers represent as metaKey).

### Tests

- Use Safari (on macOS)
- create a new issue in a repository
- start writing a list (with - one[enter]- two)
- now press Cmd+Enter
- verify that while the form is being submitted, no new line got visually added

***

The visual evidence of this bug is a race condition (form is being edited while also being submitted) and I don't think a reliable cross-browser E2E test is possible.

Bugged and fixed behavior verified manually on an actual Macbook in current Safari. Specifically,

* Before the fix: pressing Cmd+Enter submits the form *and* inserts a newline + list prefix in the markdown editor.  Reporter had the changed content submitted, I only saw it submit the original (but the change was visible during submission).
* After the fix: Cmd+Enter only submits the form. Enter with no modifiers inserts newlines/prefixes as before.

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [x] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8170
Reviewed-by: Beowulf <beowulf@beocode.eu>
Co-authored-by: Danko Aleksejevs <danko@very.lv>
Co-committed-by: Danko Aleksejevs <danko@very.lv>
This commit is contained in:
Danko Aleksejevs 2025-06-23 15:21:15 +02:00 committed by Beowulf
parent debd74e1b6
commit 39e6785da0

View file

@ -121,12 +121,12 @@ class ComboMarkdownEditor {
// Prevent special keyboard handling if currently a text expander popup is open
if (this.textarea.hasAttribute('aria-expanded')) return;
const noModifiers = !e.shiftKey && !e.ctrlKey && !e.altKey;
const noModifiers = !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey;
if (e.key === 'Escape') {
// Explicitly lose focus and reenable tab navigation.
e.target.blur();
this.tabEnabled = false;
} else if (e.key === 'Tab' && this.tabEnabled && !e.altKey && !e.ctrlKey) {
} else if (e.key === 'Tab' && this.tabEnabled && !e.altKey && !e.ctrlKey && !e.metaKey) {
if (this.indentSelection(e.shiftKey, true)) {
this.options?.onContentChanged?.(this, e);
e.preventDefault();