feat(desktop): propose typo fixes inside the suggestion popup and make suggestions snappier
While suggestions are on, typos are no longer replaced silently. The popup shows the fix next to the candidate and applies it only when the candidate is accepted. The per-minute request cap rises from 6 to 20 so suggestions keep appearing after accepting one and continuing to type.
This commit is contained in:
parent
d63854db67
commit
f5ae4c8c04
38 changed files with 1239 additions and 660 deletions
|
|
@ -35,6 +35,8 @@
|
|||
var provenance = null
|
||||
var i18nStrings = {}
|
||||
var keyHints = null
|
||||
/** 후보와 함께 적용되는 오타 교정 { from, to, edits:[{start,end,to}] } */
|
||||
var correction = null
|
||||
var generatingSince = 0
|
||||
var tickTimer = null
|
||||
|
||||
|
|
@ -70,6 +72,8 @@
|
|||
return
|
||||
}
|
||||
|
||||
if (correction) candidatesContainer.appendChild(buildCorrectionRow(correction))
|
||||
|
||||
var page = Math.floor(activeIndex / PAGE_SIZE)
|
||||
var pageStart = page * PAGE_SIZE
|
||||
var pageEnd = Math.min(pageStart + PAGE_SIZE, candidates.length)
|
||||
|
|
@ -105,9 +109,45 @@
|
|||
body.textContent = text
|
||||
item.appendChild(num)
|
||||
item.appendChild(body)
|
||||
// 교정이 있으면 후보 앞에 고친 글 끝부분을 강조해 붙인다 — "이렇게 고친 뒤 이어진다" 를 보여 준다.
|
||||
if (correction && tag === 'button') {
|
||||
var lead = document.createElement('span')
|
||||
lead.className = 'corrected'
|
||||
var tail = correction.to.replace(/\s+$/, '')
|
||||
lead.textContent = (tail.length > 18 ? '…' + tail.slice(-18) : tail) + ' '
|
||||
body.insertBefore(lead, body.firstChild)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
/** "고침 | 지운 글자 → 고친 글자" 한 줄 — 바뀐 단어만 보여 준다. */
|
||||
function buildCorrectionRow(value) {
|
||||
var row = document.createElement('div')
|
||||
row.className = 'correction'
|
||||
var label = document.createElement('span')
|
||||
label.className = 'correction-label'
|
||||
label.textContent = i18nStrings.suggestionCorrectionLabel || ''
|
||||
row.appendChild(label)
|
||||
var diff = document.createElement('span')
|
||||
diff.className = 'correction-diff'
|
||||
var edits = value.edits && value.edits.length ? value.edits : [{ start: 0, end: value.from.length, to: value.to }]
|
||||
for (var i = 0; i < edits.length; i++) {
|
||||
if (i > 0) diff.appendChild(document.createTextNode(', '))
|
||||
var removed = document.createElement('del')
|
||||
removed.textContent = value.from.slice(edits[i].start, edits[i].end).trim() || '␣'
|
||||
var arrow = document.createElement('span')
|
||||
arrow.className = 'correction-arrow'
|
||||
arrow.textContent = '→'
|
||||
var added = document.createElement('ins')
|
||||
added.textContent = edits[i].to || '∅'
|
||||
diff.appendChild(removed)
|
||||
diff.appendChild(arrow)
|
||||
diff.appendChild(added)
|
||||
}
|
||||
row.appendChild(diff)
|
||||
return row
|
||||
}
|
||||
|
||||
function renderProgress() {
|
||||
if (!progressContainer) return
|
||||
progressContainer.textContent = ''
|
||||
|
|
@ -211,6 +251,7 @@
|
|||
if (payload.warmingUp !== undefined) warmingUp = payload.warmingUp === true
|
||||
if (payload.partialText !== undefined) partialText = payload.partialText || null
|
||||
if (payload.provenance !== undefined) provenance = payload.provenance || null
|
||||
if (payload.correction !== undefined) correction = payload.correction || null
|
||||
}
|
||||
|
||||
function startTick() {
|
||||
|
|
@ -254,6 +295,7 @@
|
|||
warmingUp = false
|
||||
partialText = null
|
||||
provenance = null
|
||||
correction = null
|
||||
candidates = []
|
||||
activeIndex = 0
|
||||
targetTotal = 0
|
||||
|
|
|
|||
|
|
@ -299,3 +299,55 @@ kbd {
|
|||
line-height: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* ── 오타 교정 (후보와 함께 적용된다) — 지운 글자는 취소선, 고친 글자는 강조. 높이 26px 고정 ── */
|
||||
.correction {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
height: 26px;
|
||||
margin-bottom: 2px;
|
||||
padding: 0 28px 0 8px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
font-size: 12px;
|
||||
color: var(--d3-text-secondary);
|
||||
}
|
||||
|
||||
.correction-label {
|
||||
flex: 0 0 auto;
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
background: var(--d3-accent-dim);
|
||||
color: var(--d3-accent-main);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.correction-diff {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.correction del {
|
||||
color: var(--d3-status-danger);
|
||||
text-decoration: line-through;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.correction ins {
|
||||
color: var(--d3-accent-main);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.correction-arrow {
|
||||
margin: 0 3px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
/* 후보 앞에 붙는 고친 글 — 이 글자들로 바뀐 뒤 후보가 이어진다는 표시 */
|
||||
.suggestion-text .corrected {
|
||||
color: var(--d3-accent-main);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue