fix(suggestion): keep a shown typo fix when only trailing spaces changed before accepting
The session ignores trailing whitespace but acceptance compared the raw prefix, so typing one more space after the fix appeared made accept drop the correction silently and leave the typo in place.
This commit is contained in:
parent
1b39afe9ff
commit
32cf826290
3 changed files with 45 additions and 1 deletions
|
|
@ -824,3 +824,23 @@ export function detectTypoRevert(currentPrefix: string, applied: { from: string;
|
|||
const tokens = tokenizeWords(window).map((token) => token.text)
|
||||
return tokens.includes(applied.from) && !tokens.includes(applied.to)
|
||||
}
|
||||
|
||||
/**
|
||||
* 표시된 교정을 수락 시점의 커서 앞 원문에 맞춘다. 맞출 수 없으면 null.
|
||||
*
|
||||
* 교정 구간(from)은 만들 때의 끝 공백을 그대로 담지만, 제안 세션은 끝 공백만 달라진 글을
|
||||
* 같은 세션으로 본다. 교정이 뜬 뒤 공백을 하나 더 치거나 지우면 from 이 원문 끝과 어긋나
|
||||
* 화면에 보이던 교정이 조용히 버려졌다 — 끝 공백을 빼고 비교하고, 지금의 끝 공백을 붙여 돌려준다.
|
||||
*/
|
||||
export function alignCorrectionToPrefix<T extends { from: string; to: string }>(
|
||||
prefix: string,
|
||||
correction: T
|
||||
): T | null {
|
||||
if (prefix.endsWith(correction.from)) return correction
|
||||
const fromCore = correction.from.trimEnd()
|
||||
const prefixCore = prefix.trimEnd()
|
||||
const trailing = prefix.slice(prefixCore.length)
|
||||
// 줄바꿈까지 지우고 다시 쓰는 건 앱마다 결과가 달라 위험하다.
|
||||
if (fromCore.length === 0 || /[\r\n]/u.test(trailing) || !prefixCore.endsWith(fromCore)) return null
|
||||
return { ...correction, from: fromCore + trailing, to: correction.to.trimEnd() + trailing }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue