Add more internal links and precisions on command arguments

This commit is contained in:
Igor Támara 2025-10-31 08:53:12 -05:00 committed by CJ van den Berg
parent 0494574c36
commit b01dfdb992
4 changed files with 53 additions and 30 deletions

View file

@ -69,7 +69,7 @@ in Vim Mode `vim.zig`, `q` corresponds to (quit), the most famous one.
```zig
pub fn q(_: *void, _: Ctx) Result {
try cmd("quit", .{});
try command.cmd("quit", .{});
}
pub const q_meta: Meta = .{ .description = "q (quit)" };
```
@ -122,14 +122,14 @@ pub fn select_to_char_left_helix(_: *void, ctx: Ctx) Result {
`goto_line` (in the case of vim and helix mode, you first type the
number and then the action, `gg`) is a command that exemplifies
receiving an integer parameter as stated in its meta:
receiving an integer parameter. As stated in its meta:
```zig
pub const goto_line_meta: Meta = .{ .arguments = &.{.integer} };
```
and to actually receiving the integer parameter, `goto_line` will
extract it like this:
extract from the context like this:
```zig
pub fn goto_line(self: *Self, ctx: Context) Result {
@ -140,9 +140,17 @@ pub fn goto_line(self: *Self, ctx: Context) Result {
```
To send a parameter to a command, make sure that the type is exactly
the same when retrieving it. We will refer as encode and decode. Hence
for our terminology to send an integer parameter to a command, we
will encode it using `command.fmt` like in
the same when retrieving it. We will refer as encode and decode when
packing parameters in the context. To pack the `command.fmt` we will
encode it like this, when invoking `goto_line`.
```zig
var the_line: usize = 43;
try command.cmd("goto_line", command.fmt(.{the_line - 1}));
```
Or calling the command directly, if we have a reference to the object
that holds the command.
```zig
var the_line: usize = 43;
@ -150,10 +158,12 @@ try ed.goto_line(command.fmt(.{the_line - 1}));
```
It's possible to pass multiple parameters to commands, including arrays
and json, they all will be packed in Command.Context.
and json, packing all of them in Command.Context.
A deeper explanation of the rules about parameter passing is exposed in
[inner data exchange](/docs/architecture/inner_data_exchange).
[inner data exchange](/docs/architecture/inner_data_exchange), given
that parameters can be sent not only to commands, but other broather
use cases.
[]($section.id('next'))
## Next steps

View file

@ -12,29 +12,38 @@
If you are here, maybe is because you want to make flow behave according
to your key presses preferences or possibly you already have edited your
own keybinds to suit your needs and are looking for some advanced
topics to cope your use cases and make everything easier, faster and
fluid when in Flow.
own keybinds to suit your use cases and make everything easier, faster
and more fluid when in flow.
First make sure you are aware of the
[existence of ctrl+f2 palette](/docs#key_controls) which
exposes a list of commands available for you to use, and when you select
a command, it's pasted in your current cursor position.
Using the command palette `Ctrl+Shift+p` and typing **Edit key
bindings**, takes you to a json file to extend Flow, configuring
keybindings to suit your needs. According to the mode you are in, the
corresponding file will be opened. The palette can also be reached left
clicking on the current mode in the status bar.
bindings**, takes you to a json file to extend flow, configuring
keybindings to suit your needs. According to the mode you are in, your
personal mode's file configuration will be opened. Explore the
the file to discover how commands are bound to some combos, key presses
and the different [imodes](#hierarchy) present.
Command palette can also be reached left clicking on the current
mode in the status bar.
[]($section.id('tldr'))
## ;TLDR;
Once you open the corresponding json file, locate inside the imode
(internal mode) that will accept the key or key/combos and add an array,
where the first element is the combination to map to the commands that
will be invoked, the array accepts strings like in
Once you open the corresponding json file, locate inside the
[imode](#hierarchy)(internal mode) that will accept the key or
key/combos and add an array, where the first element is the combination
to map to the commands that will be invoked, the array accepts strings
like in
```js
["ctrl+alt+shift+p", "open_command_palette"]
```
To avoid screwing up the combinations, and putting Flow in an unusable
To avoid screwing up the combinations, and putting flow in an unusable
state derived from a wrong mapping of key combinations, read on.
[]($section.id('defaults'))
@ -154,11 +163,12 @@ consider using more keybindings or running tasks for your projects.
If you realized that there is a handy combination that others can
benefit from or that a mode lacks the combination and it might be
included in flow, look at the [contribution guidelines](/docs/contributing)
to submit your findings and solution.
included in flow, look at the
[contribution guidelines](/docs/contributing) to submit your findings
and solutions.
Probably binding commands is good, but maybe there is a feature in other
text editors that you miss and would love to have it at your fingertips.
text editors that you miss and would love to have at your fingertips.
Then it's Zig time: [Adding commands](/docs/architecture/command) to
flow.