fix(app): navigate to tabs when opening file
This commit is contained in:
@@ -26,7 +26,7 @@ type Entry = {
|
|||||||
|
|
||||||
type DialogSelectFileMode = "all" | "files"
|
type DialogSelectFileMode = "all" | "files"
|
||||||
|
|
||||||
export function DialogSelectFile(props: { mode?: DialogSelectFileMode }) {
|
export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFile?: (path: string) => void }) {
|
||||||
const command = useCommand()
|
const command = useCommand()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
const layout = useLayout()
|
const layout = useLayout()
|
||||||
@@ -164,6 +164,7 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode }) {
|
|||||||
tabs().open(value)
|
tabs().open(value)
|
||||||
file.load(path)
|
file.load(path)
|
||||||
view().reviewPanel.open()
|
view().reviewPanel.open()
|
||||||
|
props.onOpenFile?.(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSelect = (item: Entry | undefined) => {
|
const handleSelect = (item: Entry | undefined) => {
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ export default function Page() {
|
|||||||
category: language.t("command.category.file"),
|
category: language.t("command.category.file"),
|
||||||
keybind: "mod+p",
|
keybind: "mod+p",
|
||||||
slash: "open",
|
slash: "open",
|
||||||
onSelect: () => dialog.show(() => <DialogSelectFile />),
|
onSelect: () => dialog.show(() => <DialogSelectFile onOpenFile={() => showAllFiles()} />),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "context.addSelection",
|
id: "context.addSelection",
|
||||||
@@ -1084,11 +1084,31 @@ export default function Page() {
|
|||||||
const pendingDiff = () => tree.pendingDiff
|
const pendingDiff = () => tree.pendingDiff
|
||||||
const setPendingDiff = (value: string | undefined) => setTree("pendingDiff", value)
|
const setPendingDiff = (value: string | undefined) => setTree("pendingDiff", value)
|
||||||
|
|
||||||
|
const showAllFiles = () => {
|
||||||
|
if (!layout.fileTree.opened()) return
|
||||||
|
if (fileTreeTab() !== "changes") return
|
||||||
|
setFileTreeTab("all")
|
||||||
|
}
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (!layout.fileTree.opened()) return
|
if (!layout.fileTree.opened()) return
|
||||||
setFileTreeTab("changes")
|
setFileTreeTab("changes")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
createEffect(
|
||||||
|
on(
|
||||||
|
() => tabs().active(),
|
||||||
|
(active) => {
|
||||||
|
if (!active) return
|
||||||
|
if (!layout.fileTree.opened()) return
|
||||||
|
if (fileTreeTab() !== "changes") return
|
||||||
|
if (!file.pathFromTab(active)) return
|
||||||
|
showAllFiles()
|
||||||
|
},
|
||||||
|
{ defer: true },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
const setFileTreeTabValue = (value: string) => {
|
const setFileTreeTabValue = (value: string) => {
|
||||||
if (value !== "changes" && value !== "all") return
|
if (value !== "changes" && value !== "all") return
|
||||||
setFileTreeTab(value)
|
setFileTreeTab(value)
|
||||||
@@ -1702,6 +1722,7 @@ export default function Page() {
|
|||||||
focusedComment={comments.focus()}
|
focusedComment={comments.focus()}
|
||||||
onFocusedCommentChange={comments.setFocus}
|
onFocusedCommentChange={comments.setFocus}
|
||||||
onViewFile={(path) => {
|
onViewFile={(path) => {
|
||||||
|
showAllFiles()
|
||||||
const value = file.tab(path)
|
const value = file.tab(path)
|
||||||
tabs().open(value)
|
tabs().open(value)
|
||||||
file.load(path)
|
file.load(path)
|
||||||
@@ -2068,7 +2089,9 @@ export default function Page() {
|
|||||||
icon="plus-small"
|
icon="plus-small"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
iconSize="large"
|
iconSize="large"
|
||||||
onClick={() => dialog.show(() => <DialogSelectFile mode="files" />)}
|
onClick={() =>
|
||||||
|
dialog.show(() => <DialogSelectFile mode="files" onOpenFile={() => showAllFiles()} />)
|
||||||
|
}
|
||||||
aria-label={language.t("command.file.open")}
|
aria-label={language.t("command.file.open")}
|
||||||
/>
|
/>
|
||||||
</TooltipKeybind>
|
</TooltipKeybind>
|
||||||
@@ -2100,6 +2123,7 @@ export default function Page() {
|
|||||||
focusedComment={comments.focus()}
|
focusedComment={comments.focus()}
|
||||||
onFocusedCommentChange={comments.setFocus}
|
onFocusedCommentChange={comments.setFocus}
|
||||||
onViewFile={(path) => {
|
onViewFile={(path) => {
|
||||||
|
showAllFiles()
|
||||||
const value = file.tab(path)
|
const value = file.tab(path)
|
||||||
tabs().open(value)
|
tabs().open(value)
|
||||||
file.load(path)
|
file.load(path)
|
||||||
@@ -2679,6 +2703,7 @@ export default function Page() {
|
|||||||
focusedComment={comments.focus()}
|
focusedComment={comments.focus()}
|
||||||
onFocusedCommentChange={comments.setFocus}
|
onFocusedCommentChange={comments.setFocus}
|
||||||
onViewFile={(path) => {
|
onViewFile={(path) => {
|
||||||
|
showAllFiles()
|
||||||
const value = file.tab(path)
|
const value = file.tab(path)
|
||||||
tabs().open(value)
|
tabs().open(value)
|
||||||
file.load(path)
|
file.load(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user