]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1009716 - Add (Cmd|Ctrl)+Enter shortcut for submitting from text areas.
authorKohei Yoshino <kohei.yoshino@gmail.com>
Mon, 15 Oct 2018 20:40:30 +0000 (16:40 -0400)
committerDylan William Hardison <dylan@hardison.net>
Mon, 15 Oct 2018 20:40:30 +0000 (16:40 -0400)
js/field.js

index db2f9ac397dda4037145c6e9397980afee224a06..ec802b2026557e4bdbe39518e0c759a5f7ae38b4 100644 (file)
@@ -974,3 +974,34 @@ function show_comment_edit() {
     YAHOO.util.Dom.addClass(comment_tab, 'active_comment_tab');
     comment_tab.setAttribute('aria-selected', 'true');
 }
+
+/**
+ * Comment form keyboard shortcuts
+ */
+
+window.addEventListener('DOMContentLoaded', () => {
+  const on_mac = navigator.platform === 'MacIntel';
+  const $comment = document.querySelector('#comment');
+  const $save_button = document.querySelector('.save-btn, #commit');
+
+  if (!$comment || !$save_button) {
+    return;
+  }
+
+  $comment.addEventListener('keydown', event => {
+    const { isComposing, key, altKey, ctrlKey, metaKey, shiftKey } = event;
+    const accelKey = on_mac ? metaKey && !ctrlKey : ctrlKey;
+    const has_value = /\S/.test($comment.value);
+
+    if (isComposing) {
+      return;
+    }
+
+    // Accel + Enter = Save
+    if (has_value && key === 'Enter' && accelKey && !altKey && !shiftKey) {
+      event.preventDefault();
+      // Click the Save button to trigger the `submit` event handler
+      $save_button.click();
+    }
+  });
+}, { once: true });