diff options
| author | adamelmore <[email protected]> | 2026-01-25 06:42:33 -0600 |
|---|---|---|
| committer | adamelmore <[email protected]> | 2026-01-25 06:43:27 -0600 |
| commit | dcc8d1a638723678b6aeb1da95fd29a30314d0c3 (patch) | |
| tree | 121051bd043679e7892968ceeaef11c0678dc5b4 /packages/app/src/components | |
| parent | ddc4e893598b7aeb54d8476e97332ab97c02002f (diff) | |
| download | opencode-dcc8d1a638723678b6aeb1da95fd29a30314d0c3.tar.gz opencode-dcc8d1a638723678b6aeb1da95fd29a30314d0c3.zip | |
perf(app): performance improvements
Diffstat (limited to 'packages/app/src/components')
| -rw-r--r-- | packages/app/src/components/prompt-input.tsx | 23 | ||||
| -rw-r--r-- | packages/app/src/components/session-context-usage.tsx | 14 | ||||
| -rw-r--r-- | packages/app/src/components/session/session-context-tab.tsx | 14 |
3 files changed, 41 insertions, 10 deletions
diff --git a/packages/app/src/components/prompt-input.tsx b/packages/app/src/components/prompt-input.tsx index 074a03582..ccff04efe 100644 --- a/packages/app/src/components/prompt-input.tsx +++ b/packages/app/src/components/prompt-input.tsx @@ -137,6 +137,8 @@ export const PromptInput: Component<PromptInputProps> = (props) => { let scrollRef!: HTMLDivElement let slashPopoverRef!: HTMLDivElement + const mirror = { input: false } + const scrollCursorIntoView = () => { const container = scrollRef const selection = window.getSelection() @@ -651,6 +653,25 @@ export const PromptInput: Component<PromptInputProps> = (props) => { () => prompt.current(), (currentParts) => { const inputParts = currentParts.filter((part) => part.type !== "image") as Prompt + + if (mirror.input) { + mirror.input = false + if (isNormalizedEditor()) return + + const selection = window.getSelection() + let cursorPosition: number | null = null + if (selection && selection.rangeCount > 0 && editorRef.contains(selection.anchorNode)) { + cursorPosition = getCursorPosition(editorRef) + } + + renderEditor(inputParts) + + if (cursorPosition !== null) { + setCursorPosition(editorRef, cursorPosition) + } + return + } + const domParts = parseFromDOM() if (isNormalizedEditor() && isPromptEqual(inputParts, domParts)) return @@ -765,6 +786,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => { setStore("savedPrompt", null) } if (prompt.dirty()) { + mirror.input = true prompt.set(DEFAULT_PROMPT, 0) } queueScroll() @@ -795,6 +817,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => { setStore("savedPrompt", null) } + mirror.input = true prompt.set([...rawParts, ...images], cursorPosition) queueScroll() } diff --git a/packages/app/src/components/session-context-usage.tsx b/packages/app/src/components/session-context-usage.tsx index cd43c33c1..4dbb9e048 100644 --- a/packages/app/src/components/session-context-usage.tsx +++ b/packages/app/src/components/session-context-usage.tsx @@ -26,13 +26,17 @@ export function SessionContextUsage(props: SessionContextUsageProps) { const view = createMemo(() => layout.view(sessionKey)) const messages = createMemo(() => (params.id ? (sync.data.message[params.id] ?? []) : [])) + const usd = createMemo( + () => + new Intl.NumberFormat(language.locale(), { + style: "currency", + currency: "USD", + }), + ) + const cost = createMemo(() => { - const locale = language.locale() const total = messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0) - return new Intl.NumberFormat(locale, { - style: "currency", - currency: "USD", - }).format(total) + return usd().format(total) }) const context = createMemo(() => { diff --git a/packages/app/src/components/session/session-context-tab.tsx b/packages/app/src/components/session/session-context-tab.tsx index 4c672af3e..37733caff 100644 --- a/packages/app/src/components/session/session-context-tab.tsx +++ b/packages/app/src/components/session/session-context-tab.tsx @@ -26,6 +26,14 @@ export function SessionContextTab(props: SessionContextTabProps) { const sync = useSync() const language = useLanguage() + const usd = createMemo( + () => + new Intl.NumberFormat(language.locale(), { + style: "currency", + currency: "USD", + }), + ) + const ctx = createMemo(() => { const last = findLast(props.messages(), (x) => { if (x.role !== "assistant") return false @@ -62,12 +70,8 @@ export function SessionContextTab(props: SessionContextTabProps) { }) const cost = createMemo(() => { - const locale = language.locale() const total = props.messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0) - return new Intl.NumberFormat(locale, { - style: "currency", - currency: "USD", - }).format(total) + return usd().format(total) }) const counts = createMemo(() => { |
