diff options
| author | supahgreg <supahgreg@users.noreply.github.com> | 2025-10-10 23:30:34 +0000 |
|---|---|---|
| committer | supahgreg <supahgreg@users.noreply.github.com> | 2025-10-10 23:30:34 +0000 |
| commit | bb08b0acd5dbdfba068fad5332ddf51b485fc477 (patch) | |
| tree | dd36e91e8d40aaa2efa170ab116bcc28466700d2 /js/App.js | |
| parent | b888fa10328219d4eb5bec3fd0c69fa859a8c43b (diff) | |
Improve 'App.getSelectedText()'.
This also drops 'String.prototype.stripTags', which is no longer used.
Diffstat (limited to 'js/App.js')
| -rw-r--r-- | js/App.js | 21 |
1 files changed, 2 insertions, 19 deletions
@@ -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) { |