Prevent losing commands with context (#254)
This commit is contained in:
+19
-2
@@ -74,7 +74,7 @@ import {
|
||||
vim,
|
||||
yUndoManagerKeymap,
|
||||
} from "./deps.ts";
|
||||
import { CommandHook } from "./hooks/command.ts";
|
||||
import { AppCommand, CommandHook } from "./hooks/command.ts";
|
||||
import { SlashCommandHook } from "./hooks/slash_command.ts";
|
||||
import { PathPageNavigator } from "./navigator.ts";
|
||||
import reducer from "./reducer.ts";
|
||||
@@ -926,7 +926,7 @@ export class Editor {
|
||||
});
|
||||
}
|
||||
}}
|
||||
commands={viewState.commands}
|
||||
commands={this.getCommandsByContext(viewState)}
|
||||
vimMode={viewState.uiOptions.vimMode}
|
||||
darkMode={viewState.uiOptions.darkMode}
|
||||
completer={this.miniEditorComplete.bind(this)}
|
||||
@@ -1069,6 +1069,23 @@ export class Editor {
|
||||
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 {
|
||||
const state = this.editorView!.state;
|
||||
const selection = state.selection.main;
|
||||
|
||||
Reference in New Issue
Block a user