feat(ui): wrap the YAML editor at the pane or a set print width, with an appearance setting

This commit is contained in:
sam committed 2026-10-19 09:41:03 +11:00
1 parent f4d0b45672
commit b2eba7a8f0
5 files changed
+206 -131

No files matched your search

+53 -27
View File
@@ -8,7 +8,7 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { CircleAlert, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
import { isSending, setTurnHooks } from "@/chat/state";
@@ -354,12 +354,35 @@ const lines = computed(() => yamlLines(yaml.value));
const SECTIONS: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
// The highlight layer sits behind the textarea and never scrolls by itself, so
// it follows the textarea's own scroll on both axes.
const scrolled = ref({ top: 0, left: 0 });
// it follows the textarea's own scroll. Lines wrap at the editor's width, and
// each wrapped line's gutter cell lists a continuation mark per extra row, so
// the numbers still count lines of the file. A row's wrapped height is measured
// from the layer, which breaks exactly where the textarea does.
const scrolled = ref({ top: 0 });
const scrollbar = ref(0);
const rowEls = ref<HTMLElement[]>([]);
const wraps = ref<number[]>([]);
const yamlBox = ref<InstanceType<typeof Textarea> | null>(null);
function syncScroll(event: Event): void {
const { scrollTop, scrollLeft } = event.target as HTMLTextAreaElement;
scrolled.value = { top: scrollTop, left: scrollLeft };
scrolled.value = { top: (event.target as HTMLTextAreaElement).scrollTop };
}
function measureWraps(): void {
const field = document.getElementById("workflow-yaml");
scrollbar.value = field ? field.offsetWidth - field.clientWidth : 0;
wraps.value = rowEls.value.map((row) =>
Math.max(1, Math.round(row.offsetHeight / (parseFloat(getComputedStyle(row).lineHeight) || 24))),
);
}
let yamlObserver: ResizeObserver | undefined;
watch(yamlBox, (box) => {
yamlObserver?.disconnect();
const field = box ? document.getElementById("workflow-yaml") : null;
if (!field) return;
yamlObserver = new ResizeObserver(measureWraps);
yamlObserver.observe(field);
});
watch(lines, () => nextTick(measureWraps), { flush: "post" });
onBeforeUnmount(() => yamlObserver?.disconnect());
</script>
@@ -509,44 +532,47 @@ function syncScroll(event: Event): void {
>
<div
aria-hidden="true"
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none overflow-hidden border-r border-border bg-secondary/40 py-3 text-right"
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none border-r border-border bg-secondary/40"
></div>
<div
aria-hidden="true"
class="pointer-events-none absolute inset-0 overflow-hidden py-3 pr-3"
:style="{ paddingRight: `calc(0.75rem + ${scrollbar}px)` }"
>
<div :style="`transform:translateY(${-scrolled.top}px)`">
<div
v-for="line in lines"
v-for="(line, i) in lines"
:key="line.number"
class="min-h-6 pr-2 text-fg-subtle"
>{{ line.number }}</div
:ref="(el) => { if (el) rowEls[i] = el as HTMLElement }"
class="flex min-h-6"
>
</div>
</div>
<!-- Clipped to the right of the gutter, so a line scrolled left never
paints over the numbers. -->
<div
aria-hidden="true"
class="pointer-events-none absolute inset-y-0 right-0 left-11 overflow-hidden py-3 pr-3 pl-3 whitespace-pre"
>
<div :style="`transform:translate(${-scrolled.left}px,${-scrolled.top}px)`">
<div v-for="line in lines" :key="line.number" class="min-h-6">
<span
v-for="(token, i) in line.tokens"
:key="i"
:class="yamlTokenClass(token.kind)"
>{{ token.text }}</span
>
<div class="w-11 shrink-0 select-none pr-2 text-right text-fg-subtle">
<div>{{ line.number }}</div>
<div v-for="n in (wraps[i] ?? 1) - 1" :key="n">↳</div>
</div>
<div class="max-w-[calc(var(--code-print-width)+0.75rem)] min-w-0 flex-1 pl-3 break-words whitespace-pre-wrap">
<span
v-for="(token, j) in line.tokens"
:key="j"
:class="yamlTokenClass(token.kind)"
>{{ token.text }}</span
>
</div>
</div>
</div>
</div>
<Textarea
id="workflow-yaml"
ref="yamlBox"
aria-label="Workflow YAML"
v-model="yaml"
name="workflow-yaml"
required
:readonly="archieWorking"
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent pt-3 pr-3 pb-[calc(0.75rem+var(--code-overscroll))] pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent pt-3 pr-3 pb-[calc(0.75rem+var(--code-overscroll))] pl-14 text-[13px] leading-6 break-words whitespace-pre-wrap text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
spellcheck="false"
wrap="off"
wrap="soft"
:style="{ maxWidth: `calc(3.5rem + var(--code-print-width) + 0.75rem + ${scrollbar}px)` }"
@scroll="syncScroll"
/>
</div>