From 4f72968c1279016289b3d8e2e58dd1efb62f85ff Mon Sep 17 00:00:00 2001 From: josc146 Date: Mon, 27 Mar 2023 23:29:27 +0800 Subject: [PATCH] fix: selection tools window pops up when selecting blank content (#104) --- src/content-script/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content-script/index.jsx b/src/content-script/index.jsx index b440b1f..ed6cd14 100644 --- a/src/content-script/index.jsx +++ b/src/content-script/index.jsx @@ -126,7 +126,7 @@ async function prepareForSelectionTools() { deleteToolbar() setTimeout(() => { - const selection = window.getSelection()?.toString() + const selection = window.getSelection()?.toString().trim() if (selection) { const inputElement = selectionElement.querySelector('input, textarea') let position @@ -165,7 +165,7 @@ async function prepareForSelectionTools() { (e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA') ) { setTimeout(() => { - if (!window.getSelection()?.toString()) deleteToolbar() + if (!window.getSelection()?.toString().trim()) deleteToolbar() }) } }) @@ -183,7 +183,7 @@ async function prepareForSelectionToolsTouch() { deleteToolbar() setTimeout(() => { - const selection = window.getSelection()?.toString() + const selection = window.getSelection()?.toString().trim() if (selection) { toolbarContainer = createElementAtPosition( e.changedTouches[0].pageX + 20,