diff --git a/common/deps.ts b/common/deps.ts index 07f7893..5af7b15 100644 --- a/common/deps.ts +++ b/common/deps.ts @@ -44,7 +44,7 @@ export { export type { NodeType, SyntaxNode, SyntaxNodeRef, Tree } from "@lezer/common"; -export { searchKeymap } from "https://esm.sh/@codemirror/search@6.2.3?external=@codemirror/state,@codemirror/view"; +export { searchKeymap } from "@codemirror/search"; export { Decoration, drawSelection, diff --git a/common/util.ts b/common/util.ts index 88d9bb5..b75753e 100644 --- a/common/util.ts +++ b/common/util.ts @@ -33,7 +33,12 @@ export function parseYamlSettings(settingsMarkdown: string): { return {}; } const yaml = match[1]; - return YAML.parse(yaml) as { - [key: string]: any; - }; + try { + return YAML.parse(yaml) as { + [key: string]: any; + }; + } catch (e: any) { + console.error("Error parsing SETTINGS as YAML", e.message); + return {}; + } } diff --git a/import_map.json b/import_map.json index 230624b..f3f83a3 100644 --- a/import_map.json +++ b/import_map.json @@ -11,6 +11,7 @@ "@codemirror/autocomplete": "https://esm.sh/@codemirror/autocomplete@6.3.4?external=@codemirror/state,@codemirror/commands,@lezer/common,@codemirror/view", "@codemirror/lint": "https://esm.sh/@codemirror/lint@6.1.0?external=@codemirror/state,@lezer/common", "@codemirror/lang-html": "https://esm.sh/@codemirror/lang-html@6.4.0", + "@codemirror/search": "https://esm.sh/@codemirror/search@6.2.3?external=@codemirror/state,@codemirror/view", "preact": "https://esm.sh/preact@10.11.1", "yjs": "https://esm.sh/yjs@13.5.42", "$sb/": "./plug-api/", diff --git a/web/boot.ts b/web/boot.ts index dd0d7dc..1939748 100644 --- a/web/boot.ts +++ b/web/boot.ts @@ -6,6 +6,7 @@ import { PlugSpacePrimitives } from "../server/hooks/plug_space_primitives.ts"; import { PageNamespaceHook } from "../server/hooks/page_namespace.ts"; import { SilverBulletHooks } from "../common/manifest.ts"; import { System } from "../plugos/system.ts"; +import { BuiltinSettings } from "./types.ts"; safeRun(async () => { const httpPrimitives = new HttpSpacePrimitives(""); @@ -36,14 +37,18 @@ safeRun(async () => { console.log("Booting..."); - const settings = parseYamlSettings(settingsPageText); + const settings = parseYamlSettings(settingsPageText) as BuiltinSettings; + + if (!settings.indexPage) { + settings.indexPage = "index"; + } const editor = new Editor( serverSpace, system, document.getElementById("sb-root")!, "", - settings.indexPage || "index", + settings, ); // @ts-ignore: for convenience window.editor = editor; diff --git a/web/deps.ts b/web/deps.ts index 4790155..0c936ec 100644 --- a/web/deps.ts +++ b/web/deps.ts @@ -28,3 +28,6 @@ export { yUndoManagerKeymap, } from "https://esm.sh/y-codemirror.next@0.3.2?external=yjs,@codemirror/state,@codemirror/commands,@codemirror/history,@codemirror/view"; export { WebsocketProvider } from "https://esm.sh/y-websocket@1.4.5?external=yjs"; + +// Vim mode +export { vim } from "https://esm.sh/@replit/codemirror-vim@6.0.3?external=@codemirror/state,@codemirror/language,@codemirror/view,@codemirror/search,@codemirror/commands"; diff --git a/web/editor.tsx b/web/editor.tsx index c111e0c..7deb67a 100644 --- a/web/editor.tsx +++ b/web/editor.tsx @@ -80,7 +80,12 @@ import { systemSyscalls } from "./syscalls/system.ts"; import assetSyscalls from "../plugos/syscalls/asset.ts"; // State and state transitions -import { Action, AppViewState, initialViewState } from "./types.ts"; +import { + Action, + AppViewState, + BuiltinSettings, + initialViewState, +} from "./types.ts"; import type { AppEvent, ClickEvent } from "../plug-api/app_event.ts"; // UI Components @@ -104,6 +109,7 @@ import customMarkdownStyle from "./style.ts"; // Real-time collaboration import { CollabState } from "./cm_plugins/collab.ts"; import { collabSyscalls } from "./syscalls/collab.ts"; +import { vim } from "./deps.ts"; const frontMatterRegex = /^---\s*$(.*?)---\s*$/ms; @@ -143,14 +149,14 @@ export class Editor { system: System, parent: Element, urlPrefix: string, - indexPage: string, + readonly builtinSettings: BuiltinSettings, ) { this.space = space; this.system = system; this.urlPrefix = urlPrefix; this.viewState = initialViewState; this.viewDispatch = () => {}; - this.indexPage = indexPage; + this.indexPage = builtinSettings.indexPage; // Event hook this.eventHook = new EventHook(); @@ -178,7 +184,10 @@ export class Editor { state: this.createEditorState("", ""), parent: document.getElementById("sb-editor")!, }); - this.pageNavigator = new PathPageNavigator(indexPage, urlPrefix); + this.pageNavigator = new PathPageNavigator( + builtinSettings.indexPage, + urlPrefix, + ); this.system.registerSyscalls( [], @@ -478,6 +487,8 @@ export class Editor { inlineImagesPlugin(), highlightSpecialChars(), history(), + // Enable vim mode + [...this.builtinSettings.vimMode ? [vim()] : []], drawSelection(), dropCursor(), indentOnInput(), diff --git a/web/types.ts b/web/types.ts index 58cbba5..98a5df7 100644 --- a/web/types.ts +++ b/web/types.ts @@ -12,6 +12,11 @@ type EditorMode = "ro" | "rw"; export type PanelMode = number; +export type BuiltinSettings = { + indexPage: string; + vimMode?: boolean; +}; + export type PanelConfig = { mode?: PanelMode; html?: string; diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 5d74c24..af826fe 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -3,6 +3,11 @@ release. --- +## Next +* Initial version of vim mode is here. To enable set `vimMode` to `true` in your [[SETTINGS]] page and reload. + +--- + ## 0.2.3 > **Note** Admonition support