From 2a48b7f07227a9c6b6455538fbc4cb17e3a107fd Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Sat, 17 Feb 2024 20:28:36 +0100 Subject: [PATCH] feat: the commit message will no longer be lost during navigation --- .../src/lib/components/CommitDialog.svelte | 17 +++++++++++++++-- gitbutler-ui/src/lib/config/config.ts | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gitbutler-ui/src/lib/components/CommitDialog.svelte b/gitbutler-ui/src/lib/components/CommitDialog.svelte index d60af6a0c..6aebf0d5a 100644 --- a/gitbutler-ui/src/lib/components/CommitDialog.svelte +++ b/gitbutler-ui/src/lib/components/CommitDialog.svelte @@ -9,7 +9,9 @@ projectAiGenEnabled, projectCommitGenerationExtraConcise, projectCommitGenerationUseEmojis, - projectRunCommitHooks + projectRunCommitHooks, + projectCurrentCommitMessage, + projectLastCommitMessage } from '$lib/config/config'; import { persisted } from '$lib/persisted/persisted'; import * as toasts from '$lib/utils/toasts'; @@ -18,6 +20,7 @@ import { invoke } from '@tauri-apps/api/tauri'; import { createEventDispatcher } from 'svelte'; import { quintOut } from 'svelte/easing'; + import { get } from 'svelte/store'; import { slide } from 'svelte/transition'; import type { User, getCloudApiClient } from '$lib/backend/cloud'; import type { BranchController } from '$lib/vbranches/branchController'; @@ -38,11 +41,17 @@ const aiGenEnabled = projectAiGenEnabled(projectId); const runCommitHooks = projectRunCommitHooks(projectId); + const currentCommitMessage = projectCurrentCommitMessage(projectId); + const lastCommitMessage = projectLastCommitMessage(projectId); export const expanded = persisted(false, 'commitBoxExpanded_' + branch.id); - let commitMessage: string; + let commitMessage: string = get(currentCommitMessage) || ''; let isCommitting = false; let textareaElement: HTMLTextAreaElement; + $: if (textareaElement && commitMessage && expanded) { + textareaElement.style.height = 'auto'; + textareaElement.style.height = `${textareaElement.scrollHeight + 2}px`; + } const focusTextareaOnMount = (el: HTMLTextAreaElement) => { if (el) { @@ -55,7 +64,9 @@ branchController .commitBranch(branch.id, commitMessage, $selectedOwnership.toString(), $runCommitHooks) .then(() => { + lastCommitMessage.set(commitMessage); commitMessage = ''; + currentCommitMessage.set(''); }) .finally(() => (isCommitting = false)); } @@ -96,6 +107,7 @@ const summary = firstNewLine > -1 ? message.slice(0, firstNewLine).trim() : message; const description = firstNewLine > -1 ? message.slice(firstNewLine + 1).trim() : ''; commitMessage = description.length > 0 ? `${summary}\n\n${description}` : summary; + currentCommitMessage.set(commitMessage); setTimeout(() => { textareaElement.focus(); @@ -124,6 +136,7 @@ use:focusTextareaOnMount on:input={useAutoHeight} on:focus={useAutoHeight} + on:change={() => currentCommitMessage.set(commitMessage)} spellcheck={false} class="commit-box__textarea text-base-body-13" rows="1" diff --git a/gitbutler-ui/src/lib/config/config.ts b/gitbutler-ui/src/lib/config/config.ts index cd9d3f821..d39c0cf23 100644 --- a/gitbutler-ui/src/lib/config/config.ts +++ b/gitbutler-ui/src/lib/config/config.ts @@ -50,3 +50,13 @@ export function projectLaneCollapsed(projectId: string, laneId: string): Persist const key = 'projectLaneCollapsed_'; return persisted(false, key + projectId + '_' + laneId); } + +export function projectCurrentCommitMessage(projectId: string): Persisted { + const key = 'projectCurrentCommitMessage_'; + return persisted('', key + projectId); +} + +export function projectLastCommitMessage(projectId: string): Persisted { + const key = 'projectLastCommitMessage_'; + return persisted('', key + projectId); +}