Skip to content

Commit

Permalink
fix edit
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlashAccount committed Mar 22, 2024
1 parent 0adc035 commit 4f41db0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/ide-desktop/lib/dashboard/src/components/EditableSpan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as React from 'react'
import CrossIcon from 'enso-assets/cross.svg'
import TickIcon from 'enso-assets/tick.svg'

import * as eventCalback from '#/hooks/eventCallbackHooks'

import * as inputBindingsProvider from '#/providers/InputBindingsProvider'

import SvgMask from '#/components/SvgMask'
Expand Down Expand Up @@ -38,6 +40,10 @@ export default function EditableSpan(props: EditableSpanProps) {
const inputRef = React.useRef<HTMLInputElement>(null)
const cancelled = React.useRef(false)

// Making sure that the event callback is stable.
// to prevent the effect from re-running.
const onCancelEventCallback = eventCalback.useEventCallback(onCancel)

React.useEffect(() => {
setIsSubmittable(checkSubmittable?.(inputRef.current?.value ?? '') ?? true)
// This effect MUST only run on mount.
Expand All @@ -48,15 +54,15 @@ export default function EditableSpan(props: EditableSpanProps) {
if (editable) {
return inputBindings.attach(sanitizedEventTargets.document.body, 'keydown', {
cancelEditName: () => {
onCancel()
onCancelEventCallback()
cancelled.current = true
inputRef.current?.blur()
},
})
} else {
return
}
}, [editable, onCancel, /* should never change */ inputBindings])
}, [editable, /* should never change */ inputBindings, onCancelEventCallback])

React.useEffect(() => {
cancelled.current = false
Expand Down
1 change: 1 addition & 0 deletions app/ide-desktop/lib/dashboard/src/layouts/AssetsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ export default function AssetsTable(props: AssetsTableProps) {
break
}
case 'Escape': {
console.log(' const onKeyDown = (event: KeyboardEvent)')
setSelectedKeys(new Set())
setMostRecentlySelectedIndex(null)
selectionStartIndexRef.current = null
Expand Down

0 comments on commit 4f41db0

Please sign in to comment.