From 3d11c58b33c94336755f4bc69570247b2d32c0c3 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 18 Mar 2023 16:27:12 +0200 Subject: [PATCH] use DrT's code for files --- files/assets/js/core.js | 20 +++++++++++++++++++- files/assets/js/emoji_modal.js | 26 +------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 68d9ea5e4..181ee30ba 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -422,6 +422,24 @@ function focusSearchBar(element) +function insertText(input, text) { + const newPos = input.selectionStart + text.length; + input.setRangeText(text); + + if (window.chrome !== undefined) + setTimeout(function(){ + input.focus(); + for(let i = 0; i < 2; i++) + input.setSelectionRange(newPos, newPos); + + input.focus(); + for(let i = 0; i < 2; i++) + input.setSelectionRange(newPos, newPos); + }, 1); + else + input.setSelectionRange(newPos, newPos); +} + //FILE SHIT @@ -468,7 +486,7 @@ function handle_files(input, newfiles) { if (span.innerHTML != ' ') span.innerHTML += ', ' span.innerHTML += file.name.substr(0, 30); if (location.pathname != '/chat') - ta.setRangeText(`[${file.name}]`); + insertText(ta, `[${file.name}]`); } autoExpand(ta) diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index e5127a0ac..daf2bc7f9 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -285,31 +285,7 @@ function emojiAddToInput(event) strToInsert = emojiSelectSuffixDOMs[i].value + strToInsert; strToInsert = ":" + strToInsert + ":" - const newPos = emojiInputTargetDOM.selectionStart + strToInsert.length; - - emojiInputTargetDOM.setRangeText(strToInsert); - - const emojiInsertedEvent = new CustomEvent("emojiInserted", { detail: { emoji: strToInsert } }); - document.dispatchEvent(emojiInsertedEvent); - - // Sir, come out and drink your Chromium complaint web - // I HATE CHROME. I HATE CHROME - if(window.chrome !== undefined) - setTimeout(function(){ - console.warn("Chrome detected, r-slured mode enabled."); - - // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - // JUST WORK STUPID CHROME PIECE OF SHIT - emojiInputTargetDOM.focus(); - for(let i = 0; i < 2; i++) - emojiInputTargetDOM.setSelectionRange(newPos, newPos); - - emojiInputTargetDOM.focus(); - for(let i = 0; i < 2; i++) - emojiInputTargetDOM.setSelectionRange(newPos, newPos); - }, 1); - else - emojiInputTargetDOM.setSelectionRange(newPos, newPos); + insertText(emojiInputTargetDOM, strToInsert) // kick-start the preview emojiInputTargetDOM.dispatchEvent(new Event('input'));