mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 14:55:19 +00:00
fix: let users clear sidebar modified files without mutating diff state
This commit is contained in:
@@ -152,6 +152,18 @@ export function Session() {
|
||||
const [showHeader, setShowHeader] = kv.signal("header_visible", true)
|
||||
const [diffWrapMode] = kv.signal<"word" | "none">("diff_wrap_mode", "word")
|
||||
const [animationsEnabled, setAnimationsEnabled] = kv.signal("animations_enabled", true)
|
||||
const [clearedDiff, setClearedDiff] = createSignal<Record<string, string>>({})
|
||||
const diff = createMemo(() => sync.data.session_diff[route.sessionID] ?? [])
|
||||
const diffStamp = createMemo(() =>
|
||||
diff()
|
||||
.map((item) => `${item.file}:${item.additions}:${item.deletions}`)
|
||||
.join("\n"),
|
||||
)
|
||||
const diffHidden = createMemo(() => {
|
||||
const mark = clearedDiff()[route.sessionID]
|
||||
if (!mark) return false
|
||||
return mark === diffStamp()
|
||||
})
|
||||
|
||||
const wide = createMemo(() => dimensions().width > 120)
|
||||
const sidebarVisible = createMemo(() => {
|
||||
@@ -163,6 +175,18 @@ export function Session() {
|
||||
const showTimestamps = createMemo(() => timestamps() === "show")
|
||||
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
|
||||
|
||||
createEffect(() => {
|
||||
const mark = clearedDiff()[route.sessionID]
|
||||
if (!mark) return
|
||||
if (mark === diffStamp()) return
|
||||
setClearedDiff((prev) => {
|
||||
if (!prev[route.sessionID]) return prev
|
||||
const next = { ...prev }
|
||||
delete next[route.sessionID]
|
||||
return next
|
||||
})
|
||||
})
|
||||
|
||||
const scrollAcceleration = createMemo(() => {
|
||||
const tui = sync.data.config.tui
|
||||
if (tui?.scroll_acceleration?.enabled) {
|
||||
@@ -526,6 +550,19 @@ export function Session() {
|
||||
dialog.clear()
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Clear Modified",
|
||||
value: "session.modified.clear",
|
||||
category: "Session",
|
||||
enabled: !session()?.parentID && !diffHidden() && diff().length > 0,
|
||||
onSelect: (dialog) => {
|
||||
setClearedDiff((prev) => ({
|
||||
...prev,
|
||||
[route.sessionID]: diffStamp(),
|
||||
}))
|
||||
dialog.clear()
|
||||
},
|
||||
},
|
||||
{
|
||||
title: conceal() ? "Disable code concealment" : "Enable code concealment",
|
||||
value: "session.toggle.conceal",
|
||||
@@ -1120,7 +1157,7 @@ export function Session() {
|
||||
<Show when={sidebarVisible()}>
|
||||
<Switch>
|
||||
<Match when={wide()}>
|
||||
<Sidebar sessionID={route.sessionID} />
|
||||
<Sidebar sessionID={route.sessionID} hideDiff={diffHidden()} />
|
||||
</Match>
|
||||
<Match when={!wide()}>
|
||||
<box
|
||||
@@ -1132,7 +1169,7 @@ export function Session() {
|
||||
alignItems="flex-end"
|
||||
backgroundColor={RGBA.fromInts(0, 0, 0, 70)}
|
||||
>
|
||||
<Sidebar sessionID={route.sessionID} />
|
||||
<Sidebar sessionID={route.sessionID} hideDiff={diffHidden()} />
|
||||
</box>
|
||||
</Match>
|
||||
</Switch>
|
||||
|
||||
@@ -12,11 +12,14 @@ import { useDirectory } from "../../context/directory"
|
||||
import { useKV } from "../../context/kv"
|
||||
import { TodoItem } from "../../component/todo-item"
|
||||
|
||||
export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
|
||||
export function Sidebar(props: { sessionID: string; overlay?: boolean; hideDiff?: boolean }) {
|
||||
const sync = useSync()
|
||||
const { theme } = useTheme()
|
||||
const session = createMemo(() => sync.session.get(props.sessionID)!)
|
||||
const diff = createMemo(() => sync.data.session_diff[props.sessionID] ?? [])
|
||||
const diff = createMemo(() => {
|
||||
if (props.hideDiff) return []
|
||||
return sync.data.session_diff[props.sessionID] ?? []
|
||||
})
|
||||
const todo = createMemo(() => sync.data.todo[props.sessionID] ?? [])
|
||||
const messages = createMemo(() => sync.data.message[props.sessionID] ?? [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user