작성 패널 컨텍스트 갱신 정리

This commit is contained in:
2026-07-24 17:08:07 +09:00
parent 540255512c
commit 8abe130f8d
5 changed files with 23 additions and 6 deletions

View File

@@ -85,6 +85,8 @@ const previewRendererRef = ref(null)
const gutterRef = ref(null)
/** 커서가 있는 논리 줄(0-based, `\\n` 기준) */
const activeLogicalLineIndex = ref(0)
/** 소스 모드 입력 이벤트 직후 textarea의 최신 본문 값 */
const writeModeContextValue = ref(null)
/** textarea 자동 줄바꿈을 반영한 논리 줄별 표시 높이(px) */
const gutterLineHeights = ref([])
/** 라이브 모드에서 소스 모드로 돌아올 때 복원할 줄(0-based) */
@@ -189,6 +191,16 @@ const markdownValue = computed({
set: (value) => emit('update:modelValue', value)
})
watch(markdownValue, () => {
const textarea = textareaRef.value
if (activeMode.value !== 'write'
|| !textarea
|| import.meta.client && document.activeElement !== textarea) {
writeModeContextValue.value = null
}
})
/** textarea 포커스·블록 패널 상호작용 */
const isTextareaFocused = ref(false)
const isBlockPanelEngaged = ref(false)
@@ -391,7 +403,7 @@ const syncInlineColorSelectionContext = () => {
* @returns {Object|null}
*/
const activeBlockContext = computed(() => resolveActiveBlockContext(
markdownValue.value,
writeModeContextValue.value ?? markdownValue.value,
activeLogicalLineIndex.value
))
@@ -992,11 +1004,12 @@ const refreshCaretLogicalLine = () => {
return
}
const value = markdownValue.value ?? ''
const value = textarea.value ?? markdownValue.value ?? ''
const start = Math.min(textarea.selectionStart, value.length)
const end = Math.min(textarea.selectionEnd, value.length)
const lineIndex = value.slice(0, start).split('\n').length - 1
writeModeContextValue.value = value
lastSelectionState.value = {
start,
end