Skip to content

Commit

Permalink
[#134] fix: focus 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
domino8788 committed Dec 17, 2020
1 parent 5ef7998 commit 9bf703c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/src/components/atoms/BlockContent/BlockContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ function BlockContent(blockDTO: Block) {
const listCnt = useRef(1);
const [Dispatcher] = useCommand();
const [
{ blockIndex, prevSiblings },
{ blockIndex, prevSiblings, blockMap },
{
commitTransaction,
startTransaction,
setBlock,
setCaretOffset,
deleteBlock,
setFocus,
},
] = useManager(blockDTO.id);
const draggingBlock = useRecoilValue(draggingBlockState);
Expand Down Expand Up @@ -125,14 +126,15 @@ function BlockContent(blockDTO: Block) {
startTransaction();
setBlock(blockDTO.id, { value, type: type || blockDTO.type });
contentEditableRef.current.blur();
setTimeout(() =>
setCaretOffset(caretOffset === -1 ? focusOffset : caretOffset),
);
setImmediate(() => {
setCaretOffset(caretOffset === -1 ? focusOffset : caretOffset);
setFocus(blockDTO);
});
commitTransaction();
};

const handleValue = () => {
const content = contentEditableRef.current.textContent;
const content = contentEditableRef.current?.textContent ?? '';

let nowLetterIdx = window.getSelection().focusOffset;
if (!nowLetterIdx) nowLetterIdx += 1;
Expand Down Expand Up @@ -175,7 +177,7 @@ function BlockContent(blockDTO: Block) {
}
handleBlock(content);
};
const updateValue = useRef(debounce(handleValue, 300)).current;
const updateValue = debounce(handleValue, 30);

const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
const { focusNode, focusOffset } = window.getSelection();
Expand Down

0 comments on commit 9bf703c

Please sign in to comment.