Skip to content

Commit 4b52e8d

Browse files
committed
Fix command docs
1 parent 117e8a0 commit 4b52e8d

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

docs/guides/commands.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,33 @@ export default class ExamplePlugin extends Plugin {
3030

3131
If your command is only able to run under certain conditions, then consider using [`checkCallback`](../api/interfaces/Command.md#checkcallback) instead.
3232

33-
When using the `checkCallback`, Obsidian first performs a _check_ to see whether the command can run. To determine whether the callback should perform a check or an action, a `checking` argument is passed to the callback.
33+
The `checkCallback` runs twice. First, to perform a preliminary check to determine whether the command can run. Second, to perform the action.
3434

35-
- If `checking` is set to `true`, perform a check.
35+
Since time may pass between the two runs, you need to perform the check during both calls.
36+
37+
To determine whether the callback should perform a preliminary check or an action, a `checking` argument is passed to the callback.
38+
39+
- If `checking` is set to `true`, perform a preliminary check.
3640
- If `checking` is set to `false`, perform an action.
3741

42+
The command in the following example depends on a required value. In both runs, the callback checks that the value is present but only performs the action if `checking` is `false`.
43+
3844
```ts {4}
3945
this.addCommand({
4046
id: 'example-command',
4147
name: 'Example command',
4248
checkCallback: (checking: boolean) => {
43-
if (checking) {
44-
return isCommandPossible();
45-
}
49+
const value = getRequiredValue();
4650

47-
doCommand();
51+
if (value) {
52+
if (!checking) {
53+
doCommand(value);
54+
}
4855

49-
return true;
56+
return true
57+
}
58+
59+
return false;
5060
},
5161
});
5262
```
@@ -78,13 +88,17 @@ this.addCommand({
7888
id: 'example-command',
7989
name: 'Example command',
8090
editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => {
81-
if (checking) {
82-
return isCommandPossible();
83-
}
91+
const value = getRequiredValue();
8492

85-
doCommand();
93+
if (value) {
94+
if (!checking) {
95+
doCommand(value);
96+
}
97+
98+
return true
99+
}
86100

87-
return true;
101+
return false;
88102
},
89103
});
90104
```

0 commit comments

Comments
 (0)