mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: update focus properly
This commit is contained in:
parent
453ed1d588
commit
d683777c34
3 changed files with 10 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ import * as React from 'react'
|
|||
import { useEvent } from 'react-use'
|
||||
import { FixedSizeList, ListChildComponentProps } from 'react-window'
|
||||
import { cx } from 'utils/cx'
|
||||
import { focusFileExplorer } from 'utils/DOMHelper'
|
||||
import { isValidRegexpSource } from 'utils/general'
|
||||
import { useOnLocationChange } from 'utils/hooks/useOnLocationChange'
|
||||
import { VisibleNodes } from 'utils/VisibleNodesGenerator'
|
||||
|
|
@ -37,6 +38,10 @@ const RawFileExplorer: React.FC<Props & ConnectorState> = function RawFileExplor
|
|||
setUpTree({ treeRoot, metaData, config })
|
||||
}, [setUpTree, treeRoot, config.compressSingletonFolder, config.access_token])
|
||||
|
||||
React.useEffect(() => {
|
||||
if (visibleNodes?.focusedNode) focusFileExplorer()
|
||||
})
|
||||
|
||||
function renderFiles(visibleNodes: VisibleNodes) {
|
||||
const inSearch = searchKey !== ''
|
||||
const { nodes } = visibleNodes
|
||||
|
|
@ -172,10 +177,10 @@ function ListView({
|
|||
const { focusedNode, nodes } = visibleNodes
|
||||
React.useEffect(() => {
|
||||
if (listRef.current && focusedNode) {
|
||||
const index = nodes.indexOf(focusedNode)
|
||||
const index = nodes.findIndex(node => node.path === focusedNode.path)
|
||||
if (index !== -1) {
|
||||
listRef.current.scrollToItem(index, 'smart')
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [focusedNode])
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export type ConnectorState = {
|
|||
}
|
||||
|
||||
function getVisibleParentNode(nodes: TreeNode[], focusedNode: TreeNode) {
|
||||
let index = nodes.indexOf(focusedNode) - 1
|
||||
let index = nodes.findIndex(node => node.path === focusedNode.path) - 1
|
||||
while (index >= 0) {
|
||||
if (nodes[index].contents?.includes(focusedNode)) {
|
||||
return nodes[index]
|
||||
|
|
@ -93,7 +93,7 @@ export const handleKeyDown: BoundMethodCreator<[React.KeyboardEvent]> = dispatch
|
|||
// prevent document body scrolling if the keypress results in Gitako action
|
||||
let muteEvent = true
|
||||
if (focusedNode) {
|
||||
const focusedNodeIndex = nodes.indexOf(focusedNode)
|
||||
const focusedNodeIndex = nodes.findIndex(node => node.path === focusedNode.path)
|
||||
switch (key) {
|
||||
case 'ArrowUp':
|
||||
// focus on previous node
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ class FlattenLayer extends CompressLayer {
|
|||
if (
|
||||
focusedNode &&
|
||||
this.compressedRoot &&
|
||||
(await findNode(this.compressedRoot, focusedNode.path)) !== focusedNode
|
||||
!(await findNode(this.compressedRoot, focusedNode.path))
|
||||
) {
|
||||
// rescue the focus after expanding async singleton folder
|
||||
await traverse(
|
||||
|
|
|
|||
Loading…
Reference in a new issue