Skip to content

Commit f7a5ac1

Browse files
committed
Make each sidebar page it's own "panel", and provide shortcuts for
navigating between sidebar panels
1 parent 6f9d22c commit f7a5ac1

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/ts/core/features/vim-mode/commands/panel-commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const closeSidebarPage = () => {
1515

1616
export const PanelCommands = [
1717
// Need to wrap in function to preserve the `this` reference inside of RoamPanel
18-
nmap('h', 'Select Panel Left', () => RoamPanel.previousPanel().select()),
19-
nmap('l', 'Select Panel Right', () => RoamPanel.nextPanel().select()),
18+
nmap('h', 'Select Main Panel', () => RoamPanel.mainPanel().select()),
19+
nmap('l', 'Select Prior Sidebar Panel', () => RoamPanel.previousSidebarPanel().select()),
20+
nmap('ctrl+k', 'Select Previous Panel', () => RoamPanel.previousPanel().select()),
21+
nmap('ctrl+j', 'Select Next Panel', () => RoamPanel.nextPanel().select()),
2022
map('ctrl+w', 'Close Page in Side Bar', closeSidebarPage),
2123
]

src/ts/core/features/vim-mode/roam/roam-panel.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ type BlockNavigationState = {
99
panelOrder: PanelId[]
1010
panels: Map<PanelId, RoamPanel>
1111
focusedPanel: PanelIndex
12+
lastFocusedSidebarPanel: PanelIndex
1213
}
1314

1415
const state: BlockNavigationState = {
1516
panelOrder: [],
1617
panels: new Map(),
1718
focusedPanel: 0,
19+
lastFocusedSidebarPanel: 1,
1820
}
1921

2022
/**
@@ -26,7 +28,7 @@ type PanelIndex = number
2628
type PanelElement = HTMLElement
2729

2830
const PANEL_CSS_CLASS = 'roam-toolkit--panel'
29-
const PANEL_SELECTOR = `.${PANEL_CSS_CLASS}, ${Selectors.sidebarContent}`
31+
const PANEL_SELECTOR = `.${PANEL_CSS_CLASS}, ${Selectors.sidebarPage}`
3032

3133
/**
3234
* A "Panel" is a viewport that contains blocks. For now, there is just
@@ -121,8 +123,11 @@ export class RoamPanel {
121123
}
122124

123125
select() {
126+
if (state.focusedPanel > 0) {
127+
state.lastFocusedSidebarPanel = state.focusedPanel
128+
}
124129
state.focusedPanel = state.panelOrder.indexOf(this.element)
125-
this.element.scrollIntoView({behavior: 'smooth'})
130+
this.element.scrollIntoView()
126131
}
127132

128133
static selected(): RoamPanel {
@@ -144,6 +149,10 @@ export class RoamPanel {
144149
return RoamPanel.at(0)
145150
}
146151

152+
static previousSidebarPanel(): RoamPanel {
153+
return RoamPanel.at(state.lastFocusedSidebarPanel)
154+
}
155+
147156
static previousPanel(): RoamPanel {
148157
return RoamPanel.at(state.focusedPanel - 1)
149158
}

src/ts/core/roam/selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const Selectors = {
1010
mainPanel: '.roam-body-main',
1111

1212
sidebarContent: '#roam-right-sidebar-content',
13-
sidebarPage: '#right-sidebar > div',
13+
sidebarPage: `#roam-right-sidebar-content > div`,
1414
sidebar: '#right-sidebar',
1515

1616
leftPanel: '.roam-sidebar-container',

0 commit comments

Comments
 (0)