mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-25 18:54:56 +01:00
fix(desktop): prompt clearing inconsistent
This commit is contained in:
@@ -319,7 +319,9 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
|
|||||||
|
|
||||||
session.layout.setActiveTab(undefined)
|
session.layout.setActiveTab(undefined)
|
||||||
session.messages.setActive(undefined)
|
session.messages.setActive(undefined)
|
||||||
session.prompt.set(DEFAULT_PROMPT, 0)
|
// Clear the editor DOM directly to ensure it's empty
|
||||||
|
editorRef.innerHTML = ""
|
||||||
|
session.prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0)
|
||||||
|
|
||||||
sdk.client.session.prompt({
|
sdk.client.session.prompt({
|
||||||
path: { id: existing.id },
|
path: { id: existing.id },
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createStore, produce } from "solid-js/store"
|
import { createStore, produce } from "solid-js/store"
|
||||||
import { createSimpleContext } from "./helper"
|
import { createSimpleContext } from "./helper"
|
||||||
import { batch, createEffect, createMemo, createSignal, on } from "solid-js"
|
import { batch, createEffect, createMemo } from "solid-js"
|
||||||
import { useSync } from "./sync"
|
import { useSync } from "./sync"
|
||||||
import { makePersisted } from "@solid-primitives/storage"
|
import { makePersisted } from "@solid-primitives/storage"
|
||||||
import { TextSelection, useLocal } from "./local"
|
import { TextSelection, useLocal } from "./local"
|
||||||
@@ -13,9 +13,7 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
const sync = useSync()
|
const sync = useSync()
|
||||||
const local = useLocal()
|
const local = useLocal()
|
||||||
|
|
||||||
const seed = props.sessionId ?? "new-session"
|
const [store, setStore] = makePersisted(
|
||||||
|
|
||||||
const [persist, setPersist] = makePersisted(
|
|
||||||
createStore<{
|
createStore<{
|
||||||
messageId?: string
|
messageId?: string
|
||||||
tabs: {
|
tabs: {
|
||||||
@@ -32,7 +30,7 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
cursor: undefined,
|
cursor: undefined,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: seed,
|
name: props.sessionId ?? "new-session",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,8 +50,8 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
return userMessages()?.at(0)
|
return userMessages()?.at(0)
|
||||||
})
|
})
|
||||||
const activeMessage = createMemo(() => {
|
const activeMessage = createMemo(() => {
|
||||||
if (!persist.messageId) return lastUserMessage()
|
if (!store.messageId) return lastUserMessage()
|
||||||
return userMessages()?.find((m) => m.id === persist.messageId)
|
return userMessages()?.find((m) => m.id === store.messageId)
|
||||||
})
|
})
|
||||||
const working = createMemo(() => {
|
const working = createMemo(() => {
|
||||||
if (!props.sessionId) return false
|
if (!props.sessionId) return false
|
||||||
@@ -104,14 +102,14 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
working,
|
working,
|
||||||
diffs,
|
diffs,
|
||||||
prompt: {
|
prompt: {
|
||||||
current: createMemo(() => persist.prompt),
|
current: createMemo(() => store.prompt),
|
||||||
cursor: createMemo(() => persist.cursor),
|
cursor: createMemo(() => store.cursor),
|
||||||
dirty: createMemo(() => !isPromptEqual(persist.prompt, DEFAULT_PROMPT)),
|
dirty: createMemo(() => !isPromptEqual(store.prompt, DEFAULT_PROMPT)),
|
||||||
set(prompt: Prompt, cursorPosition?: number) {
|
set(prompt: Prompt, cursorPosition?: number) {
|
||||||
const next = clonePrompt(prompt)
|
const next = clonePrompt(prompt)
|
||||||
batch(() => {
|
batch(() => {
|
||||||
setPersist("prompt", next)
|
setStore("prompt", next)
|
||||||
if (cursorPosition !== undefined) setPersist("cursor", cursorPosition)
|
if (cursorPosition !== undefined) setStore("cursor", cursorPosition)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -121,7 +119,7 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
last: lastUserMessage,
|
last: lastUserMessage,
|
||||||
active: activeMessage,
|
active: activeMessage,
|
||||||
setActive(id: string | undefined) {
|
setActive(id: string | undefined) {
|
||||||
setPersist("messageId", id)
|
setStore("messageId", id)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
usage: {
|
usage: {
|
||||||
@@ -130,46 +128,46 @@ export const { use: useSession, provider: SessionProvider } = createSimpleContex
|
|||||||
context,
|
context,
|
||||||
},
|
},
|
||||||
layout: {
|
layout: {
|
||||||
tabs: persist.tabs,
|
tabs: store.tabs,
|
||||||
setActiveTab(tab: string | undefined) {
|
setActiveTab(tab: string | undefined) {
|
||||||
setPersist("tabs", "active", tab)
|
setStore("tabs", "active", tab)
|
||||||
},
|
},
|
||||||
setOpenedTabs(tabs: string[]) {
|
setOpenedTabs(tabs: string[]) {
|
||||||
setPersist("tabs", "opened", tabs)
|
setStore("tabs", "opened", tabs)
|
||||||
},
|
},
|
||||||
async openTab(tab: string) {
|
async openTab(tab: string) {
|
||||||
if (tab === "chat") {
|
if (tab === "chat") {
|
||||||
setPersist("tabs", "active", undefined)
|
setStore("tabs", "active", undefined)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (tab.startsWith("file://")) {
|
if (tab.startsWith("file://")) {
|
||||||
await local.file.open(tab.replace("file://", ""))
|
await local.file.open(tab.replace("file://", ""))
|
||||||
}
|
}
|
||||||
if (tab !== "review") {
|
if (tab !== "review") {
|
||||||
if (!persist.tabs.opened.includes(tab)) {
|
if (!store.tabs.opened.includes(tab)) {
|
||||||
setPersist("tabs", "opened", [...persist.tabs.opened, tab])
|
setStore("tabs", "opened", [...store.tabs.opened, tab])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setPersist("tabs", "active", tab)
|
setStore("tabs", "active", tab)
|
||||||
},
|
},
|
||||||
closeTab(tab: string) {
|
closeTab(tab: string) {
|
||||||
batch(() => {
|
batch(() => {
|
||||||
setPersist(
|
setStore(
|
||||||
"tabs",
|
"tabs",
|
||||||
"opened",
|
"opened",
|
||||||
persist.tabs.opened.filter((x) => x !== tab),
|
store.tabs.opened.filter((x) => x !== tab),
|
||||||
)
|
)
|
||||||
if (persist.tabs.active === tab) {
|
if (store.tabs.active === tab) {
|
||||||
const index = persist.tabs.opened.findIndex((f) => f === tab)
|
const index = store.tabs.opened.findIndex((f) => f === tab)
|
||||||
const previous = persist.tabs.opened[Math.max(0, index - 1)]
|
const previous = store.tabs.opened[Math.max(0, index - 1)]
|
||||||
setPersist("tabs", "active", previous)
|
setStore("tabs", "active", previous)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
moveTab(tab: string, to: number) {
|
moveTab(tab: string, to: number) {
|
||||||
const index = persist.tabs.opened.findIndex((f) => f === tab)
|
const index = store.tabs.opened.findIndex((f) => f === tab)
|
||||||
if (index === -1) return
|
if (index === -1) return
|
||||||
setPersist(
|
setStore(
|
||||||
"tabs",
|
"tabs",
|
||||||
"opened",
|
"opened",
|
||||||
produce((opened) => {
|
produce((opened) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user