This commit is contained in:
Timothy Jaeryang Baek
2026-03-01 02:38:45 -06:00
parent d2b38127d0
commit ed1b959bc6
@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getContext, onDestroy } from 'svelte'; import { getContext, onDestroy, tick } from 'svelte';
import panzoom, { type PanZoom } from 'panzoom'; import panzoom, { type PanZoom } from 'panzoom';
import { marked } from 'marked'; import { marked } from 'marked';
import DOMPurify from 'dompurify'; import DOMPurify from 'dompurify';
@@ -19,6 +19,7 @@
export let editing = false; export let editing = false;
let editContent = ''; let editContent = '';
export let saving = false; export let saving = false;
let editTextarea: HTMLTextAreaElement;
// Reset edit state when switching files // Reset edit state when switching files
$: selectedFile, resetEdit(); $: selectedFile, resetEdit();
@@ -29,10 +30,12 @@
saving = false; saving = false;
}; };
export const startEdit = () => { export const startEdit = async () => {
editContent = fileContent ?? ''; editContent = fileContent ?? '';
editing = true; editing = true;
showRaw = true; showRaw = true;
await tick();
editTextarea?.focus();
}; };
export const saveEdit = async () => { export const saveEdit = async () => {
@@ -191,6 +194,7 @@
{:else} {:else}
{#if editing} {#if editing}
<textarea <textarea
bind:this={editTextarea}
bind:value={editContent} bind:value={editContent}
class="w-full h-full text-xs font-mono text-gray-800 dark:text-gray-200 whitespace-pre break-all leading-relaxed p-3 bg-transparent border-none outline-none resize-none" class="w-full h-full text-xs font-mono text-gray-800 dark:text-gray-200 whitespace-pre break-all leading-relaxed p-3 bg-transparent border-none outline-none resize-none"
spellcheck="false" spellcheck="false"