From da97b29dbe7ac923fae5a0cddee141716d1da3e5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 21:07:28 +0300 Subject: prevent filter selected text dialog from opening in wrong order --- js/App.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'js/App.js') diff --git a/js/App.js b/js/App.js index 2041a6168..68f3740c5 100644 --- a/js/App.js +++ b/js/App.js @@ -358,6 +358,27 @@ const App = { return p; } }, + // 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(); + }, displayIfChecked: function(checkbox, elemId) { if (checkbox.checked) { Element.show(elemId); -- cgit v1.2.3