Fixes #495
parent
8112616cb2
commit
40dc50f782
|
@ -43,7 +43,11 @@ export {
|
||||||
|
|
||||||
export type { NodeType, SyntaxNode, SyntaxNodeRef, Tree } from "@lezer/common";
|
export type { NodeType, SyntaxNode, SyntaxNodeRef, Tree } from "@lezer/common";
|
||||||
|
|
||||||
export { searchKeymap } from "@codemirror/search";
|
export {
|
||||||
|
closeSearchPanel,
|
||||||
|
openSearchPanel,
|
||||||
|
searchKeymap,
|
||||||
|
} from "@codemirror/search";
|
||||||
export {
|
export {
|
||||||
Decoration,
|
Decoration,
|
||||||
drawSelection,
|
drawSelection,
|
||||||
|
|
|
@ -178,3 +178,7 @@ export function foldAll() {
|
||||||
export function unfoldAll() {
|
export function unfoldAll() {
|
||||||
return syscall("editor.unfoldAll");
|
return syscall("editor.unfoldAll");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function openSearchPanel() {
|
||||||
|
return syscall("editor.openSearchPanel");
|
||||||
|
}
|
||||||
|
|
|
@ -270,11 +270,18 @@ functions:
|
||||||
command:
|
command:
|
||||||
name: "Outline: Unfold All"
|
name: "Outline: Unfold All"
|
||||||
key: "Ctrl-Alt-Shift-]"
|
key: "Ctrl-Alt-Shift-]"
|
||||||
|
findInPageCommand:
|
||||||
|
path: editor.ts:findInPageCommand
|
||||||
|
command:
|
||||||
|
name: "Editor: Find in Page"
|
||||||
|
key: "Ctrl-f"
|
||||||
|
mac: "Cmd-f"
|
||||||
|
|
||||||
# Demo
|
# Demo
|
||||||
customFlashMessage:
|
customFlashMessage:
|
||||||
path: editor.ts:customFlashMessage
|
path: editor.ts:customFlashMessage
|
||||||
command:
|
command:
|
||||||
name: "Flash: Custom Message"
|
name: "Flash: Custom Message"
|
||||||
|
hide: true
|
||||||
contexts:
|
contexts:
|
||||||
- internal
|
- internal
|
|
@ -51,3 +51,8 @@ export async function reloadSettingsAndCommands() {
|
||||||
await editor.reloadSettingsAndCommands();
|
await editor.reloadSettingsAndCommands();
|
||||||
await editor.flashNotification("Reloaded settings and commands");
|
await editor.flashNotification("Reloaded settings and commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function findInPageCommand() {
|
||||||
|
await editor.openSearchPanel();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -287,9 +287,11 @@ export function createCommandKeyBindings(client: Client): KeyBinding[] {
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
).then(() => {
|
).then((returnValue: any) => {
|
||||||
// Always be focusing the editor after running a command
|
// Always be focusing the editor after running a command
|
||||||
|
if (returnValue !== false) {
|
||||||
client.focus();
|
client.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -322,11 +324,13 @@ export function createCommandKeyBindings(client: Client): KeyBinding[] {
|
||||||
`Error running command: ${e.message}`,
|
`Error running command: ${e.message}`,
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
})
|
}).then((returnValue: any) => {
|
||||||
.then(() => {
|
|
||||||
// Always be focusing the editor after running a command
|
// Always be focusing the editor after running a command
|
||||||
|
if (returnValue !== false) {
|
||||||
client.focus();
|
client.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -342,7 +346,6 @@ export function createKeyBindings(client: Client): Extension {
|
||||||
...smartQuoteKeymap,
|
...smartQuoteKeymap,
|
||||||
...closeBracketsKeymap,
|
...closeBracketsKeymap,
|
||||||
...standardKeymap,
|
...standardKeymap,
|
||||||
...searchKeymap,
|
|
||||||
...historyKeymap,
|
...historyKeymap,
|
||||||
...completionKeymap,
|
...completionKeymap,
|
||||||
indentWithTab,
|
indentWithTab,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { TopBar } from "./components/top_bar.tsx";
|
||||||
import reducer from "./reducer.ts";
|
import reducer from "./reducer.ts";
|
||||||
import { Action, AppViewState, initialViewState } from "./types.ts";
|
import { Action, AppViewState, initialViewState } from "./types.ts";
|
||||||
import {
|
import {
|
||||||
|
closeSearchPanel,
|
||||||
featherIcons,
|
featherIcons,
|
||||||
preactRender,
|
preactRender,
|
||||||
runScopeHandlers,
|
runScopeHandlers,
|
||||||
|
@ -27,7 +28,13 @@ export class MainUI {
|
||||||
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
||||||
globalThis.addEventListener("keydown", (ev) => {
|
globalThis.addEventListener("keydown", (ev) => {
|
||||||
if (!client.editorView.hasFocus) {
|
if (!client.editorView.hasFocus) {
|
||||||
if ((ev.target as any).closest(".cm-content")) {
|
const target = ev.target as HTMLElement;
|
||||||
|
if (target.className === "cm-textfield" && ev.key === "Escape") {
|
||||||
|
// Search panel is open, let's close it
|
||||||
|
console.log("Closing search panel");
|
||||||
|
closeSearchPanel(client.editorView);
|
||||||
|
return;
|
||||||
|
} else if (target.closest(".cm-content")) {
|
||||||
// In some cm element, let's back out
|
// In some cm element, let's back out
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -119,9 +126,6 @@ export class MainUI {
|
||||||
<CommandPalette
|
<CommandPalette
|
||||||
onTrigger={(cmd) => {
|
onTrigger={(cmd) => {
|
||||||
dispatch({ type: "hide-palette" });
|
dispatch({ type: "hide-palette" });
|
||||||
setTimeout(() => {
|
|
||||||
client.focus();
|
|
||||||
});
|
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
dispatch({ type: "command-run", command: cmd.command.name });
|
dispatch({ type: "command-run", command: cmd.command.name });
|
||||||
cmd
|
cmd
|
||||||
|
@ -129,9 +133,11 @@ export class MainUI {
|
||||||
.catch((e: any) => {
|
.catch((e: any) => {
|
||||||
console.error("Error running command", e.message);
|
console.error("Error running command", e.message);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then((returnValue: any) => {
|
||||||
// Always be focusing the editor after running a command
|
// Always be focusing the editor after running a command
|
||||||
|
if (returnValue !== false) {
|
||||||
client.focus();
|
client.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { SysCallMapping } from "../../plugos/system.ts";
|
||||||
import type { FilterOption } from "../types.ts";
|
import type { FilterOption } from "../types.ts";
|
||||||
import { UploadFile } from "../../plug-api/types.ts";
|
import { UploadFile } from "../../plug-api/types.ts";
|
||||||
import { PageRef } from "$sb/lib/page.ts";
|
import { PageRef } from "$sb/lib/page.ts";
|
||||||
|
import { openSearchPanel } from "../deps.ts";
|
||||||
|
|
||||||
export function editorSyscalls(client: Client): SysCallMapping {
|
export function editorSyscalls(client: Client): SysCallMapping {
|
||||||
const syscalls: SysCallMapping = {
|
const syscalls: SysCallMapping = {
|
||||||
|
@ -268,6 +269,9 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
||||||
"editor.unfoldAll": () => {
|
"editor.unfoldAll": () => {
|
||||||
unfoldAll(client.editorView);
|
unfoldAll(client.editorView);
|
||||||
},
|
},
|
||||||
|
"editor.openSearchPanel": () => {
|
||||||
|
openSearchPanel(client.editorView);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return syscalls;
|
return syscalls;
|
||||||
|
|
Loading…
Reference in New Issue