| Summary: | Keyboard autocorrect (spellcheck) buffer is not reset when clearing text field value | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Teodor <teodor.atroshenko> |
| Component: | HTML Editing | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW --- | ||
| Severity: | Major | CC: | ap, maxime.decaix, megan_gardner, teodor.atroshenko, webkit-bug-importer, wenson_hsieh |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 15 | ||
| Hardware: | iPhone / iPad | ||
| OS: | iOS 15 | ||
| See Also: |
https://bugs.webkit.org/show_bug.cgi?id=225092 https://bugs.webkit.org/show_bug.cgi?id=48411 https://bugs.webkit.org/show_bug.cgi?id=139473 |
||
|
Description
Teodor
2022-02-20 01:45:25 PST
I found a workaround. This one is specific to Quill, but I've encountered this issue with different libraries and without them, so minor changes would be needed to apply this to anything else but Quill.
```html
<input id="flick-target" type="text" tabindex="-1" />
<quill-element /> <!-- Insert it however you are used to -->
```
```css
.flick-target {
display: block;
width: 0;
height: 0;
opacity: 0;
border: 0;
padding: 0;
margin: 0;
}
```
```js
if (platform.is.ios) { // Use your favorite way of checking if the device is running your favorite mobile OS
quill.on('text-change', (delta, previousDelta) => {
if (isEmpty(delta)) { // Use your favorite way of checking if supplied Delta/Text is empty
flickFocus()
} else if (isNewLine(delta, previousDelta)) { // Use your favorite way of checking is new line was *just entered*
flickFocus(quill.getSelection())
}
})
}
function flickFocus(selectionTarget) {
$('#flick-target').focus()
quill.root.style.opacity = 0 // Make contentEditable element transparent - prevents page flicker when refocusing
requestAnimationFrame(() => {
quill.root.focus() // Return focus back to Quill contentEditable
if (selectionTarget) {
quill.setSelection(selectionTarget)
}
setTimeout(() => {
quill.root.style.opacity = 1 // Restore visibility on next frame (may take up to 2 frames = 32ms)
})
})
}
function isEmpty(delta) { // Tweak this as you see fit
return delta.ops.length === 1 && delta.ops[0].insert == '\n'
}
function isNewLine(delta, previousDelta) { // Tweak this as you see fit
return delta.ops.length > previousDelta.ops.length
}
```
Instead of checking for new line entry you can also listen for Enter `keydown` event (`e.key === 'Enter' || e.keyCode === 13`).
|