Refactor vim mode naming
Rebind "o" to follow markdown editor's newline and continue behavior
This commit is contained in:
@@ -478,8 +478,8 @@ export function vimEx(exCommand: string): Promise<any> {
|
||||
/**
|
||||
* Execute a vim config using the CodeMirror Vim Mode API
|
||||
*/
|
||||
export function vimConfig(): Promise<any> {
|
||||
return syscall("editor.vimConfig");
|
||||
export function configureVimMode(): Promise<any> {
|
||||
return syscall("editor.configureVimMode");
|
||||
}
|
||||
|
||||
// Document editor specific syscalls
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ export async function loadVimConfig() {
|
||||
try {
|
||||
await editor.save();
|
||||
await editor.reloadConfigAndCommands();
|
||||
await editor.vimConfig();
|
||||
await editor.configureVimMode();
|
||||
} catch (e: any) {
|
||||
await editor.flashNotification(e.message, "error");
|
||||
}
|
||||
|
||||
+1
-1
@@ -307,7 +307,7 @@ export function createCommandKeyBindings(client: Client): KeyBinding[] {
|
||||
|
||||
// Track which keyboard shortcuts for which commands we've overridden, so we can skip them later
|
||||
const overriddenCommands = new Set<string>();
|
||||
// Keyboard shortcuts from SETTINGS take precedense
|
||||
// Keyboard shortcuts from SETTINGS take precedence
|
||||
if (client.config.has("shortcuts")) {
|
||||
for (const shortcut of client.config.get<Shortcut[]>("shortcuts", [])) {
|
||||
overriddenCommands.add(shortcut.command);
|
||||
|
||||
+13
-1
@@ -8,6 +8,7 @@ import {
|
||||
} from "@codemirror/language";
|
||||
import {
|
||||
deleteLine,
|
||||
insertNewlineAndIndent,
|
||||
moveLineDown,
|
||||
moveLineUp,
|
||||
redo,
|
||||
@@ -24,6 +25,8 @@ import type {
|
||||
import type { PageMeta, UploadFile } from "../../plug-api/types.ts";
|
||||
import { openSearchPanel } from "@codemirror/search";
|
||||
import { parseRef, type Ref } from "@silverbulletmd/silverbullet/lib/page_ref";
|
||||
import { insertNewlineContinueMarkup } from "@codemirror/lang-markdown";
|
||||
import { configureVimMode } from "../../plug-api/syscalls/editor.ts";
|
||||
|
||||
export function editorSyscalls(client: Client): SysCallMapping {
|
||||
const syscalls: SysCallMapping = {
|
||||
@@ -400,7 +403,16 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
||||
throw new Error("Vim mode not active or not initialized.");
|
||||
}
|
||||
},
|
||||
"editor.vimConfig": () => {
|
||||
"editor.configureVimMode": () => {
|
||||
// Override the default "o" binding to be more intelligent and follow the markdown editor's behavior
|
||||
Vim.mapCommand("o", "action", "newline-continue-markup", {}, {});
|
||||
Vim.defineAction("newline-continue-markup", (cm) => {
|
||||
Vim.handleKey(cm, "A", "+input");
|
||||
insertNewlineContinueMarkup(client.editorView) ||
|
||||
insertNewlineAndIndent(client.editorView);
|
||||
});
|
||||
|
||||
// Load the config if any
|
||||
const config = client.config.get<VimConfig>("vim", {});
|
||||
if (config) {
|
||||
config.unmap?.forEach((binding) => {
|
||||
|
||||
Reference in New Issue
Block a user