Make WordPress Core

Opened 7 years ago

Last modified 5 weeks ago

#48536 accepted enhancement

Allow cmd/ctrl-enter to submit comment forms in wp-admin

Reported by: davidbinda's profile david.binda Owned by: davidbaumwald's profile davidbaumwald
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch 2nd-opinion has-unit-tests
Focuses: javascript, administration Cc:

Description

This is a follow-up on #41545 which says:

I think it'd be a nice enhancement for comment forms in both the admin and front end to submit this way.

However, the r45790 introducing the feature does so only for frontend. Submitting comment by pressing ctrl/cmd + 'enter' does not seem to be working in wp-admin.

It would be cool if the new feature could be added to wp-admin as well.

Attachments (3)

48536.diff (636 bytes) - added by davidbaumwald 6 years ago.
Updated with keypress
48536.2.diff (637 bytes) - added by davidbaumwald 6 years ago.
Refreshed patch
48536.3.diff (848 bytes) - added by davidbaumwald 6 years ago.

Download all attachments as: .zip

Change History (14)

#1 @SergeyBiryukov
7 years ago

  • Focuses administration added

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.


6 years ago

#3 @ehtis
6 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.4

Thanks for the report @davidbinda!

That indeed appears to be an issue - for now setting it for 5.4.

#4 @davidbaumwald
6 years ago

  • Owner set to davidbaumwald
  • Status changed from new to accepted

#5 @davidbaumwald
6 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

@davidbaumwald
6 years ago

Updated with keypress

@davidbaumwald
6 years ago

Refreshed patch

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


6 years ago

#7 @davidbaumwald
6 years ago

After some help from @garrett-eclipse, I'm updating the patch for WPCS and dropping the '10' keyCode.

#8 @davidbaumwald
6 years ago

  • Keywords 2nd-opinion added

Revisiting the 10 keyCode I had in the original patch, this was to accommodate Chrome's quirk for the keypress event. See https://bugs.chromium.org/p/chromium/issues/detail?id=79407. I'm thinking the final patch should include this, and we should also re-open #41545 or create a new ticket. Marking for 2nd-opinion.

#9 @davidbaumwald
6 years ago

  • Milestone changed from 5.4 to Future Release

This ticket still needs a final direction, patch, and testing. With 5.4 Beta 1 landing tomorrow, this is being moved to Future Release. If any maintainer or committer feels this can be included in 5.4 or wishes to assume ownership during a specific cycle, feel free to update the milestone accordingly.

#10 @huzaifaalmesbah
3 months ago

  • Keywords needs-refresh added; needs-testing removed

I attempted to apply the latest patch (48536.3.diff) against trunk (7.0-alpha-61215-src), but it does not apply cleanly.

The following file failed to patch:

  • src/js/_enqueues/admin/edit-comments.js

A .rej file was generated, which indicates the patch is outdated and no longer matches current core.

Because the patch cannot be applied, testing is not possible at this time. Removing needs-testing and adding needs-refresh so the patch can be updated for trunk.

This ticket was mentioned in PR #11486 on WordPress/wordpress-develop by @vidugupta.


5 weeks ago
#11

  • Keywords has-unit-tests added; needs-refresh removed

Problem

The WordPress admin comment reply/edit forms did not support the Ctrl+Enter / Cmd+Enter keyboard shortcut for submitting comments. While this convenient shortcut was available for frontend comment forms (added in ticket #41545), wp-admin users had to reach for the mouse to click the Submit button, creating an inconsistent experience across frontend and backend.

Root Cause

The root cause was that the comment reply/edit form handler in edit-comments.js lacked the necessary keyboard vent logic to detect and handle the Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac) key combination. While the file contained handlers for other keyboard interactions (Escape to cancel, Enter on text inputs), there was no support for the modifier+Enter pattern used to submit the textarea content.

Solution

Added keyboard event detection to the existing contextmenu keydown handler on the #replycontent textarea inside commentReply.open() in src/js/_enqueues/admin/edit-comments.js:

  // Submit the comment when Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac) is pressed.
  if ( e.type === 'keydown' && ( e.ctrlKey || e.metaKey ) && e.which === 13 && ! isComposing ) {
      e.preventDefault();
      commentReply.send();
  }

This addition:

  • Detects Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac) on the comment textarea
  • Respects IME (Input Method Editor) composition state to prevent accidental submissions during CJK input
  • Calls the existing commentReply.send() method to submit via AJAX
  • Prevents the default browser behavior to avoid inserting a newline

Example Usage

After this change, users can submit admin comment replies and edits using the keyboard shortcut:

  1. Click "Reply" or "Quick Edit" on a comment
  2. Type the comment text in the textarea
  3. Press Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac)
  4. Form submits immediately without requiring mouse interaction

Impact

This enhancement improves the WordPress admin user experience by providing keyboard-savvy users with a faster workflow for managing comments. The implementation maintains consistency with the frontend comment form behavior while following WordPress JavaScript coding standards and accessibility best practices (IME-aware composition detection).

Trac Link

https://core.trac.wordpress.org/ticket/48536

Note: See TracTickets for help on using tickets.