슬래시 명령 로직 분리
This commit is contained in:
@@ -219,6 +219,47 @@ export const resolveSlashCommand = (query) => {
|
||||
return exact ?? matches[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* 미디어 선택 모달을 여는 슬래시 명령인지 확인한다.
|
||||
* @param {string} action - 명령 action
|
||||
* @returns {boolean} 미디어 명령 여부
|
||||
*/
|
||||
export const isMediaSlashAction = (action) => ['media-image', 'media-gallery', 'media-video', 'media-audio', 'media-file']
|
||||
.includes(String(action || ''))
|
||||
|
||||
/**
|
||||
* 라이브 모드 미디어 슬래시 명령 처리 중 지연 commit을 무시할지 확인한다.
|
||||
* @param {Object} options - 판별 옵션
|
||||
* @param {number|null} options.pendingInsertLine - 미디어 삽입 대기 줄
|
||||
* @param {number} options.startLine - commit 시작 줄
|
||||
* @param {string[]} options.replacementLines - commit 대체 줄
|
||||
* @returns {boolean} 무시 여부
|
||||
*/
|
||||
export const shouldIgnorePendingMediaSlashCommit = ({ pendingInsertLine, startLine, replacementLines }) => pendingInsertLine === startLine
|
||||
&& Array.isArray(replacementLines)
|
||||
&& replacementLines.length === 1
|
||||
&& Boolean(parseSlashInput(replacementLines[0]))
|
||||
|
||||
/**
|
||||
* 지정 줄에 마크다운 줄을 삽입하되, 해당 줄이 슬래시 명령이면 교체한다.
|
||||
* @param {string} markdown - 원본 마크다운
|
||||
* @param {number} lineIndex - 삽입 위치
|
||||
* @param {string[]} insertLines - 삽입 줄
|
||||
* @returns {string} 갱신된 마크다운
|
||||
*/
|
||||
export const insertMarkdownLinesAtSlashTarget = (markdown, lineIndex, insertLines) => {
|
||||
const sourceLines = String(markdown ?? '').split('\n')
|
||||
const safeLine = Math.max(0, Math.min(Number.isFinite(lineIndex) ? lineIndex : 0, sourceLines.length))
|
||||
const lines = Array.isArray(insertLines) ? insertLines : []
|
||||
const replaceCount = parseSlashInput(sourceLines[safeLine] ?? '') ? 1 : 0
|
||||
|
||||
return [
|
||||
...sourceLines.slice(0, safeLine),
|
||||
...lines,
|
||||
...sourceLines.slice(safeLine + replaceCount)
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
/**
|
||||
* 슬래시 명령 적용 후 포커스할 줄·커서 오프셋을 계산한다.
|
||||
* @param {number} startLine - 교체 시작 줄(0-based)
|
||||
|
||||
Reference in New Issue
Block a user