🐛 Fix focus after selecting mark in text editor

This commit is contained in:
Baptiste Arnaud
2023-03-21 18:26:39 +01:00
parent a41c65f528
commit 02d25d0fc7
6 changed files with 456 additions and 270 deletions

View File

@@ -38,6 +38,7 @@ const TextBubbleEditorContent = ({
const varDropdownRef = useRef<HTMLDivElement | null>(null)
const rememberedSelection = useRef<BaseSelection | null>(null)
const [isVariableDropdownOpen, setIsVariableDropdownOpen] = useState(false)
const [isFirstFocus, setIsFirstFocus] = useState(true)
const textEditorRef = useRef<HTMLDivElement>(null)
@@ -139,14 +140,16 @@ const TextBubbleEditorContent = ({
style: editorStyle(useColorModeValue('white', colors.gray[850])),
autoFocus: true,
onFocus: () => {
if (!isFirstFocus) return
if (editor.children.length === 0) return
selectEditor(editor, {
edge: 'end',
})
setIsFirstFocus(false)
},
'aria-label': 'Text editor',
onBlur: () => {
rememberedSelection.current = editor.selection
rememberedSelection.current = editor?.selection
},
onKeyDown: handleKeyDown,
onClick: () => {

View File

@@ -41,7 +41,7 @@ export const ItemNodesList = ({
const isDraggingOnCurrentBlock =
(draggedItem && mouseOverBlock?.id === block.id) ?? false
const showPlaceholders =
draggedItem !== undefined && block.items[0].type === draggedItem.type
draggedItem !== undefined && block.items.at(0)?.type === draggedItem.type
const isLastBlock =
isDefined(typebot) &&