summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.md2
-rw-r--r--source/features/avoid-accidental-submissions.tsx46
-rw-r--r--source/github-helpers/index.ts1
3 files changed, 35 insertions, 14 deletions
diff --git a/readme.md b/readme.md
index b4c26647..8109796e 100644
--- a/readme.md
+++ b/readme.md
@@ -200,7 +200,7 @@ Thanks for contributing! 🦋🙌
- [](# "unfinished-comments") [Notifies the user of unfinished comments in hidden tabs.](https://user-images.githubusercontent.com/1402241/97792086-423d5d80-1b9f-11eb-9a3a-daf716d10b0e.gif)
- [](# "wait-for-attachments") [Wait for the attachments to finish uploading before allowing to post a comment.](https://user-images.githubusercontent.com/46634000/104294547-9b8b0c80-54bf-11eb-93e5-65ae158353b3.gif)
- [](# "delete-review-comments-faster") [Adds a button to delete review comments in one click when editing them.](https://user-images.githubusercontent.com/46634000/115445792-9fdd6900-a216-11eb-9ba3-6dab4d2f9d32.png)
-- [](# "avoid-accidental-submissions") [Disables the <kbd>enter</kbd>-to-submit shortcut in some commit/PR/issue title fields to avoid accidental submissions. Use <kbd>ctrl</kbd><kbd>enter</kbd> instead.](https://user-images.githubusercontent.com/723651/115148453-5818df00-a068-11eb-92d4-51ac6e937b8b.gif)
+- [](# "avoid-accidental-submissions") [Disables the <kbd>enter</kbd>-to-submit shortcut in some commit/PR/issue title fields to avoid accidental submissions. Use <kbd>ctrl</kbd><kbd>enter</kbd> instead.](https://user-images.githubusercontent.com/723651/125863341-6cf0bce0-f120-4cec-ac1f-1ce35920e7a7.gif)
- [](# "comment-on-draft-pr-indicator") [Reminds you you’re commenting on a draft PR by changing the submit button’s label.](https://user-images.githubusercontent.com/723651/123682081-39e31280-d853-11eb-9c86-97be400aca67.jpg)
<!-- Refer to style guide above. Keep this message between sections. -->
diff --git a/source/features/avoid-accidental-submissions.tsx b/source/features/avoid-accidental-submissions.tsx
index 5390046a..80893a6e 100644
--- a/source/features/avoid-accidental-submissions.tsx
+++ b/source/features/avoid-accidental-submissions.tsx
@@ -1,7 +1,9 @@
+import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
+import {isMac} from '../github-helpers';
import features from '.';
function addQuickSubmit(): void {
@@ -9,32 +11,50 @@ function addQuickSubmit(): void {
}
function onKeyDown(event: delegate.Event<KeyboardEvent, HTMLInputElement>): void {
+ const field = event.delegateTarget;
+ const form = field.form!;
if (
event.key !== 'Enter'
|| event.ctrlKey
|| event.metaKey
|| event.isComposing // #4323
- || select.exists('.suggester', event.delegateTarget.form!) // GitHub’s autocomplete dropdown
+ || select.exists([
+ '.suggester', // GitHub’s autocomplete dropdown
+ '.rgh-avoid-accidental-submissions',
+ ], form)
) {
return;
}
+ if (select.exists('.btn-primary[type="submit"]:disabled', form)) {
+ return;
+ }
+
+ const spacingClasses = pageDetect.isNewFile() || pageDetect.isEditingFile() ? 'my-1' : 'mt-2 mb-n1';
+
+ const message = (
+ <p className={'rgh-avoid-accidental-submissions ' + spacingClasses}>
+ A submission via <kbd>enter</kbd> has been prevented. You can press <kbd>enter</kbd> again or use <kbd>{isMac ? 'cmd' : 'ctrl'}</kbd><kbd>enter</kbd>.
+ </p>
+ );
+ if (pageDetect.isNewFile() || pageDetect.isEditingFile() || pageDetect.isPRConversation()) {
+ field.after(message);
+ } else {
+ field.parentElement!.append(message);
+ }
+
event.preventDefault();
- select([
- '#issue_body',
- '#pull_request_body',
- '#commit-description-textarea',
- '#merge_message_field',
- ], event.delegateTarget.form!)!.focus();
}
+const inputElements = [
+ 'form.new_issue input#issue_title',
+ 'input#pull_request_title',
+ 'input#commit-summary-input',
+ '#merge_title_field',
+];
+
function init(): void {
- delegate(document, [
- 'form.new_issue input#issue_title',
- 'input#pull_request_title',
- 'input#commit-summary-input',
- '#merge_title_field',
- ].join(','), 'keydown', onKeyDown);
+ delegate(document, inputElements.join(','), 'keydown', onKeyDown);
}
void features.add(__filebasename, {
diff --git a/source/github-helpers/index.ts b/source/github-helpers/index.ts
index e6f852ae..6f24a6b1 100644
--- a/source/github-helpers/index.ts
+++ b/source/github-helpers/index.ts
@@ -38,6 +38,7 @@ export const getCurrentCommittish = (pathname = location.pathname, title = docum
};
export const isFirefox = navigator.userAgent.includes('Firefox/');
+export const isMac = navigator.userAgent.includes('Macintosh');
// The type requires at least one parameter https://stackoverflow.com/a/49910890
export const buildRepoURL = (...pathParts: Array<string | number> & {0: string}): string => {