Commit 4bdddefb authored by ioedeveloper's avatar ioedeveloper

Fixed new input field focus

parent 7c5ad393
...@@ -15,12 +15,18 @@ export interface FileLabelProps { ...@@ -15,12 +15,18 @@ export interface FileLabelProps {
export const FileLabel = (props: FileLabelProps) => { export const FileLabel = (props: FileLabelProps) => {
const { file, focusEdit, editModeOff } = props const { file, focusEdit, editModeOff } = props
const isEditable = focusEdit.element === file.path const [isEditable, setIsEditable] = useState<boolean>(false)
const labelRef = useRef(null) const labelRef = useRef(null)
const [defaultValue, setDefaultValue] = useState<string>(null) const [defaultValue, setDefaultValue] = useState<string>(null)
useEffect(() => { useEffect(() => {
if (isEditable) { if (focusEdit.element && file.path) {
setIsEditable(focusEdit.element === file.path)
}
}, [file.path, focusEdit])
useEffect(() => {
if (labelRef.current) {
setTimeout(() => { setTimeout(() => {
labelRef.current.focus() labelRef.current.focus()
}, 0) }, 0)
...@@ -28,7 +34,7 @@ export const FileLabel = (props: FileLabelProps) => { ...@@ -28,7 +34,7 @@ export const FileLabel = (props: FileLabelProps) => {
}, [isEditable]) }, [isEditable])
useEffect(() => { useEffect(() => {
setDefaultValue(labelRef.current.innerText) if (labelRef.current) setDefaultValue(labelRef.current.innerText)
}, [labelRef.current]) }, [labelRef.current])
const handleEditInput = (event: React.KeyboardEvent<HTMLDivElement>) => { const handleEditInput = (event: React.KeyboardEvent<HTMLDivElement>) => {
...@@ -48,7 +54,7 @@ export const FileLabel = (props: FileLabelProps) => { ...@@ -48,7 +54,7 @@ export const FileLabel = (props: FileLabelProps) => {
return ( return (
<div <div
className='remixui_items d-inline-block w-100' className='remixui_items d-inline-block w-100'
ref={labelRef} ref={isEditable ? labelRef : null}
suppressContentEditableWarning={true} suppressContentEditableWarning={true}
contentEditable={isEditable} contentEditable={isEditable}
onKeyDown={handleEditInput} onKeyDown={handleEditInput}
......
...@@ -21,6 +21,7 @@ export function Workspace () { ...@@ -21,6 +21,7 @@ export function Workspace () {
useEffect(() => { useEffect(() => {
global.dispatchInitWorkspace() global.dispatchInitWorkspace()
resetFocus()
}, []) }, [])
useEffect(() => { useEffect(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment