mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Support Shift+Enter for newlines in chat input
The chat field was a single-line <input>, unable to hold a line break. Switch it to an auto-growing <textarea>: plain Enter still sends, Shift+Enter inserts a newline.
This commit is contained in:
1 parent
69b256eb42
commit
af3a7c97cf
2 files changed
+22
-3
No files matched your search
+5
-1
@@ -645,14 +645,18 @@
|
|||||||
border-top: 1px solid var(--border-soft);
|
border-top: 1px solid var(--border-soft);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ts-chat-input-row input {
|
.ts-chat-input-row textarea {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
padding: 0.3rem 0.5rem;
|
padding: 0.3rem 0.5rem;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
font-family: inherit;
|
||||||
background: var(--input-bg);
|
background: var(--input-bg);
|
||||||
color: var(--input-text);
|
color: var(--input-text);
|
||||||
|
resize: none;
|
||||||
|
max-height: 8.5em;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ts-chat-input-row button {
|
.ts-chat-input-row button {
|
||||||
|
|||||||
+17
-2
@@ -1399,6 +1399,7 @@ function AppInner() {
|
|||||||
const [chat, setChat] = useState<ChatEntry[]>([]);
|
const [chat, setChat] = useState<ChatEntry[]>([]);
|
||||||
const [serverChat, setServerChat] = useState<ChatEntry[]>([]);
|
const [serverChat, setServerChat] = useState<ChatEntry[]>([]);
|
||||||
const [chatInput, setChatInput] = useState("");
|
const [chatInput, setChatInput] = useState("");
|
||||||
|
const chatInputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const [pmThreads, setPmThreads] = useState<Record<number, PmThread>>({});
|
const [pmThreads, setPmThreads] = useState<Record<number, PmThread>>({});
|
||||||
const [pokes, setPokes] = useState<PokeNotice[]>([]);
|
const [pokes, setPokes] = useState<PokeNotice[]>([]);
|
||||||
const [pokeTarget, setPokeTarget] = useState<{ id: number; name: string } | null>(null);
|
const [pokeTarget, setPokeTarget] = useState<{ id: number; name: string } | null>(null);
|
||||||
@@ -2092,6 +2093,13 @@ function AppInner() {
|
|||||||
|
|
||||||
const handleSelectItem = (item: SelectedItem) => setSelected(item);
|
const handleSelectItem = (item: SelectedItem) => setSelected(item);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = chatInputRef.current;
|
||||||
|
if (!el) return;
|
||||||
|
el.style.height = "auto";
|
||||||
|
el.style.height = `${el.scrollHeight}px`;
|
||||||
|
}, [chatInput]);
|
||||||
|
|
||||||
const handleSendChat = () => {
|
const handleSendChat = () => {
|
||||||
const message = chatInput.trim();
|
const message = chatInput.trim();
|
||||||
if (!message) return;
|
if (!message) return;
|
||||||
@@ -2695,10 +2703,17 @@ function AppInner() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="ts-chat-input-row">
|
<div className="ts-chat-input-row">
|
||||||
<input
|
<textarea
|
||||||
|
ref={chatInputRef}
|
||||||
|
rows={1}
|
||||||
value={chatInput}
|
value={chatInput}
|
||||||
onChange={(e) => setChatInput(e.target.value)}
|
onChange={(e) => setChatInput(e.target.value)}
|
||||||
onKeyDown={(e) => e.key === "Enter" && handleSendChat()}
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
handleSendChat();
|
||||||
|
}
|
||||||
|
}}
|
||||||
disabled={!connected}
|
disabled={!connected}
|
||||||
placeholder={
|
placeholder={
|
||||||
!connected
|
!connected
|
||||||
|
|||||||
Reference in new issue
Block a user