keep cursor at edit position while typing in the middle

This commit is contained in:
Martin Raifer
2023-05-26 17:59:04 +02:00
parent a18de6b5c3
commit 14c752548d
2 changed files with 12 additions and 2 deletions
+10 -2
View File
@@ -2,7 +2,7 @@
// which can result in layout/repaint thrashing in some situations.
/** @returns {string} */
export function utilGetSetValue(selection, value) {
function d3_selection_value(value) {
function setValue(value) {
function valueNull() {
delete this.value;
}
@@ -27,9 +27,17 @@ export function utilGetSetValue(selection, value) {
? valueFunction : valueConstant);
}
function stickyCursor(func) {
return function() {
const cursor = { start: this.selectionStart, end: this.selectionEnd };
func.apply(this, arguments);
this.setSelectionRange(cursor.start, cursor.end);
}
}
if (arguments.length === 1) {
return selection.property('value');
}
return selection.each(d3_selection_value(value));
return selection.each(stickyCursor(setValue(value)));
}