From dd0dc21db5aaf5e4e298d145e675614559083e2a Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 13:54:13 +0100 Subject: [PATCH 1/6] Fix replacement of sent URLs with actual links (fixes #231) --- public/scripts/ui.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index ae63a0e..9cf0b3b 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -2014,10 +2014,19 @@ class ReceiveTextDialog extends Dialog { // Beautify text if text is short if (text.length < 2000) { - // replace urls with actual links - this.$text.innerHTML = this.$text.innerHTML.replace(/((https?:\/\/|www)[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-._~:\/?#\[\]@!$&'()*+,;=]+)/g, url => { - return `${url}`; - }); + // replace URLs with actual links + this.$text.innerHTML = this.$text.innerHTML + .replace(/(^|(?<=(
|\s)))(https?:\/\/|www.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%]){2,}\.)(([a-z]|[A-Z]|[0-9]|[\-_~:\/?#\[\]@!$&'()*+,;=%.]){2,})/g, + (url) => { + let link = url; + + // prefix www.example.com with http protocol to prevent it from being a relative link + if (link.startsWith('www')) { + link = "http://" + link + } + + return `${url}`; + }); } this._evaluateOverflowing(this.$text); @@ -2048,6 +2057,7 @@ class ReceiveTextDialog extends Dialog { } hide() { + // Todo: clear text field super.hide(); setTimeout(() => this._dequeueRequests(), 500); } From 676c68b6e7bbe5ce71e999941150761ec454007c Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 16:52:26 +0100 Subject: [PATCH 2/6] Clear text field when closing receive text dialog --- public/scripts/ui.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 9cf0b3b..ffef7ee 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -2057,9 +2057,11 @@ class ReceiveTextDialog extends Dialog { } hide() { - // Todo: clear text field super.hide(); - setTimeout(() => this._dequeueRequests(), 500); + setTimeout(() => { + this._dequeueRequests(); + this.$text.innerHTML = ""; + }, 500); } } From d58f38056574a60ba4eb77ce898792293242fbb6 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 16:53:09 +0100 Subject: [PATCH 3/6] Prevent executing _onCopy() when text is selected on receive text dialog --- public/scripts/ui.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index ffef7ee..1917eb8 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -1978,12 +1978,15 @@ class ReceiveTextDialog extends Dialog { this._receiveTextQueue = []; } + selectionEmpty() { + return !window.getSelection().toString() + } + async _onKeyDown(e) { if (!this.isShown()) return - if (e.code === "KeyC" && (e.ctrlKey || e.metaKey)) { + if (e.code === "KeyC" && (e.ctrlKey || e.metaKey) && this.selectionEmpty()) { await this._onCopy() - this.hide(); } else if (e.code === "Escape") { this.hide(); From 229084fab33827c3e9d243a7a4fed0283f487ec5 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 16:54:01 +0100 Subject: [PATCH 4/6] Properly style indented text via css --- public/styles/styles-deferred.css | 1 + 1 file changed, 1 insertion(+) diff --git a/public/styles/styles-deferred.css b/public/styles/styles-deferred.css index 36a7b29..cda51e2 100644 --- a/public/styles/styles-deferred.css +++ b/public/styles/styles-deferred.css @@ -16,6 +16,7 @@ max-height: 350px; word-break: break-word; word-wrap: anywhere; + white-space: pre-wrap; } .textarea:before { From 48090ec41cecca89508aea69af14d0b98cd99729 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 16:54:43 +0100 Subject: [PATCH 5/6] Fix x-paper width (fixed #233) --- public/styles/styles-deferred.css | 1 + 1 file changed, 1 insertion(+) diff --git a/public/styles/styles-deferred.css b/public/styles/styles-deferred.css index cda51e2..6fbf811 100644 --- a/public/styles/styles-deferred.css +++ b/public/styles/styles-deferred.css @@ -336,6 +336,7 @@ x-dialog x-paper { display: flex; margin: auto; flex-direction: column; + width: 100%; max-width: 450px; z-index: 3; border-radius: 30px; From bea0fa5b9c83559112671a2c9caffae5a05199ab Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Wed, 3 Jan 2024 17:11:38 +0100 Subject: [PATCH 6/6] Fix color of URLs on receive text dialog --- public/styles/styles-deferred.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/styles/styles-deferred.css b/public/styles/styles-deferred.css index 6fbf811..0d81761 100644 --- a/public/styles/styles-deferred.css +++ b/public/styles/styles-deferred.css @@ -384,10 +384,6 @@ x-dialog:not([show]) x-paper { transform: scale(0.1); } -x-dialog a { - color: var(--primary-color); -} - /* Pair Devices Dialog & Public Room Dialog */ .input-key-container { @@ -786,7 +782,7 @@ x-dialog x-paper { background-color: var(--bg-color-secondary) !important; } -.textarea * { +.textarea *:not(a) { margin: 0 !important; padding: 0 !important; color: unset !important; @@ -799,6 +795,10 @@ x-dialog x-paper { font-weight: unset !important; } +x-dialog a { + color: var(--primary-color); +} + /* Image/Video/Audio Preview */ .file-preview { margin-bottom: 15px;