fix: toggle active neighborhood back to notes
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
isEditableElement,
|
||||
popNeighborhoodHistory,
|
||||
pushNeighborhoodHistory,
|
||||
resolveNeighborhoodSelection,
|
||||
selectionsEqual,
|
||||
shouldProcessNeighborhoodEscape,
|
||||
} from './neighborhoodHistory'
|
||||
@@ -62,6 +63,21 @@ describe('neighborhoodHistory', () => {
|
||||
expect(pushNeighborhoodHistory([inboxSelection], alphaSelection, alphaSelection)).toEqual([inboxSelection])
|
||||
})
|
||||
|
||||
it('resolves Neighborhood entry as enter, switch, or exit actions', () => {
|
||||
expect(resolveNeighborhoodSelection(inboxSelection, alphaSelection.entry)).toEqual({
|
||||
action: 'enter',
|
||||
selection: alphaSelection,
|
||||
})
|
||||
expect(resolveNeighborhoodSelection(alphaSelection, betaSelection.entry)).toEqual({
|
||||
action: 'switch',
|
||||
selection: betaSelection,
|
||||
})
|
||||
expect(resolveNeighborhoodSelection(alphaSelection, buildEntry('/vault/alpha.md', 'Alpha copy'))).toEqual({
|
||||
action: 'exit',
|
||||
selection: { kind: 'filter', filter: 'all' },
|
||||
})
|
||||
})
|
||||
|
||||
it('pops one level of note-list history at a time', () => {
|
||||
expect(popNeighborhoodHistory([inboxSelection, alphaSelection])).toEqual({
|
||||
previousSelection: alphaSelection,
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import type { SidebarSelection } from '../types'
|
||||
import type { SidebarSelection, VaultEntry } from '../types'
|
||||
|
||||
const NOTE_LIST_CONTAINER_SELECTOR = '[data-testid="note-list-container"]'
|
||||
const EDITOR_SURFACE_SELECTOR = '.editor__blocknote-container, .cm-editor'
|
||||
|
||||
export type NeighborhoodSelectionAction = 'enter' | 'switch' | 'exit'
|
||||
|
||||
export interface NeighborhoodSelectionUpdate {
|
||||
action: NeighborhoodSelectionAction
|
||||
selection: SidebarSelection
|
||||
}
|
||||
|
||||
function isSameFilterSelection(a: Extract<SidebarSelection, { kind: 'filter' }>, b: Extract<SidebarSelection, { kind: 'filter' }>) {
|
||||
return a.filter === b.filter
|
||||
}
|
||||
@@ -49,6 +56,21 @@ export function pushNeighborhoodHistory(
|
||||
return [...history, currentSelection]
|
||||
}
|
||||
|
||||
export function resolveNeighborhoodSelection(
|
||||
currentSelection: SidebarSelection,
|
||||
entry: VaultEntry,
|
||||
): NeighborhoodSelectionUpdate {
|
||||
const nextSelection: SidebarSelection = { kind: 'entity', entry }
|
||||
if (selectionsEqual(currentSelection, nextSelection)) {
|
||||
return { action: 'exit', selection: { kind: 'filter', filter: 'all' } }
|
||||
}
|
||||
|
||||
return {
|
||||
action: currentSelection.kind === 'entity' ? 'switch' : 'enter',
|
||||
selection: nextSelection,
|
||||
}
|
||||
}
|
||||
|
||||
export function popNeighborhoodHistory(history: SidebarSelection[]) {
|
||||
if (history.length === 0) return { previousSelection: null, nextHistory: history }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user