슬래시 명령 커서 복원 계산 분리
This commit is contained in:
@@ -279,3 +279,25 @@ export const getSlashCommandFocusTarget = (startLine, lines) => {
|
||||
|
||||
return { line: safeStart + 1, offset: 0 }
|
||||
}
|
||||
|
||||
/**
|
||||
* 슬래시 명령 적용 후 textarea 선택 위치를 계산한다.
|
||||
* @param {Object} options - 계산 옵션
|
||||
* @param {string} options.markdown - 현재 마크다운
|
||||
* @param {number} options.startLine - 교체 시작 줄(0-based)
|
||||
* @param {string[]} options.lines - 삽입 줄
|
||||
* @returns {{ start: number, end: number }} 선택 범위
|
||||
*/
|
||||
export const getSlashCommandTextareaSelection = ({ markdown, startLine, lines }) => {
|
||||
const sourceLines = String(markdown ?? '').split('\n')
|
||||
const safeStart = Math.max(0, Math.min(Number.isFinite(startLine) ? startLine : 0, sourceLines.length))
|
||||
const { line, offset } = getSlashCommandFocusTarget(safeStart, lines)
|
||||
const safeLine = Math.max(0, Math.min(line, sourceLines.length))
|
||||
const lineStart = sourceLines.slice(0, safeLine).join('\n').length + (safeLine > 0 ? 1 : 0)
|
||||
const selection = lineStart + offset
|
||||
|
||||
return {
|
||||
start: selection,
|
||||
end: selection
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user