Skip to content

Commit dc526c9

Browse files
committed
🚸(frontend) allow opening "interlinks" with ctrl/command/middle mouse
Links to other pages created through the "@" shortcut are not actual anchor (`<a>`) elements seemingly due to conflicts with lower-lvl code, noticeably when drag&dropping the elements. So those "links" are actually span and we must handle the "link behavior" ourselves. This adds more usual "link behavior" to thoses, allowing users to ctrl+click, command+click, shift+click and middle-mouse click to interact with the links and open them in a new tab or new window. Signed-off-by: Emmanuel Pelletier <manu@habite.la>
1 parent 4b4319d commit dc526c9

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to
66

77
## [Unreleased]
88

9+
- 🚸(frontend) allow opening "@page" links with ctrl/command/middle-mouse click
10+
911
### Added
1012

1113
- 🔧(backend) settings CONVERSION_UPLOAD_ENABLED to control usage of docspec

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-inline-content/Interlinking/InterlinkingLinkInlineContent.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,35 @@ export const LinkSelected = ({
124124

125125
const { emoji, titleWithoutEmoji } = getEmojiAndTitle(title);
126126
const router = useRouter();
127+
const href = `/docs/${docId}/`;
127128

128129
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
129130
e.preventDefault();
130-
void router.push(`/docs/${docId}/`);
131+
132+
// If ctrl or command is pressed, it opens a new tab. If shift is pressed, it opens a new window
133+
if (e.metaKey || e.ctrlKey || e.shiftKey) {
134+
window.open(href, '_blank');
135+
return;
136+
}
137+
void router.push(href);
138+
};
139+
140+
// This triggers on middle-mouse click
141+
const handleAuxClick = (e: React.MouseEvent<HTMLDivElement>) => {
142+
if (e.button !== 1) {
143+
return;
144+
}
145+
e.preventDefault();
146+
e.stopPropagation();
147+
window.open(href, '_blank');
131148
};
132149

133150
return (
134151
<BoxButton
135152
as="span"
136153
className="--docs--interlinking-link-inline-content"
137154
onClick={handleClick}
155+
onAuxClick={handleAuxClick}
138156
draggable="false"
139157
$css={css`
140158
display: inline;

0 commit comments

Comments
 (0)