Looking at Creating Extensions | Bike, and just checking that I have understood which string values are valid for the source
key in:
.addCommands
.addKeyBinding
these are essentially the name of the source extension, without the @
prefix ?
(I notice, in the example, that the CommandSource
value in the example starts with a capital letter, while the KeybindingSource
value is all lower case. Should we follow that pattern, or is the value matching case-insensitive ?)
A separate question: is there any way of listing the keybindings (and commands) that are currently defined by JS extensions in a given context (editor or dom) ?
I am finding, with the rough draft @Startup
below:
Expand disclosure triangle to view TS source
import { AppExtensionContext } from "bike";
function toggleCollapseCommand(): boolean {
const
editor = bike.frontmostOutlineEditor,
selnRows = editor?.selection!.rows;
return selnRows
? (
// Effect
editor.isCollapsed(selnRows[0])
? editor.expand(selnRows, "completely")
: editor.collapse(selnRows, "row"),
// Value
true
)
: false;
};
export function activate(context: AppExtensionContext) {
bike.commands.addCommands({
source: "startup",
commands: {
"startup:toggle-collapse": toggleCollapseCommand
}
});
bike.keybindings.addKeybindings({
keymap: "block-mode",
source: "startup",
keybindings: {
"t c": "startup:toggle-collapse",
}
});
// bike.keybindings.addKeybindings({
// keymap: "text-mode",
// source: "startup",
// keybindings: {
// "cmd+e": "startup:toggle-collapse",
// }
// });
console.log("Defined ?")
}
That I can trigger startup:toggle-collapse
either:
- in the Safari console with
bike.commands.performCommand("startup:toggle-collapse")
, or
- in Bike 2 Preview (219) block mode with
t c
,
but I don’t seem to be succeeding in binding a key to it text mode (see .addKeyBindings
snippet commented out in the draft above).
Not sure whether this is because toggling collapse is more a block mode operation than a text mode edit, or whether I am just getting something else wrong.