Files
devplacepy/devplacepy/static/js/TextInput.js
T
retoor c01dff4c00
DevPlace CI / test (push) Has been cancelled
Done
2026-05-23 08:41:47 +02:00

18 lines
595 B
JavaScript

export class TextInput {
static applyValue(element, value, caretPos) {
element.value = value;
element.setSelectionRange(caretPos, caretPos);
element.focus();
element.dispatchEvent(new Event("input", { bubbles: true }));
}
static insertAtCursor(element, text) {
const start = element.selectionStart;
const end = element.selectionEnd;
const value = element.value.substring(0, start) + text + element.value.substring(end);
TextInput.applyValue(element, value, start + text.length);
}
}
window.TextInput = TextInput;