Skip to content

Commit fe2cb05

Browse files
committed
chore: normalize line endings to LF
refactor: AutosizeTextareaApi -> chatTextareaApi
1 parent 0ebbb6a commit fe2cb05

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed
-9 Bytes
Binary file not shown.

examples/server/webui/src/components/ChatScreen.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import { classNames, cleanCurrentUrl, throttle } from '../utils/misc';
66
import CanvasPyInterpreter from './CanvasPyInterpreter';
77
import StorageUtils from '../utils/storage';
88
import { useVSCodeContext } from '../utils/llama-vscode';
9-
import {
10-
useChatTextarea,
11-
AutosizeTextareaApi,
12-
} from './useChatTextarea.ts';
13-
9+
import { useChatTextarea, chatTextareaApi } from './useChatTextarea.ts';
1410

1511
/**
1612
* A message display is a message node with additional information for rendering.
@@ -95,7 +91,6 @@ const scrollToBottom = throttle(
9591
);
9692

9793
export default function ChatScreen() {
98-
9994
const {
10095
viewingChat,
10196
sendMessage,
@@ -106,9 +101,7 @@ export default function ChatScreen() {
106101
replaceMessageAndGenerate,
107102
} = useAppContext();
108103

109-
const textarea: AutosizeTextareaApi = useChatTextarea(
110-
prefilledMsg.content()
111-
);
104+
const textarea: chatTextareaApi = useChatTextarea(prefilledMsg.content());
112105

113106
const { extraContext, clearExtraContext } = useVSCodeContext(textarea);
114107
// TODO: improve this when we have "upload file" feature
@@ -267,7 +260,7 @@ export default function ChatScreen() {
267260
onInput={textarea.onInput} // Hook's input handler (will only resize height on lg+ screens)
268261
onKeyDown={(e) => {
269262
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
270-
if (e.key === 'Enter' && !e.shiftKey) {
263+
if (e.key === 'Enter' && !e.shiftKey) {
271264
e.preventDefault();
272265
sendNewMessage();
273266
}

examples/server/webui/src/components/useChatTextarea.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const adjustTextareaHeight = (textarea: HTMLTextAreaElement | null) => {
3232
};
3333

3434
// Interface describing the API returned by the hook
35-
export interface AutosizeTextareaApi {
35+
export interface chatTextareaApi {
3636
value: () => string;
3737
setValue: (value: string) => void;
3838
focus: () => void;
@@ -43,7 +43,7 @@ export interface AutosizeTextareaApi {
4343
// This is a workaround to prevent the textarea from re-rendering when the inner content changes
4444
// See https://github.com/ggml-org/llama.cpp/pull/12299
4545
// combined now with auto-sizing logic.
46-
export function useChatTextarea(initValue: string): AutosizeTextareaApi {
46+
export function useChatTextarea(initValue: string): chatTextareaApi {
4747
const [savedInitValue, setSavedInitValue] = useState<string>(initValue);
4848
const textareaRef = useRef<HTMLTextAreaElement>(null);
4949

@@ -63,10 +63,13 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
6363
}
6464
}, [textareaRef, savedInitValue]); // Depend on ref and savedInitValue
6565

66-
const handleInput = useCallback((event: React.FormEvent<HTMLTextAreaElement>) => {
67-
// Call adjustTextareaHeight on every input - it will decide whether to act
68-
adjustTextareaHeight(event.currentTarget);
69-
}, []);
66+
const handleInput = useCallback(
67+
(event: React.FormEvent<HTMLTextAreaElement>) => {
68+
// Call adjustTextareaHeight on every input - it will decide whether to act
69+
adjustTextareaHeight(event.currentTarget);
70+
},
71+
[]
72+
);
7073

7174
return {
7275
// Method to get the current value directly from the textarea
@@ -75,12 +78,12 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
7578
},
7679
// Method to programmatically set the value and trigger height adjustment
7780
setValue: (value: string) => {
78-
const textarea = textareaRef.current;
79-
if (textarea) {
80-
textarea.value = value;
81-
// Call adjustTextareaHeight - it will check screen size internally
82-
setTimeout(() => adjustTextareaHeight(textarea), 0);
83-
}
81+
const textarea = textareaRef.current;
82+
if (textarea) {
83+
textarea.value = value;
84+
// Call adjustTextareaHeight - it will check screen size internally
85+
setTimeout(() => adjustTextareaHeight(textarea), 0);
86+
}
8487
},
8588
focus: () => {
8689
if (textareaRef.current) {
@@ -90,4 +93,4 @@ export function useChatTextarea(initValue: string): AutosizeTextareaApi {
9093
ref: textareaRef,
9194
onInput: handleInput,
9295
};
93-
}
96+
}

examples/server/webui/src/utils/llama-vscode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import { MessageExtraContext } from './types';
3-
import { AutosizeTextareaApi } from '../components/useChatTextarea.ts';
3+
import { chatTextareaApi } from '../components/useChatTextarea.ts';
44

55
// Extra context when using llama.cpp WebUI from llama-vscode, inside an iframe
66
// Ref: https://github.com/ggml-org/llama.cpp/pull/11940
@@ -15,7 +15,7 @@ interface SetTextEvData {
1515
* window.postMessage({ command: 'setText', text: 'Spot the syntax error', context: 'def test()\n return 123' }, '*');
1616
*/
1717

18-
export const useVSCodeContext = (textarea: AutosizeTextareaApi ) => {
18+
export const useVSCodeContext = (textarea: chatTextareaApi) => {
1919
const [extraContext, setExtraContext] = useState<MessageExtraContext | null>(
2020
null
2121
);

0 commit comments

Comments
 (0)