fix: restore input binding selection position (#14649)

pull/14656/head
Dominic Gannaway 2 weeks ago committed by GitHub
parent 8bee23e387
commit 9cfd2e20ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: restore input binding selection position

@ -30,8 +30,17 @@ export function bind_value(input, get, set = get) {
// In runes mode, respect any validation in accessors (doesn't apply in legacy mode,
// because we use mutable state which ensures the render effect always runs)
if (runes && value !== (value = get())) {
var start = input.selectionStart;
var end = input.selectionEnd;
// the value is coerced on assignment
input.value = value ?? '';
// Restore selection
if (end !== null) {
input.selectionStart = start;
input.selectionEnd = Math.min(end, input.value.length);
}
}
});

Loading…
Cancel
Save