From 84b891435cdc01f66f3079908d00303528d9f04a Mon Sep 17 00:00:00 2001 From: Sebastian Blask Date: Sun, 28 Mar 2021 01:25:11 +1300 Subject: [PATCH] Fix context menu selection when selectionStart/SelectionEnd are missing Fixes #55 --- content-scripts/insert-item.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content-scripts/insert-item.js b/content-scripts/insert-item.js index 8ddaf53..02c2ba3 100644 --- a/content-scripts/insert-item.js +++ b/content-scripts/insert-item.js @@ -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,