| ... | @@ -55,11 +55,24 @@ export function PullRequestMarkdownEditor({ | ... | @@ -55,11 +55,24 @@ export function PullRequestMarkdownEditor({ |
| 55 | setDraft(value); | 55 | setDraft(value); |
| 56 | } | 56 | } |
| 57 | const empty = draft.trim().length === 0; | 57 | const empty = draft.trim().length === 0; |
| | 58 | const saveDisabled = saving || (empty && !allowEmpty); |
| 58 | | 59 | |
| 59 | return ( | 60 | return ( |
| 60 | <div | 61 | <div |
| 61 | className={cn("space-y-2", className)} | 62 | className={cn("space-y-2", className)} |
| 62 | onKeyDown={(event) => { | 63 | onKeyDown={(event) => { |
| | 64 | if (event.nativeEvent.isComposing || event.keyCode === 229) return; |
| | 65 | if ( |
| | 66 | event.key === "Enter" && |
| | 67 | (event.metaKey || event.ctrlKey) && |
| | 68 | !event.shiftKey && |
| | 69 | !event.altKey |
| | 70 | ) { |
| | 71 | event.preventDefault(); |
| | 72 | event.stopPropagation(); |
| | 73 | if (!saveDisabled && !event.repeat) onSave(draft); |
| | 74 | return; |
| | 75 | } |
| 63 | if (event.key !== "Escape" || saving) return; | 76 | if (event.key !== "Escape" || saving) return; |
| 64 | event.preventDefault(); | 77 | event.preventDefault(); |
| 65 | onCancel(); | 78 | onCancel(); |
| ... | @@ -106,12 +119,7 @@ export function PullRequestMarkdownEditor({ | ... | @@ -106,12 +119,7 @@ export function PullRequestMarkdownEditor({ |
| 106 | <Button size="xs" variant="ghost" disabled={saving} onClick={onCancel}> | 119 | <Button size="xs" variant="ghost" disabled={saving} onClick={onCancel}> |
| 107 | Cancel | 120 | Cancel |
| 108 | </Button> | 121 | </Button> |
| 109 | <Button | 122 | <Button size="xs" variant="outline" disabled={saveDisabled} onClick={() => onSave(draft)}> |
| 110 | size="xs" | | |
| 111 | variant="outline" | | |
| 112 | disabled={saving || (empty && !allowEmpty)} | | |
| 113 | onClick={() => onSave(draft)} | | |
| 114 | > | | |
| 115 | {saving ? "Saving..." : "Save"} | 123 | {saving ? "Saving..." : "Save"} |
| 116 | </Button> | 124 | </Button> |
| 117 | </div> | 125 | </div> |