fix: resize markdown preview as well

This commit is contained in:
2026-01-25 08:38:32 -05:00
parent 9c49c21e62
commit 51449abe6e
+26 -15
View File
@@ -21,6 +21,7 @@
export let data: PageData; export let data: PageData;
let textArea: HTMLTextAreaElement; let textArea: HTMLTextAreaElement;
let markdownConatiner: HTMLDivElement;
let error = ''; let error = '';
let title = ''; let title = '';
@@ -54,25 +55,34 @@
renderedMarkdown = await parseMarkdown(content, false); renderedMarkdown = await parseMarkdown(content, false);
} }
previewMode = toPreview; previewMode = toPreview;
if (!toPreview) { requestAnimationFrame(() => resize(true));
requestAnimationFrame(resize);
}
} }
function resize() { function resize(markdown: boolean = false) {
if (!textArea) return; if ((!markdown && !textArea) || (markdown && !markdownConatiner)) return;
let h: number;
let max: number;
let element = markdown ? markdownConatiner : textArea;
if (!markdown) {
textArea.style.height = 'auto'; textArea.style.height = 'auto';
const h = textArea.scrollHeight; h = textArea.scrollHeight;
const max = MAX_HEIGHT(); max = MAX_HEIGHT();
} else {
markdownConatiner.style.height = 'auto';
h = markdownConatiner.scrollHeight;
max = MAX_HEIGHT();
}
if (h > max) { if (h > max) {
textArea.style.height = max + 'px'; element.style.height = max + 'px';
textArea.style.overflowY = 'auto'; element.style.overflowY = 'auto';
} else { } else {
textArea.style.height = h + 'px'; element.style.height = h + 'px';
textArea.style.overflowY = 'hidden'; element.style.overflowY = 'hidden';
} }
} }
@@ -242,6 +252,7 @@
<div <div
class="markdown min-h-20 w-full overflow-y-auto rounded rounded-b-none border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200" class="markdown min-h-20 w-full overflow-y-auto rounded rounded-b-none border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200"
style="height: {previewHeight}" style="height: {previewHeight}"
bind:this={markdownConatiner}
> >
{@html renderedMarkdown} {@html renderedMarkdown}
</div> </div>
@@ -254,9 +265,9 @@
minlength="1" minlength="1"
bind:this={textArea} bind:this={textArea}
bind:value={content} bind:value={content}
on:input={resize} on:input={() => resize()}
on:change={resize} on:change={() => resize()}
on:focus={resize} on:focus={() => resize()}
on:beforeinput={(e) => { on:beforeinput={(e) => {
if (!data.options?.maxPasteSize) return; if (!data.options?.maxPasteSize) return;
@@ -285,7 +296,7 @@
isDragging = false; isDragging = false;
}} }}
on:drop={(e) => { on:drop={(e) => {
requestAnimationFrame(resize); requestAnimationFrame(() => resize());
e.preventDefault(); e.preventDefault();
isDragging = false; isDragging = false;