Skip to content

Commit

Permalink
Fix textarea undo history cleared by editAttention (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered authored Aug 26, 2024
1 parent a5cdebe commit f9ae5aa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/extensions/core/editAttention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ app.registerExtension({
}
}

function editAttention(event) {
const inputField = event.composedPath()[0]
function editAttention(event: KeyboardEvent) {
// @ts-expect-error Runtime narrowing not impl.
const inputField: HTMLTextAreaElement = event.composedPath()[0]
const delta = parseFloat(editAttentionDelta.value)

if (inputField.tagName !== 'TEXTAREA') return
Expand Down Expand Up @@ -153,7 +154,10 @@ app.registerExtension({
}
)

inputField.setRangeText(updatedText, start, end, 'select')
inputField.setSelectionRange(start, end)
// Intentional use of deprecated: https://developer.mozilla.org/docs/Web/API/Document/execCommand#using_inserttext
document.execCommand('insertText', false, updatedText)
inputField.setSelectionRange(start, start + updatedText.length)
}
window.addEventListener('keydown', editAttention)
}
Expand Down

0 comments on commit f9ae5aa

Please sign in to comment.