오늘의 목표

수행 내역

// finding cursor position for modal
    const getCursorPosition = () => {
        const scrollOffset = scrollTopRef.current;
        const textarea = markdownRef.current;
        const mirror = mirrorRef.current;
        const start = textarea.selectionStart;

        // Get the text content before the cursor
        const textBeforeCursor = textarea.value.substring(0, start);

        // Update the mirror content to match the textarea's
        mirror.textContent = textBeforeCursor;

        // Create a temporary span to represent the cursor and measure its position
        const cursorSpan = document.createElement('span');
        cursorSpan.textContent = '|'; // A single character to measure position
        mirror.appendChild(cursorSpan);

        // Get the position of the cursor span relative to the viewport
        const cursorRect = cursorSpan.getBoundingClientRect();
        const textareaRect = textarea.getBoundingClientRect();

        // Calculate final position relative to the textarea wrapper
        const top = cursorRect.top - textareaRect.top + textarea.offsetTop - scrollOffset;
        const left = cursorRect.left - textareaRect.left + textarea.offsetLeft;

        // Clean up the mirror
        setModalPosition({ top: top, left: left });

        mirror.textContent = '';
    };

문제 및 이슈

const recoverScrollTop = () => {
        if (markdownRef.current) {
            markdownRef.current.scrollTop = scrollTopRef.current;
        }
    };

참고자료

지원요청