Skip to content

Commit

Permalink
Fix context menu selection when selectionStart/SelectionEnd are missing
Browse files Browse the repository at this point in the history
Fixes #55
  • Loading branch information
sblask committed Mar 27, 2021
1 parent 879bde7 commit 84b8914
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions content-scripts/insert-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ function insertItemListener(message) {
}

function insertItem(node, item) {
if (node.selectionStart == undefined || node.selectionEnd == undefined) {
return;
}
// some pages seem to override/reset selectionStart/selectionEnd
const selectionStart = node.selectionStart || 0;
const selectionEnd = node.selectionEnd || node.value.length;

const beforeCursorOrSelection = node.value.slice(0, node.selectionStart);
const afterCursorOrSelection = node.value.slice(node.selectionEnd, node.value.length);
const beforeCursorOrSelection = node.value.slice(0, selectionStart);
const afterCursorOrSelection = node.value.slice(selectionEnd, node.value.length);
node.value = beforeCursorOrSelection + item + afterCursorOrSelection;
const detail = {
simpleFormFillCustomInputEvent: true,
Expand Down

0 comments on commit 84b8914

Please sign in to comment.