Repository navigation
feat(preview): open a middle-clicked link in a background tab (#1087) - #1091
Merged
Merged
Conversation
Middle-clicking a link to another Markdown file opens it in a new tab behind the current one, scrolled to the link's heading when first shown. If the file is already open in this window, its tab flashes instead. Other links open as a plain click would. A window-level guard stops WebKit from navigating the whole webview on a middle-clicked link.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Middle-clicking a link to another Markdown file did nothing on Windows. On macOS, in a build without the guard below, WebKit navigated the whole window to the link's href and left a bare "404 Not Found" page until restart. Now a middle-click opens the file in a new tab behind the current one, as browsers do. Plain click, Ctrl/Cmd-click, the "Open Links in a New Tab" setting and the context menu keep their current behavior.
Mechanism
mousedownwith button 1, the same way a tab's middle-click close does. A Markdown target goes toopenInBackgroundTab. Other links (external URLs, local non-Markdown files) open as a plain click would.openInBackgroundTabadds the tab withaddTab(..., activate = false)and marks itunread, so it is read the first time it is shown, through the existing lazy-restore path. Nothing is loaded into the tab being read, and the file joins recent files only when that read succeeds, so a dead link leaves no entry.#headingin the link is stored on the tab aspendingAnchor.readActiveIfUnreadhands it back once after that first read, and the viewer scrolls to it with the samescrollToAnchorWhenReadycall the Ctrl-click path uses.prefers-reduced-motionthe highlight is held still instead of animated.mousedowndoes not stop WebKit's own middle-click navigation, which runs onauxclick.blockMiddleClickNavigationcancelsauxclickandclickwith button 1 on anya[href], onwindowin the capture phase.Tests
tabs.spec.tschecks that a background open keeps the active tab and reads on first show, that an already-open file flashes without changing the active tab or tab count, that the heading is handed over once, after the read, never to the tab being read, and that recent files are written by the read rather than the click.preview.spec.tschecks the navigation guard, andpreview.test.tsthe middle-click routing.Verification
npm run check,npm run lint,npm test(962 passed),npx vitest run(776 passed),vite buildandcheck-startup-chunk. No Rust changes.Closes #1087