From 11103527b0f3593e15d0919563e69fe6c23ab8d9 Mon Sep 17 00:00:00 2001 From: fly_mc Date: Wed, 18 Sep 2024 23:00:06 +0800 Subject: [PATCH] autosize --- packages/frontend/package.json | 2 ++ packages/frontend/src/components/MkPostForm.vue | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 1464be18a..ce2ebf126 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -31,6 +31,7 @@ "@vue/compiler-sfc": "3.4.37", "aiscript-vscode": "github:aiscript-dev/aiscript-vscode#v0.1.11", "astring": "1.8.6", + "autosize": "^6.0.1", "broadcast-channel": "7.0.0", "buraha": "0.0.1", "canvas-confetti": "1.9.3", @@ -96,6 +97,7 @@ "@storybook/vue3": "8.2.6", "@storybook/vue3-vite": "8.1.11", "@testing-library/vue": "8.1.0", + "@types/autosize": "^4.0.3", "@types/escape-regexp": "0.0.3", "@types/estree": "1.0.5", "@types/matter-js": "0.19.7", diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue index c1383e5f6..705a83678 100644 --- a/packages/frontend/src/components/MkPostForm.vue +++ b/packages/frontend/src/components/MkPostForm.vue @@ -105,6 +105,7 @@ import * as mfm from 'mfm-js'; import * as Misskey from 'misskey-js'; import insertTextAtCursor from 'insert-text-at-cursor'; import { toASCII } from 'punycode/'; +import autosize from 'autosize'; import MkNoteSimple from '@/components/MkNoteSimple.vue'; import MkNotePreview from '@/components/MkNotePreview.vue'; import XPostFormAttaches from '@/components/MkPostFormAttaches.vue'; @@ -569,20 +570,28 @@ function clear() { files.value = []; poll.value = null; quoteId.value = null; + + nextTick(() => textareaEl.value && autosize.update(textareaEl.value)); } function onKeydown(ev: KeyboardEvent) { if (ev.key === 'Enter' && (ev.ctrlKey || ev.metaKey) && canPost.value) post(); if (ev.key === 'Escape') emit('esc'); + + nextTick(() => textareaEl.value && autosize.update(textareaEl.value)); } function onCompositionUpdate(ev: CompositionEvent) { imeText.value = ev.data; + + nextTick(() => textareaEl.value && autosize.update(textareaEl.value)); } function onCompositionEnd(ev: CompositionEvent) { imeText.value = ''; + + nextTick(() => textareaEl.value && autosize.update(textareaEl.value)); } async function onPaste(ev: ClipboardEvent) { @@ -634,6 +643,7 @@ async function onPaste(ev: ClipboardEvent) { upload(file, `${fileName}.txt`); }); } + nextTick(() => textareaEl.value && autosize.update(textareaEl.value)); } function onDragover(ev) { @@ -1042,6 +1052,7 @@ onMounted(() => { } nextTick(() => watchForDraft()); + nextTick(() => textareaEl.value && autosize(textareaEl.value)); }); });