Skip to content

Commit

Permalink
chore: migrate BranchLabel to runes (gitbutlerapp#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Aug 19, 2024
1 parent 575d8a0 commit 776a66b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
5 changes: 1 addition & 4 deletions apps/desktop/src/lib/branch/BranchHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@
</div>

<div class="header__info">
<BranchLabel
name={branch.name}
on:change={(e) => handleBranchNameChange(e.detail.name)}
/>
<BranchLabel name={branch.name} onChange={(name) => handleBranchNameChange(name)} />
<div class="header__remote-branch">
<ActiveBranchStatus
{hasIntegratedCommits}
Expand Down
40 changes: 20 additions & 20 deletions apps/desktop/src/lib/branch/BranchLabel.svelte
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<script lang="ts">
import { resizeObserver } from '$lib/utils/resizeObserver';
import { createEventDispatcher } from 'svelte';
export let name: string;
export let disabled = false;
interface Props {
name: string;
disabled?: boolean;
onChange?: (value: string) => void;
}
let { name, disabled = false, onChange }: Props = $props();
let inputEl: HTMLInputElement;
let initialName = name;
let mesureEl: HTMLSpanElement;
let inputWidth: string | undefined;
const dispatch = createEventDispatcher<{
change: { name: string };
}>();
let inputWidth = $state('');
</script>

<span
use:resizeObserver={(e) => {
inputWidth = `${Math.round(e.frame.width)}px`;
}}
class="branch-name-mesure-el text-14 text-bold"
bind:this={mesureEl}>{name}</span
class="branch-name-measure-el text-14 text-bold"
>
{name}
</span>
<input
type="text"
{disabled}
bind:this={inputEl}
bind:value={name}
on:change={(e) => dispatch('change', { name: e.currentTarget.value.trim() })}
onchange={(e) => onChange?.(e.currentTarget.value.trim())}
title={name}
class="branch-name-input text-14 text-bold"
on:dblclick|stopPropagation
on:click|stopPropagation={() => {
ondblclick={(e) => e.stopPropagation()}
onclick={(e) => {
e.stopPropagation();
inputEl.focus();
}}
on:blur={() => {
onblur={() => {
if (name === '') name = initialName;
}}
on:focus={() => {
onfocus={() => {
initialName = name;
}}
on:keydown={(e) => {
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === 'Escape') {
inputEl.blur();
}
Expand All @@ -53,14 +53,14 @@
/>

<style lang="postcss">
.branch-name-mesure-el,
.branch-name-measure-el,
.branch-name-input {
min-width: 44px;
height: 20px;
padding: 2px 4px;
border: 1px solid transparent;
}
.branch-name-mesure-el {
.branch-name-measure-el {
pointer-events: none;
visibility: hidden;
border: 2px solid transparent;
Expand Down

0 comments on commit 776a66b

Please sign in to comment.