From e516c9bfd2a3850a1e3c7b58eb24734e539c399c Mon Sep 17 00:00:00 2001 From: Ryan Gabriel Date: Mon, 24 Aug 2026 00:20:16 +0800 Subject: [PATCH] Fix silent failures of Alt+O / Alt+C shortcuts Alt+O (open original page) and Alt+C (copy original link) both bail out silently when the rendered entry has no ._attribution ._attribution-link element, which left users of affected documentations with dead shortcuts and no feedback (#2634). Alt+C also logged to console on every use and ignored clipboard promise rejections after the navigator.clipboard migration. - Show a transient notice when no original-page link exists - Surface a notice if the clipboard write rejects instead of failing silently; drop the leftover console.log - Notices auto-dismiss after 3s without stacking --- assets/javascripts/templates/notice_tmpl.js | 6 ++++++ .../javascripts/views/content/entry_page.js | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/templates/notice_tmpl.js b/assets/javascripts/templates/notice_tmpl.js index 49793eb571..26c8c947b1 100644 --- a/assets/javascripts/templates/notice_tmpl.js +++ b/assets/javascripts/templates/notice_tmpl.js @@ -7,3 +7,9 @@ app.templates.singleDocNotice = (doc) => app.templates.disabledDocNotice = () => notice(` This documentation is disabled. To enable it, go to Preferences. `); + +app.templates.noOriginalLinkNotice = () => + notice(` The original page link is not available for this documentation. `); + +app.templates.copyFailedNotice = () => + notice(` Couldn't copy the original page link to the clipboard. `); diff --git a/assets/javascripts/views/content/entry_page.js b/assets/javascripts/views/content/entry_page.js index 961d90e1fa..8b7bc4dd52 100644 --- a/assets/javascripts/views/content/entry_page.js +++ b/assets/javascripts/views/content/entry_page.js @@ -221,17 +221,32 @@ app.views.EntryPage = class EntryPage extends app.View { onAltC() { const link = this.find("._attribution:last-child ._attribution-link"); if (!link) { + this.showTransientNotice("noOriginalLink"); return; } - console.log(link.href + location.hash); - navigator.clipboard.writeText(link.href + location.hash); + navigator.clipboard.writeText(link.href + location.hash).catch(() => + this.showTransientNotice("copyFailed"), + ); } onAltO() { const link = this.find("._attribution:last-child ._attribution-link"); if (!link) { + this.showTransientNotice("noOriginalLink"); return; } this.delay(() => $.popup(link.href + location.hash)); } + + showTransientNotice(type) { + if (this.transientNotice) { + clearTimeout(this.transientNoticeTimer); + this.transientNotice.deactivate(); + } + this.transientNotice = new app.views.Notice(type); + this.transientNoticeTimer = setTimeout(() => { + this.transientNotice.deactivate(); + this.transientNotice = null; + }, 3000); + } };