Skip to content

Commit 4cd68a5

Browse files
committed
Show more compact preview of commit message
I just trialled and errored my way to a formula for how many characters we can fit in the container, taking current zoom level into account.
1 parent 313dbdf commit 4cd68a5

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

apps/desktop/src/components/CommitDetails.svelte

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<script lang="ts">
22
import { writeClipboard } from '$lib/backend/clipboard';
33
import { type Commit, type UpstreamCommit } from '$lib/branches/v3';
4+
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
45
import { UiState } from '$lib/state/uiState.svelte';
56
import { TestId } from '$lib/testing/testIds';
67
import { UserService } from '$lib/user/userService';
78
import { splitMessage } from '$lib/utils/commitMessage';
89
import { truncate } from '$lib/utils/string';
9-
import { inject } from '@gitbutler/shared/context';
10+
import { getContextStoreBySymbol, inject } from '@gitbutler/shared/context';
1011
import Icon from '@gitbutler/ui/Icon.svelte';
1112
import Tooltip from '@gitbutler/ui/Tooltip.svelte';
1213
import Avatar from '@gitbutler/ui/avatar/Avatar.svelte';
14+
import { pxToRem } from '@gitbutler/ui/utils/pxToRem';
1315
import { getTimeAgo } from '@gitbutler/ui/utils/timeAgo';
16+
import type { Writable } from 'svelte/store';
1417
1518
type Props = {
1619
commit: UpstreamCommit | Commit;
@@ -19,12 +22,22 @@
1922
const { commit }: Props = $props();
2023
2124
const [userService] = inject(UserService, UiState);
25+
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
26+
const zoom = $derived($userSettings.zoom);
2227
2328
const user = $derived(userService.user);
2429
30+
let messageWidth = $state(0);
31+
const messageWidthRem = $derived(pxToRem(messageWidth, zoom));
32+
33+
// Calculate approximately how many characters fit on one line, as a
34+
// function of container width as well as zoom level.
35+
// TODO: Turn this magic formula into something meaningful.
36+
const maxLength = $derived((messageWidthRem - 2) * 2 - 1 * (Math.pow(zoom, 2) - 1));
37+
2538
const message = $derived(commit.message);
2639
const description = $derived(splitMessage(message).description);
27-
const abbreviated = $derived(truncate(description, 80, 3));
40+
const abbreviated = $derived(truncate(description, maxLength, 3));
2841
const isAbbrev = $derived(abbreviated !== description);
2942
3043
let expanded = $state(false);
@@ -70,7 +83,12 @@
7083
</div>
7184

7285
{#if description}
73-
<div class="text-13 description" class:expanded data-testid={TestId.CommitDrawerDescription}>
86+
<div
87+
class="text-13 description"
88+
class:expanded
89+
bind:clientWidth={messageWidth}
90+
data-testid={TestId.CommitDrawerDescription}
91+
>
7492
{#if expanded}
7593
{description}
7694
{:else}

apps/desktop/src/components/Drawer.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
scrollingAttachment,
77
type TargetType
88
} from '$lib/intelligentScrolling/service';
9-
import { inject } from '@gitbutler/shared/context';
9+
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
10+
import { getContextStoreBySymbol, inject } from '@gitbutler/shared/context';
1011
import { persistWithExpiration } from '@gitbutler/shared/persisted';
1112
import Button from '@gitbutler/ui/Button.svelte';
1213
import Icon from '@gitbutler/ui/Icon.svelte';
@@ -57,6 +58,8 @@
5758
}: Props = $props();
5859
5960
const [intelligentScrollingService] = inject(IntelligentScrollingService);
61+
const userSettings = getContextStoreBySymbol<Settings>(SETTINGS);
62+
const zoom = $derived($userSettings.zoom);
6063
6164
let headerDiv = $state<HTMLDivElement>();
6265
let containerDiv = $state<HTMLDivElement>();
@@ -69,6 +72,7 @@
6972
7073
let headerHeight = $state(0);
7174
let contentHeight = $state(0);
75+
const totalHeightRem = $derived(pxToRem(headerHeight + contentHeight, zoom));
7276
</script>
7377

7478
<div
@@ -157,8 +161,8 @@
157161
direction="down"
158162
imitateBorder
159163
{...resizer}
160-
maxHeight={resizer.maxHeight
161-
? Math.min(resizer.maxHeight, pxToRem(contentHeight + headerHeight, 1))
164+
maxHeight={resizer.maxHeight && resizer.minHeight
165+
? Math.min(resizer.maxHeight, Math.max(totalHeightRem, resizer.minHeight))
162166
: undefined}
163167
passive={resizer.passive}
164168
/>
@@ -171,7 +175,7 @@
171175
position: relative;
172176
flex-direction: column;
173177
width: 100%;
174-
max-height: calc(100% + 1px);
178+
max-height: 100%;
175179
overflow: hidden;
176180
background-color: var(--clr-bg-1);
177181

apps/desktop/src/components/Resizer.svelte

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,19 @@
113113
let overflow: number;
114114
switch (direction) {
115115
case 'down':
116-
newValue =
117-
minHeight > maxHeight
118-
? Math.max(value, minHeight)
119-
: Math.min(Math.max(value, minHeight), maxHeight);
116+
newValue = Math.min(Math.max(value, minHeight), maxHeight);
120117
overflow = minHeight - value;
121118
break;
122119
case 'up':
123-
newValue =
124-
minHeight > maxHeight
125-
? Math.max(value, minHeight)
126-
: Math.min(Math.max(value, minHeight), maxHeight);
120+
newValue = Math.min(Math.max(value, minHeight), maxHeight);
127121
overflow = minHeight - value;
128122
break;
129123
case 'right':
130-
newValue =
131-
minWidth > maxWidth
132-
? Math.max(value, minWidth)
133-
: Math.min(Math.max(value, minWidth), maxWidth);
124+
newValue = Math.min(Math.max(value, minWidth), maxWidth);
134125
overflow = minWidth - value;
135126
break;
136127
case 'left':
137-
newValue =
138-
minWidth > maxWidth
139-
? Math.max(value, minWidth)
140-
: Math.min(Math.max(value, minWidth), maxWidth);
128+
newValue = Math.min(Math.max(value, minWidth), maxWidth);
141129
overflow = minWidth - value;
142130
break;
143131
}

0 commit comments

Comments
 (0)