From 361623aaccf08063712500a213548a2756dd13c4 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Tue, 13 May 2025 18:01:19 -0400
Subject: Implement the disabled state:

* Suppress input (including paste) while the input is disabled.
* Style the input to make it visible that it's not accepting input.
---
 ui/lib/components/MessageInput.svelte | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'ui/lib/components/MessageInput.svelte')

diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte
index 71b7b8f..848321d 100644
--- a/ui/lib/components/MessageInput.svelte
+++ b/ui/lib/components/MessageInput.svelte
@@ -3,8 +3,6 @@
 
   let form = $state(null);
   let value = $state('');
-  // This doesn't seem to work with a contenteditable two-way bound svelte
-  // thing:
   let disabled = $state(false);
 
   async function onsubmit(event) {
@@ -19,21 +17,35 @@
   }
 
   function onkeydown(event) {
+    if (disabled) {
+      event.preventDefault();
+      return;
+    }
+
     let modifier = event.shiftKey || event.altKey || event.ctrlKey || event.metaKey;
     if (!modifier && event.key === 'Enter') {
       event.preventDefault();
       form?.requestSubmit?.();
     }
   }
+
+  function onpaste(event) {
+    if (disabled) {
+      event.preventDefault();
+    }
+  }
 </script>
 
 <form {onsubmit} bind:this={form}>
   <div
     contenteditable="plaintext-only"
-    class="textarea"
+    class={{
+      textarea: true,
+      disabled
+    }}
     bind:innerText={value}
     {onkeydown}
-    {disabled}
+    {onpaste}
     placeholder="Say something..."
   ></div>
   <button type="submit">&raquo;</button>
-- 
cgit v1.2.3

