게시물 라이브 편집 블록 동작 개선
This commit is contained in:
@@ -653,6 +653,43 @@ const buildInsertBelowPayload = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 편집 영역의 현재 선택 텍스트를 링크 마크다운으로 바꾼다.
|
||||
* @returns {void}
|
||||
*/
|
||||
const insertMarkdownLinkAtSelection = () => {
|
||||
if (!import.meta.client || !rootRef.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const selection = window.getSelection()
|
||||
|
||||
if (!selection || selection.rangeCount === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const range = selection.getRangeAt(0)
|
||||
|
||||
if (!rootRef.value.contains(range.commonAncestorContainer)) {
|
||||
return
|
||||
}
|
||||
|
||||
const selectedText = selection.toString() || '링크 텍스트'
|
||||
const markdown = `[${selectedText}](https://)`
|
||||
|
||||
document.execCommand('insertText', false, markdown)
|
||||
syncSlashState()
|
||||
|
||||
nextTick(() => {
|
||||
if (!rootRef.value) {
|
||||
return
|
||||
}
|
||||
|
||||
emit('input', readEditorValue())
|
||||
emit('commit', readEditorValue())
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 커서 위치에서 문단을 분리한다.
|
||||
* @returns {void}
|
||||
@@ -792,6 +829,13 @@ const onKeydown = (event) => {
|
||||
return
|
||||
}
|
||||
|
||||
if ((event.metaKey || event.ctrlKey) && !event.shiftKey && event.key.toLowerCase() === 'k') {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
insertMarkdownLinkAtSelection()
|
||||
return
|
||||
}
|
||||
|
||||
if ((event.metaKey || event.ctrlKey) && event.shiftKey && event.key.toLowerCase() === 'k') {
|
||||
if (props.sourceLine !== null) {
|
||||
const lineContext = getCaretLineContext()
|
||||
|
||||
Reference in New Issue
Block a user