Merge pull request #2138 from bb2/patch-1
UI: Decode URL in text field for better readability
This commit is contained in:
@@ -37,7 +37,23 @@ export class UrlTextHandler {
|
|||||||
this._element = element;
|
this._element = element;
|
||||||
this._copyButton = copyButton;
|
this._copyButton = copyButton;
|
||||||
this._userIndex = -1;
|
this._userIndex = -1;
|
||||||
|
this._completedUrl = "";
|
||||||
|
|
||||||
|
// Only encode the URL if the entire text is selected.
|
||||||
|
if (this._element) {
|
||||||
|
this._element.addEventListener("copy", (event) => {
|
||||||
|
const selectedText = window.getSelection()?.toString();
|
||||||
|
const totalText = this._element.value;
|
||||||
|
|
||||||
|
// Check if the selected text length matches the total text length.
|
||||||
|
if (event.clipboardData && selectedText && selectedText.length === totalText.length) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.clipboardData.setData("text/plain", this._completedUrl || "");
|
||||||
|
}
|
||||||
|
// Allow default copying if only a part of the text is selected.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this._element.addEventListener("focusin", () => {
|
this._element.addEventListener("focusin", () => {
|
||||||
this._element.setSelectionRange(0, 99999);
|
this._element.setSelectionRange(0, 99999);
|
||||||
this._updateScroll();
|
this._updateScroll();
|
||||||
@@ -88,7 +104,7 @@ export class UrlTextHandler {
|
|||||||
_oncopy() {
|
_oncopy() {
|
||||||
if (!this._element.value) return;
|
if (!this._element.value) return;
|
||||||
|
|
||||||
navigator.clipboard.writeText(this._element.value).then(() => {
|
navigator.clipboard.writeText(this._completedUrl || "").then(() => {
|
||||||
if (this._copyButton) {
|
if (this._copyButton) {
|
||||||
this._copyButton.classList.add("copied");
|
this._copyButton.classList.add("copied");
|
||||||
this._copyButton.title = "Copied!";
|
this._copyButton.title = "Copied!";
|
||||||
@@ -108,7 +124,8 @@ export class UrlTextHandler {
|
|||||||
* @param {string} href The href to set.
|
* @param {string} href The href to set.
|
||||||
*/
|
*/
|
||||||
setHref(href) {
|
setHref(href) {
|
||||||
this._element.value = completeHref(href);
|
this._completedUrl = completeHref(href);
|
||||||
|
this._element.value = decodeURIComponent(this._completedUrl);
|
||||||
|
|
||||||
this._update_username_index();
|
this._update_username_index();
|
||||||
this._updateScroll();
|
this._updateScroll();
|
||||||
|
|||||||
Reference in New Issue
Block a user