Fixed rename bug

pull/1575/head
ioedeveloper 3 years ago
parent 4ba2237822
commit 4b6f928287
  1. 9
      libs/remix-ui/workspace/src/lib/components/file-label.tsx
  2. 2
      libs/remix-ui/workspace/src/lib/utils/index.ts

@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import React, { useEffect, useRef } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { FileType } from '../types' import { FileType } from '../types'
export interface FileLabelProps { export interface FileLabelProps {
@ -17,6 +17,7 @@ export const FileLabel = (props: FileLabelProps) => {
const { file, focusEdit, editModeOff } = props const { file, focusEdit, editModeOff } = props
const isEditable = focusEdit.element === file.path const isEditable = focusEdit.element === file.path
const labelRef = useRef(null) const labelRef = useRef(null)
const [defaultValue, setDefaultValue] = useState<string>(null)
useEffect(() => { useEffect(() => {
if (isEditable) { if (isEditable) {
@ -26,16 +27,22 @@ export const FileLabel = (props: FileLabelProps) => {
} }
}, [isEditable]) }, [isEditable])
useEffect(() => {
setDefaultValue(labelRef.current.innerText)
}, [labelRef.current])
const handleEditInput = (event: React.KeyboardEvent<HTMLDivElement>) => { const handleEditInput = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.which === 13) { if (event.which === 13) {
event.preventDefault() event.preventDefault()
editModeOff(labelRef.current.innerText) editModeOff(labelRef.current.innerText)
labelRef.current.innerText = defaultValue
} }
} }
const handleEditBlur = (event: React.SyntheticEvent) => { const handleEditBlur = (event: React.SyntheticEvent) => {
event.stopPropagation() event.stopPropagation()
editModeOff(labelRef.current.innerText) editModeOff(labelRef.current.innerText)
labelRef.current.innerText = defaultValue
} }
return ( return (

@ -1,3 +1,5 @@
import { MenuItems } from '../types'
export const contextMenuActions: MenuItems = [{ export const contextMenuActions: MenuItems = [{
id: 'newFile', id: 'newFile',
name: 'New File', name: 'New File',

Loading…
Cancel
Save