Skip to content
Draft
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions src/zen/common/modules/ZenCommonUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,22 @@ export class nsZenPreloadedFeature {

window.gZenCommonActions = {
copyCurrentURLToClipboard() {

const activeBrowser = gBrowser.selectedBrowser;
const [currentUrl, ClipboardHelper] = gURLBar.zenStrippedURI;
const displaySpec = currentUrl.displaySpec;

let displaySpec = activeBrowser.userTypedValue ||
gURLBar.untrimmedValue ||
(activeBrowser.currentURI ? activeBrowser.currentURI.spec : "") ||
currentUrl.displaySpec;

if (displaySpec === "about:blank" || displaySpec === "") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you copy the tab's label tough? This seems like a hacky solution to the real issue

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out the the tab's label get the label even before the URL bar and website finish loading.
And it can be used to put in the URL bar to search for the website

What do you recommend me to approach this problem?

  1. Delete the if check block entirely and let it fall back to about:blank when the browser cannot grab any URL from all the case above?
  2. Any ideas on your side?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I have no idea yet... Let me investigate a bit and ill come back to you because this is a complex issue, even if it doesn't look like one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const tabLabel = gBrowser.selectedTab.label;
if (tabLabel && tabLabel !== "New Tab") {
displaySpec = tabLabel;
}
}

ClipboardHelper.copyString(displaySpec);
let button;
/* eslint-disable mozilla/valid-services */
Expand All @@ -111,9 +125,23 @@ window.gZenCommonActions = {
},

copyCurrentURLAsMarkdownToClipboard() {
const activeBrowser = gBrowser.selectedBrowser;
const [currentUrl, ClipboardHelper] = gURLBar.zenStrippedURI;
const tabTitle = gBrowser.selectedTab.label;
const markdownLink = `[${tabTitle}](${currentUrl.displaySpec})`;

let displaySpec = activeBrowser.userTypedValue ||
gURLBar.untrimmedValue ||
(activeBrowser.currentURI ? activeBrowser.currentURI.spec : "") ||
currentUrl.displaySpec;

if (displaySpec === "about:blank" || displaySpec === "") {
const tabLabel = gBrowser.selectedTab.label;
if (tabLabel && tabLabel !== "New Tab") {
displaySpec = tabLabel;
}
}

const tabTitle = gBrowser.selectedTab.label || displaySpec;
const markdownLink = `[${tabTitle}](${displaySpec})`;
ClipboardHelper.copyString(markdownLink);
gZenUIManager.showToast("zen-copy-current-url-confirmation", { timeout: 3000 });
},
Expand All @@ -140,4 +168,4 @@ window.gZenCommonActions = {
const tab = gBrowser.selectedTab;
return Boolean(tab.owner && !tab.pinned && !tab.hasAttribute("zen-empty-tab"));
},
};
};