fix(tui): refine diff view keyboard shortcuts (#28896)

This commit is contained in:
James Long
2026-05-22 14:40:14 -04:00
committed by GitHub
parent 1857c73565
commit 8f7a6c4a00
@@ -7,7 +7,7 @@ import { useBindings, useCommandShortcut } from "@tui/keymap"
import { useTheme } from "@tui/context/theme" import { useTheme } from "@tui/context/theme"
import { useTerminalDimensions } from "@opentui/solid" import { useTerminalDimensions } from "@opentui/solid"
import path from "path" import path from "path"
import { createEffect, createMemo, createResource, createSignal, For, Match, Show, Switch } from "solid-js" import { createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js"
import { DiffViewerFileTree } from "./diff-viewer-file-tree" import { DiffViewerFileTree } from "./diff-viewer-file-tree"
import { Panel, PanelGroup, Separator } from "./diff-viewer-ui" import { Panel, PanelGroup, Separator } from "./diff-viewer-ui"
import { DialogSelect } from "@tui/ui/dialog-select" import { DialogSelect } from "@tui/ui/dialog-select"
@@ -145,6 +145,8 @@ function DiffViewer(props: { api: TuiPluginApi }) {
const [pendingPatchScrollFileIndex, setPendingPatchScrollFileIndex] = createSignal<number | undefined>() const [pendingPatchScrollFileIndex, setPendingPatchScrollFileIndex] = createSignal<number | undefined>()
const [patchFillerHeight, setPatchFillerHeight] = createSignal(0) const [patchFillerHeight, setPatchFillerHeight] = createSignal(0)
onCleanup(() => props.api.ui.dialog.clear())
createEffect(() => { createEffect(() => {
setExpandedFileNodes(allExpandedFileTreeDirectories(fileTree())) setExpandedFileNodes(allExpandedFileTreeDirectories(fileTree()))
setHighlightedFileNode(undefined) setHighlightedFileNode(undefined)
@@ -367,6 +369,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
title: "Close diff viewer", title: "Close diff viewer",
category: "VCS", category: "VCS",
run() { run() {
props.api.ui.dialog.clear()
props.api.route.navigate("home") props.api.route.navigate("home")
}, },
}, },
@@ -604,7 +607,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
const openSwitchDiffDialog = () => { const openSwitchDiffDialog = () => {
props.api.ui.dialog.replace(() => ( props.api.ui.dialog.replace(() => (
<DialogSelect <DialogSelect
title="Switch diff" title="Switch source"
skipFilter={true} skipFilter={true}
renderFilter={false} renderFilter={false}
current={mode()} current={mode()}
@@ -824,50 +827,55 @@ function DiffViewer(props: { api: TuiPluginApi }) {
function DiffViewerHelpDialog() { function DiffViewerHelpDialog() {
const { theme } = useTheme() const { theme } = useTheme()
const rows = [ const rows = [
{
shortcut: () => "q",
action: "Close viewer",
description: "Quit the diff viewer",
},
{ {
shortcut: useCommandShortcut("diff.switch_focus"), shortcut: useCommandShortcut("diff.switch_focus"),
action: "Focus file tree", action: "Focus file tree",
description: "Move keyboard focus between the file tree and patch pane.", description: "Move keyboard focus between the file tree and patch pane",
}, },
{ {
shortcut: useCommandShortcut("diff.next_file"), shortcut: useCommandShortcut("diff.next_file"),
action: "Next file", action: "Next file",
description: "Select the next changed file in file-tree order.", description: "Select the next changed file in file-tree order",
}, },
{ {
shortcut: useCommandShortcut("diff.previous_file"), shortcut: useCommandShortcut("diff.previous_file"),
action: "Previous file", action: "Previous file",
description: "Select the previous changed file in file-tree order.", description: "Select the previous changed file in file-tree order",
}, },
{ {
shortcut: useCommandShortcut("diff.toggle_file_tree"), shortcut: useCommandShortcut("diff.toggle_file_tree"),
action: "Toggle file tree", action: "Toggle file tree",
description: "Show or hide the file tree sidebar.", description: "Show or hide the file tree sidebar",
}, },
{ {
shortcut: useCommandShortcut("diff.single_patch"), shortcut: useCommandShortcut("diff.single_patch"),
action: "Toggle patches", action: "Toggle patches",
description: "Switch between one selected patch and all patches.", description: "Switch between one selected patch and all patches",
}, },
{ {
shortcut: useCommandShortcut("diff.switch_source"), shortcut: useCommandShortcut("diff.switch_source"),
action: "Switch source", action: "Switch source",
description: "Choose working tree or last-turn changes.", description: "Choose working tree or last-turn changes",
}, },
{ {
shortcut: useCommandShortcut("diff.toggle_view"), shortcut: useCommandShortcut("diff.toggle_view"),
action: "Toggle view", action: "Toggle view",
description: "Switch between split and unified diff layout.", description: "Switch between split and unified diff layout",
}, },
{ {
shortcut: useCommandShortcut("diff.expand_all"), shortcut: useCommandShortcut("diff.expand_all"),
action: "Expand all folders", action: "Expand all folders",
description: "Open every folder in the file tree.", description: "Open every folder in the file tree",
}, },
{ {
shortcut: useCommandShortcut("diff.mark_reviewed"), shortcut: useCommandShortcut("diff.mark_reviewed"),
action: "Mark reviewed", action: "Mark reviewed",
description: "Toggle reviewed state for the selected file.", description: "Toggle reviewed state for the selected file",
}, },
] ]