MCPcopy
hub / github.com/philc/vimium / setTextInInputElement

Function setTextInInputElement

pages/hud_page.js:17–27  ·  view source on GitHub ↗
(inputEl, text)

Source from the content-addressed store, hash-verified

15
16// Set the input element's text, and move the cursor to the end.
17function setTextInInputElement(inputEl, text) {
18 inputEl.textContent = text;
19 // Move the cursor to the end. Based on one of the solutions here:
20 // http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity
21 const range = document.createRange();
22 range.selectNodeContents(inputEl);
23 range.collapse(false);
24 const selection = globalThis.getSelection();
25 selection.removeAllRanges();
26 selection.addRange(range);
27}
28
29export function onKeyEvent(event) {
30 // Handle <Enter> on "keypress", and other events on "keydown"; this avoids interence with CJK

Callers 1

onKeyEventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected