1
0

Merge branch 'main' of github.com:silverbulletmd/silverbullet

This commit is contained in:
Zef Hemel 2023-01-04 16:39:10 +01:00
commit 3883ba9a66
3 changed files with 22 additions and 12 deletions

View File

@ -74,7 +74,7 @@ import {
vim, vim,
yUndoManagerKeymap, yUndoManagerKeymap,
} from "./deps.ts"; } from "./deps.ts";
import { CommandHook } from "./hooks/command.ts"; import { AppCommand, CommandHook } from "./hooks/command.ts";
import { SlashCommandHook } from "./hooks/slash_command.ts"; import { SlashCommandHook } from "./hooks/slash_command.ts";
import { PathPageNavigator } from "./navigator.ts"; import { PathPageNavigator } from "./navigator.ts";
import reducer from "./reducer.ts"; import reducer from "./reducer.ts";
@ -926,7 +926,7 @@ export class Editor {
}); });
} }
}} }}
commands={viewState.commands} commands={this.getCommandsByContext(viewState)}
vimMode={viewState.uiOptions.vimMode} vimMode={viewState.uiOptions.vimMode}
darkMode={viewState.uiOptions.darkMode} darkMode={viewState.uiOptions.darkMode}
completer={this.miniEditorComplete.bind(this)} completer={this.miniEditorComplete.bind(this)}
@ -1069,6 +1069,23 @@ export class Editor {
preactRender(<ViewComponent />, container); preactRender(<ViewComponent />, container);
} }
private getCommandsByContext(
state: AppViewState,
): Map<string, AppCommand> {
const commands = new Map(state.commands);
for (const [k, v] of state.commands.entries()) {
if (
v.command.contexts &&
(!state.showCommandPaletteContext ||
!v.command.contexts.includes(state.showCommandPaletteContext))
) {
commands.delete(k);
}
}
return commands;
}
private getContext(): string | undefined { private getContext(): string | undefined {
const state = this.editorView!.state; const state = this.editorView!.state;
const selection = state.selection.main; const selection = state.selection.main;

View File

@ -63,25 +63,17 @@ export default function reducer(
}; };
} }
case "show-palette": { case "show-palette": {
const commands = new Map(state.commands);
for (const [k, v] of state.commands.entries()) {
if (
v.command.contexts &&
(!action.context || !v.command.contexts.includes(action.context))
) {
commands.delete(k);
}
}
return { return {
...state, ...state,
commands,
showCommandPalette: true, showCommandPalette: true,
showCommandPaletteContext: action.context,
}; };
} }
case "hide-palette": case "hide-palette":
return { return {
...state, ...state,
showCommandPalette: false, showCommandPalette: false,
showCommandPaletteContext: undefined,
}; };
case "command-run": case "command-run":
return { return {

View File

@ -29,6 +29,7 @@ export type AppViewState = {
isLoading: boolean; isLoading: boolean;
showPageNavigator: boolean; showPageNavigator: boolean;
showCommandPalette: boolean; showCommandPalette: boolean;
showCommandPaletteContext?: string;
unsavedChanges: boolean; unsavedChanges: boolean;
panels: { [key: string]: PanelConfig }; panels: { [key: string]: PanelConfig };
allPages: Set<PageMeta>; allPages: Set<PageMeta>;