Fixes #149: vim mode
This commit is contained in:
parent
d609daf59e
commit
0f090b77db
@ -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,
|
||||
|
@ -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 {};
|
||||
}
|
||||
}
|
||||
|
@ -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/",
|
||||
|
@ -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;
|
||||
|
@ -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";
|
||||
|
@ -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<SilverBulletHooks>,
|
||||
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(),
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user