Editor refactor: fix plug namespace

This commit is contained in:
Zef Hemel
2023-07-14 16:48:35 +02:00
parent e92ed2c5be
commit f3936f9b2f
6 changed files with 51 additions and 76 deletions
+5 -9
View File
@@ -1,4 +1,4 @@
import { PageNamespaceHook } from "../common/hooks/page_namespace.ts";
import { PlugNamespaceHook } from "../common/hooks/plug_namespace.ts";
import { Manifest, SilverBulletHooks } from "../common/manifest.ts";
import buildMarkdown from "../common/markdown_parser/parser.ts";
import { CronHook } from "../plugos/hooks/cron.ts";
@@ -35,7 +35,7 @@ export class ClientSystem {
system: System<SilverBulletHooks> = new System("client");
commandHook: CommandHook;
slashCommandHook: SlashCommandHook;
namespaceHook: PageNamespaceHook;
namespaceHook: PlugNamespaceHook;
indexSyscalls: SysCallMapping;
codeWidgetHook: CodeWidgetHook;
plugsUpdated = false;
@@ -47,15 +47,11 @@ export class ClientSystem {
private dbPrefix: string,
private eventHook: EventHook,
) {
// Attach the page namespace hook
const namespaceHook = new PageNamespaceHook();
this.system.addHook(namespaceHook);
this.system.addHook(this.eventHook);
// Attach the page namespace hook
this.namespaceHook = new PageNamespaceHook();
this.system.addHook(namespaceHook);
// Plug page namespace hook
this.namespaceHook = new PlugNamespaceHook();
this.system.addHook(this.namespaceHook);
// Cron hook
const cronHook = new CronHook(this.system);
+2 -54
View File
@@ -2,7 +2,6 @@
import {
CompletionContext,
CompletionResult,
EditorSelection,
EditorView,
gitIgnoreCompiler,
runScopeHandlers,
@@ -10,32 +9,12 @@ import {
} from "../common/deps.ts";
import { Space } from "./space.ts";
import { FilterOption, PageMeta } from "./types.ts";
import { isMacLike, parseYamlSettings, safeRun } from "../common/util.ts";
import { parseYamlSettings } from "../common/util.ts";
import { EventHook } from "../plugos/hooks/event.ts";
import { Confirm, Prompt } from "./components/basic_modals.tsx";
import { CommandPalette } from "./components/command_palette.tsx";
import { FilterList } from "./components/filter.tsx";
import { PageNavigator } from "./components/page_navigator.tsx";
import { Panel } from "./components/panel.tsx";
import { TopBar } from "./components/top_bar.tsx";
import {
BookIcon,
HomeIcon,
preactRender,
TerminalIcon,
useEffect,
useReducer,
} from "./deps.ts";
import { AppCommand } from "./hooks/command.ts";
import { PathPageNavigator } from "./navigator.ts";
import reducer from "./reducer.ts";
import {
Action,
AppViewState,
BuiltinSettings,
initialViewState,
} from "./types.ts";
import { AppViewState, BuiltinSettings } from "./types.ts";
import type { AppEvent, CompleteEvent } from "../plug-api/app_event.ts";
import { throttle } from "../common/async_util.ts";
@@ -194,37 +173,6 @@ export class Editor {
});
this.openPages = new OpenPages(this.editorView);
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
globalThis.addEventListener("keydown", (ev) => {
if (!this.editorView?.hasFocus) {
if ((ev.target as any).closest(".cm-editor")) {
// In some cm element, let's back out
return;
}
if (runScopeHandlers(this.editorView!, ev, "editor")) {
ev.preventDefault();
}
}
});
globalThis.addEventListener("touchstart", (ev) => {
// Launch the page picker on a two-finger tap
if (ev.touches.length === 2) {
ev.stopPropagation();
ev.preventDefault();
this.ui.viewDispatch({ type: "start-navigate" });
}
// Launch the command palette using a three-finger tap
if (ev.touches.length === 3) {
ev.stopPropagation();
ev.preventDefault();
this.ui.viewDispatch({
type: "show-palette",
context: this.getContext(),
});
}
});
}
get currentPage(): string | undefined {
+31
View File
@@ -10,6 +10,7 @@ import {
BookIcon,
HomeIcon,
preactRender,
runScopeHandlers,
TerminalIcon,
useEffect,
useReducer,
@@ -23,6 +24,36 @@ export class MainUI {
viewDispatch: (action: Action) => void = () => {};
constructor(private editor: Editor) {
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
globalThis.addEventListener("keydown", (ev) => {
if (!editor.editorView?.hasFocus) {
if ((ev.target as any).closest(".cm-editor")) {
// In some cm element, let's back out
return;
}
if (runScopeHandlers(editor.editorView!, ev, "editor")) {
ev.preventDefault();
}
}
});
globalThis.addEventListener("touchstart", (ev) => {
// Launch the page picker on a two-finger tap
if (ev.touches.length === 2) {
ev.stopPropagation();
ev.preventDefault();
this.viewDispatch({ type: "start-navigate" });
}
// Launch the command palette using a three-finger tap
if (ev.touches.length === 3) {
ev.stopPropagation();
ev.preventDefault();
this.viewDispatch({
type: "show-palette",
context: editor.getContext(),
});
}
});
}
ViewComponent() {