Skip to content

Commit ecfbef2

Browse files
authored
feat: enhance breadcrumb navigation with Shift+click functionality to open in sidebar (#4)
* feat: enhance breadcrumb navigation with Shift+click functionality to open in sidebar * 1.1.0 * docs: add Slack badge to README for community engagement
1 parent 44294b8 commit ecfbef2

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
you can jump back instantly and navigate your graph with confidence.**
99

1010
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/RoamJS/breadcrumbs)
11+
[![Slack](https://img.shields.io/badge/Slack-%23roam--js-purple)](https://roamresearch.slack.com/archives/C016N2B66JU)
1112

1213
![](https://github.com/user-attachments/assets/bb192b0d-04ad-420f-909d-7dd9be71347c)
1314

@@ -16,6 +17,7 @@ you can jump back instantly and navigate your graph with confidence.**
1617
- Tracks recently visited pages and block locations
1718
- Renders oldest-to-current breadcrumb trail in the top bar
1819
- Click any non-current breadcrumb to navigate back
20+
- Shift+click any non-current breadcrumb to open in the right sidebar
1921
- Distinguishes pages vs blocks with different styles
2022
- Supports Blueprint dark mode (`.bp3-dark`)
2123

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breadcrumbs",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Navigation breadcrumbs for Roam Research.",
55
"main": "index.js",
66
"scripts": {

src/index.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { OnloadArgs } from "roamjs-components/types/native";
22
import runExtension from "roamjs-components/util/runExtension";
3+
import openBlockInSidebar from "roamjs-components/writes/openBlockInSidebar";
34

45
type LocationType = "page" | "block";
56

@@ -170,7 +171,7 @@ const truncateText = ({
170171
return `${cleaned.slice(0, maxLength - 1)}...`;
171172
};
172173

173-
const navigateTo = ({
174+
const openInMainWindow = ({
174175
uid,
175176
type,
176177
}: {
@@ -185,6 +186,23 @@ const navigateTo = ({
185186
window.roamAlphaAPI.ui.mainWindow.openBlock({ block: { uid } });
186187
};
187188

189+
const navigateTo = ({
190+
uid,
191+
type,
192+
inSidebar,
193+
}: {
194+
uid: string;
195+
type: LocationType;
196+
inSidebar: boolean;
197+
}): void => {
198+
if (inSidebar) {
199+
openBlockInSidebar(uid);
200+
return;
201+
}
202+
203+
openInMainWindow({ uid, type });
204+
};
205+
188206
const createSeparatorElement = (): HTMLSpanElement => {
189207
const separator = document.createElement("span");
190208
separator.className = "breadcrumb-separator";
@@ -213,12 +231,25 @@ const createBreadcrumbElement = ({
213231
});
214232
element.title = stripMarkdown({ text: item.title });
215233
element.style.maxWidth = `${Math.max(truncateLength, 20)}ch`;
234+
element.addEventListener("mousedown", (event: MouseEvent) => {
235+
if (event.shiftKey) {
236+
event.preventDefault();
237+
}
238+
});
216239

217240
if (!isCurrent) {
218-
element.addEventListener("click", (event) => {
241+
element.addEventListener("click", (event: MouseEvent) => {
219242
event.preventDefault();
220243
event.stopPropagation();
221-
navigateTo({ uid: item.uid, type: item.type });
244+
if (event.shiftKey) {
245+
// handle shift+click selecting text
246+
window.getSelection()?.removeAllRanges();
247+
}
248+
navigateTo({
249+
uid: item.uid,
250+
type: item.type,
251+
inSidebar: event.shiftKey,
252+
});
222253
});
223254
}
224255

@@ -358,6 +389,8 @@ const injectStyles = (): void => {
358389
white-space: nowrap;
359390
text-overflow: ellipsis;
360391
max-width: 200px;
392+
user-select: none;
393+
-webkit-user-select: none;
361394
}
362395
363396
.breadcrumb-item:hover:not(.breadcrumb-current) {

0 commit comments

Comments
 (0)