| ... | ... | @@ -55,11 +55,24 @@ export function PullRequestMarkdownEditor({ |
| 55 | 55 | setDraft(value); |
| 56 | 56 | } |
| 57 | 57 | const empty = draft.trim().length === 0; |
| 58 | const saveDisabled = saving || (empty && !allowEmpty); |
| 58 | 59 | |
| 59 | 60 | return ( |
| 60 | 61 | <div |
| 61 | 62 | className={cn("space-y-2", className)} |
| 62 | 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 | 76 | if (event.key !== "Escape" || saving) return; |
| 64 | 77 | event.preventDefault(); |
| 65 | 78 | onCancel(); |
| ... | ... | @@ -106,12 +119,7 @@ export function PullRequestMarkdownEditor({ |
| 106 | 119 | <Button size="xs" variant="ghost" disabled={saving} onClick={onCancel}> |
| 107 | 120 | Cancel |
| 108 | 121 | </Button> |
| 109 | | <Button |
| 110 | | size="xs" |
| 111 | | variant="outline" |
| 112 | | disabled={saving || (empty && !allowEmpty)} |
| 113 | | onClick={() => onSave(draft)} |
| 114 | | > |
| 122 | <Button size="xs" variant="outline" disabled={saveDisabled} onClick={() => onSave(draft)}> |
| 115 | 123 | {saving ? "Saving..." : "Save"} |
| 116 | 124 | </Button> |
| 117 | 125 | </div> |