Skip to content

Commit

Permalink
Confirm before closing dirty create pull request dialog with escape
Browse files Browse the repository at this point in the history
  • Loading branch information
simenbrekken committed Nov 1, 2024
1 parent e7e8ffd commit 86a7f85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion apps/desktop/src/lib/pr/PrDetailsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { openExternalUrl } from '$lib/utils/url';
import { BranchController } from '$lib/vbranches/branchController';
import { PatchSeries, VirtualBranch } from '$lib/vbranches/types';
import { confirm } from '@tauri-apps/plugin-dialog';
import { getContext, getContextStore } from '@gitbutler/shared/context';
import Button from '@gitbutler/ui/Button.svelte';
import Modal from '@gitbutler/ui/Modal.svelte';
Expand Down Expand Up @@ -139,6 +140,12 @@
let inputTitle = $state<string | undefined>(undefined);
const actualBody = $derived<string>(inputBody ?? defaultBody);
const actualTitle = $derived<string>(inputTitle ?? defaultTitle);
const isDirty = $derived(
inputTitle !== undefined ||
inputBody !== undefined ||
inputTitle !== defaultTitle ||
inputBody !== defaultBody
);
$effect(() => {
if (modal?.imports.open) {
Expand Down Expand Up @@ -260,7 +267,7 @@
await tick();
}
function handleModalKeydown(e: KeyboardEvent) {
async function handleModalKeydown(e: KeyboardEvent) {
switch (e.key) {
case 'g':
if ((e.metaKey || e.ctrlKey) && e.shiftKey) {
Expand All @@ -269,6 +276,25 @@
handleAIButtonPressed();
}
break;
case KeyName.Escape:
e.stopPropagation();
if (isDirty) {
const discardPullRequest = await confirm(
'Are you sure you want to discard this pull request?',
{
title: 'Discard pull request?',
kind: 'warning'
}
);
if (!discardPullRequest) {
return;
}
}
modal?.close();
break;
case KeyName.Enter:
if (isLoading || aiIsLoading) break;
if (e.metaKey || e.ctrlKey) {
Expand Down
1 change: 1 addition & 0 deletions crates/gitbutler-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"core:default",
"core:window:allow-start-dragging",
"core:window:default",
"dialog:allow-confirm",
"dialog:allow-open",
"fs:allow-read-file",
"fs:allow-cache-read-recursive",
Expand Down

0 comments on commit 86a7f85

Please sign in to comment.