From bb08b0acd5dbdfba068fad5332ddf51b485fc477 Mon Sep 17 00:00:00 2001 From: supahgreg Date: Fri, 10 Oct 2025 23:30:34 +0000 Subject: Improve 'App.getSelectedText()'. This also drops 'String.prototype.stripTags', which is no longer used. --- js/App.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'js/App.js') diff --git a/js/App.js b/js/App.js index 5df313491..33bd81d9a 100644 --- a/js/App.js +++ b/js/App.js @@ -441,26 +441,9 @@ const App = { } }); }, - // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac getSelectedText: function() { - let text = ""; - - if (typeof window.getSelection != "undefined") { - const sel = window.getSelection(); - if (sel.rangeCount) { - const container = document.createElement("div"); - for (let i = 0, len = sel.rangeCount; i < len; ++i) { - container.appendChild(sel.getRangeAt(i).cloneContents()); - } - text = container.innerHTML; - } - } else if (typeof document.selection != "undefined") { - if (document.selection.type == "Text") { - text = document.selection.createRange().textText; - } - } - - return text.stripTags(); + const sel = window.getSelection(); + return sel ? sel.toString().trim() : ""; }, displayIfChecked: function(checkbox, elemId) { if (checkbox.checked) { -- cgit v1.2.3-54-g00ecf