Skip to content

Commit 4f4366e

Browse files
committed
sync the apis
1 parent 812d8cd commit 4f4366e

6 files changed

Lines changed: 300 additions & 95 deletions

File tree

‎.vitepress/config.mts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ export default defineConfig({
200200
text: "Commands",
201201
link: "/docs/utilities/commands",
202202
},
203+
{
204+
text: "CodeMirror packages",
205+
link: "/docs/utilities/codemirror",
206+
},
203207
{
204208
text: "Editor Languages",
205209
link: "/docs/utilities/ace-modes",

‎docs/editor-components/editor-file.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Both methods are equivalent and accept & return the same parameters.
5252
| content | string \| [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement) | Custom content element or HTML string. Strings are sanitized using DOMPurify | - |
5353
| stylesheets | `string\|string[]` | Custom stylesheets for tab. Can be URL, or CSS string | - |
5454
| hideQuickTools | `boolean` | Whether to hide quicktools for this tab | `false` |
55+
| pinned | `boolean` | Pin the tab to prevent accidental closing | `false` |
56+
| readOnly | `boolean` | Open the file as read-only | `false` |
57+
| paneId | `string` | Target editor pane id (multi-pane layout) | - |
58+
| pane | `object` | Target editor pane instance (multi-pane layout) | - |
59+
| isPanePlaceholder | `boolean` | Temporary empty tab for an empty pane | `false` |
5560

5661
## Properties
5762

‎docs/global-apis/ace.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This page exists for plugin migration from Ace-era APIs.
1010
- Use `acode.require("commands")` for command registration/removal.
1111
- Use `acode.require("editorLanguages")` to register or remove language modes.
1212
- Use `acode.require("editorThemes")` to register or apply editor themes.
13+
- Use `acode.require("codemirror")` (or `@codemirror/*` / `@lezer/*`) for the same CodeMirror packages the app uses — see [CodeMirror packages](../utilities/codemirror.md).
1314
- Use `editorManager.isCodeMirror` to check whether current acode uses codemirror or ace, if its true then its codemirror and if it is null or undefined then its ace.
1415

1516
## Legacy Compatibility

‎docs/global-apis/editor-manager.md‎

Lines changed: 195 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,37 @@
22

33
## `window.editorManager` or `editorManager`
44

5-
The `editorManager` allows to interact with the Editor Instance and listen to various events of Acode app with the help of various methods and Properties. Basically for interacting with the opened files and tabs.
5+
The `editorManager` allows you to interact with the editor instance and listen to app-level editor events. Use it for open files/tabs, multi-pane layout, and the active CodeMirror view.
66

7-
## Methods and Properties
7+
## Core properties
88

99
### `editor`
10-
This is the active **CodeMirror `EditorView`** instance.
10+
11+
Active **CodeMirror `EditorView`** for the focused pane.
1112

1213
Read text:
14+
1315
```javascript
1416
const text = editorManager.editor.state.doc.toString();
1517
```
1618

1719
Update text:
20+
1821
```javascript
1922
const view = editorManager.editor;
2023
view.dispatch({
2124
changes: { from: 0, to: view.state.doc.length, insert: "new content" },
2225
});
2326
```
2427

25-
Add a command:
26-
```javascript
27-
// Compatibility API
28-
editorManager.editor.commands.addCommand({
29-
name: "my-command",
30-
description: "My command",
31-
exec: () => console.log("Run"),
32-
});
33-
```
34-
35-
Remove a command:
36-
```javascript
37-
// Compatibility API
38-
editorManager.editor.commands.removeCommand("my-command");
39-
```
40-
4128
::: tip
4229
Prefer `acode.require("commands")` for command registration/removal in new plugins.
4330
See: [Commands API](../utilities/commands.md)
4431
:::
4532

4633
Compatibility helpers are also available for legacy plugins:
4734

48-
- `editor.session` (Ace-style session proxy for active file)
35+
- `editor.session` (Ace-style session proxy for the active file)
4936
- `editor.getValue()`
5037
- `editor.gotoLine(...)`
5138
- `editor.insert(text)`
@@ -54,77 +41,194 @@ Compatibility helpers are also available for legacy plugins:
5441
- `editor.selection.getRange()`
5542
- `editor.getCopyText()`
5643

57-
### `addNewFile(filename?:string, options?: object)`
58-
This function adds a new file to the workspace.
59-
60-
- `filename: string`: the name of the file.
61-
- `options?: object`: an optional object that can be passed with the following properties:
62-
- `text: string`: the file text content.
63-
- `isUnsaved: boolean`: whether the file is unsaved.
64-
- `render: boolean`: whether to switch to this file.
65-
- `id: string`: a unique id for the file.
66-
- `uri: string`: the file's uri, or location.
67-
- `record`: Record
68-
- `deletedFile: boolean`: whether the file is deleted.
69-
- `readOnly: boolean`: whether the file is read-only
70-
- `mode: string`: the SAF (Storage access framework) mode (TREE | SINGLE).
71-
- `type: string`: the file type (regular | git | gist).
72-
- `encoding: string`: the file encoding.
73-
- `onsave: ()=>void`: callback function called when the file is saved.
74-
75-
### `getFile(test: any, type: string)`
76-
This function gets files from the list of opened files.
77-
* `test: object`: the file id, uri, repo, or gist to find the file.
78-
* `type: string`: the type of test (uri | id | name | git | gist).
79-
80-
### `switchFile(id: string)`
81-
This function switches the tab to the given file id.
82-
83-
### `activeFile: object`
84-
This property returns the current file data as object.
85-
86-
### `hasUnsavedFiles(): number`
87-
This function returns the number of unsaved files.
88-
89-
### `files: Array<object>`
90-
This property returns a list of all files.
91-
92-
### `setSubText(file: File)`
93-
This function sets the sub text of the header, i.e. the location of the file.
94-
95-
### `container: HTMLElement`
96-
This property returns the container of the editor.
97-
98-
### `on(event: string, listener(): void)`
99-
This function adds a listener for the specified event.
100-
101-
### `off(event: string, listener(): void)`
102-
This function removes a listener for the specified event.
103-
104-
### `emit(event: string, ...args: ...any)`
105-
This function emits an event with the specified arguments.
106-
107-
### `isScrolling: boolean`
108-
Weather the editor is currently scrolling.
109-
110-
## List of events:
111-
112-
* `switch-file`
113-
* `rename-file`
114-
* `save-file`
115-
* `file-loaded`
116-
* `file-content-changed`
117-
* `add-folder`
118-
* `remove-folder`
119-
* `new-file`
120-
* `init-open-file-list`
121-
* `update`
122-
123-
Here is an example on how to listen to an example event:
44+
### `isCodeMirror: boolean`
45+
46+
`true` on modern Acode builds that use CodeMirror 6.
47+
48+
### `activeFile: EditorFile | null`
49+
50+
Currently focused file/tab.
51+
52+
### `files: EditorFile[]`
53+
54+
All open files across every pane.
55+
56+
### `container: HTMLElement`
57+
58+
Editor container of the **active pane**. Prefer this over assuming a single global editor DOM node when split panes are open.
59+
60+
### `header`
61+
62+
Editor header tile. You can set subtitle text with `editorManager.header.subText = "..."`.
63+
64+
### `openFileList: HTMLElement`
65+
66+
Open-file tab list (pane-aware when multi-pane layout is active).
67+
68+
### `isScrolling: boolean`
69+
70+
Whether the active editor is currently scrolling.
71+
72+
## Opening files
73+
74+
There is no `editorManager.addNewFile` API. Create tabs with:
75+
76+
```javascript
77+
const EditorFile = acode.require("EditorFile");
78+
79+
// Preferred
80+
new EditorFile("example.js", {
81+
text: "console.log('hi')",
82+
render: true,
83+
});
84+
85+
// Or via acode
86+
acode.newEditorFile("example.js", {
87+
text: "console.log('hi')",
88+
render: true,
89+
});
90+
```
91+
92+
See [Editor File](../editor-components/editor-file.md) for full options (`pinned`, `paneId`, custom tabs, etc.).
93+
94+
### `addFile(file: EditorFile)`
95+
96+
Registers an already-constructed `EditorFile` instance with the manager (used internally and by advanced plugins).
97+
98+
### `getFile(test, type)`
99+
100+
Finds an open file.
101+
102+
- `test`: id, uri, name, git, or gist key
103+
- `type`: `"uri" | "id" | "name" | "git" | "gist"`
104+
105+
### `switchFile(id: string)`
106+
107+
Switches the active tab to the given file id.
108+
109+
### `hasUnsavedFiles(): number`
110+
111+
Returns the number of unsaved files.
112+
113+
## Multi-pane layout
114+
115+
Acode supports side-by-side / stacked editor panes. Each pane has its own CodeMirror instance, tab list, and active file.
116+
117+
### Properties
118+
119+
| Property | Description |
120+
|---|---|
121+
| `activePane` | Currently focused pane |
122+
| `panes` | Array snapshot of all panes |
123+
| `activePaneTabList` | Tab list element for the active pane |
124+
125+
### Creating and closing panes
126+
127+
```javascript
128+
// Split active pane to the right
129+
const right = await editorManager.splitPaneRight();
130+
131+
// Split below
132+
const below = await editorManager.splitPaneDown();
133+
134+
// Or with options
135+
const pane = await editorManager.createPane({
136+
direction: "horizontal", // "horizontal" | "vertical" | "right" | "down" | "below"
137+
moveFile: editorManager.activeFile, // optional: move current file into the new pane
138+
createUntitled: true, // default true when moveFile is not set
139+
});
140+
141+
// Close panes
142+
editorManager.closeActivePane();
143+
editorManager.closeEmptyPane(pane);
144+
```
145+
146+
`createPane` / `splitPane*` resolve to the new pane object, or `null` when there is not enough space.
147+
148+
### Focusing panes
149+
150+
```javascript
151+
editorManager.focusNextPane();
152+
editorManager.focusPreviousPane();
153+
editorManager.focusPaneByDirection("left"); // "left" | "right" | "up" | "down"
154+
editorManager.setActivePane(pane);
155+
```
156+
157+
### Moving files between panes
158+
159+
```javascript
160+
await editorManager.moveActiveFileToNewPane("vertical");
161+
162+
editorManager.moveFileToPane(file, targetPane, {
163+
activate: true,
164+
});
165+
166+
editorManager.removeFileFromPane(file);
167+
editorManager.getFilePane(file); // pane hosting the file, or null
168+
editorManager.getPaneFiles(pane); // files in a pane
169+
```
170+
171+
### Pin helpers
172+
173+
Pinned tabs stay grouped at the front of a pane's tab list:
174+
175+
```javascript
176+
file.setPinnedState(true, { reorder: true });
177+
editorManager.moveFileByPinnedState(file);
178+
editorManager.normalizePinnedTabOrder(pane);
179+
```
180+
181+
## Tab history
182+
183+
```javascript
184+
editorManager.openPreviousEditorFromHistory();
185+
editorManager.openNextEditorFromHistory();
186+
editorManager.recordHistory(file); // usually automatic on switch
187+
```
188+
189+
## LSP / cache helpers
190+
124191
```javascript
125-
function listener(){
126-
console.log("user has switched a file")
127-
}
192+
// Restart language clients for the active editor file
193+
editorManager.restartLsp();
128194

129-
editorManager.on("switch-file", listener) // listens to file switch event
195+
// Flush pending crash-cache writes for open editor files
196+
await editorManager.flushCacheWrites();
197+
```
198+
199+
## Events
200+
201+
### `on(event, listener)` / `off(event, listener)` / `emit(event, ...args)`
202+
203+
| Event | Description |
204+
|---|---|
205+
| `switch-file` | Active file changed |
206+
| `rename-file` | File renamed |
207+
| `save-file` | File saved |
208+
| `file-loaded` | File finished loading |
209+
| `file-content-changed` | File content changed |
210+
| `add-folder` | Workspace folder added |
211+
| `remove-folder` | Workspace folder removed |
212+
| `update-folder` | Workspace folder updated |
213+
| `new-file` | New file created |
214+
| `init-open-file-list` | Open file list initialized |
215+
| `remove-file` | File removed |
216+
| `update` | Generic update (often with a sub-action) |
217+
218+
`update` listeners may receive a sub-action as the first argument, for example:
219+
220+
- `"pin-tab"`
221+
- `"switch-file"`
222+
- `"read-only"`
223+
224+
```javascript
225+
editorManager.on("switch-file", () => {
226+
console.log("user switched file", editorManager.activeFile?.filename);
227+
});
228+
229+
editorManager.on("update", (action, file) => {
230+
if (action === "pin-tab") {
231+
console.log("pin state changed", file?.filename, file?.pinned);
232+
}
233+
});
130234
```

‎docs/ui-components/dialogs/color-picker.md‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,28 @@ In this example, the color picker dialog box will open with the default color se
2828

2929
## Returns
3030

31-
The `colorPicker` component returns a promise that resolves to a string representing the `selected color`. This color can then be used in your plugin based on user input.
31+
The `colorPicker` component returns a promise that:
32+
33+
- **resolves** to a string representing the selected color (hex / rgb / hsl, including alpha when used)
34+
- **rejects** with `Error("cancelled")` when the user taps Cancel, the mask, or otherwise dismisses the dialog
35+
36+
The dialog also includes a format toggle (HEX / RGB / HSL).
3237

3338
## Example
3439

3540
```javascript:line-numbers{1,3}
3641
const colorPicker = acode.require('colorPicker');
3742
38-
let selectedColor = await colorPicker('#ff0000');
39-
console.log(`Selected Color: ${selectedColor}`);
43+
try {
44+
const selectedColor = await colorPicker('#ff0000');
45+
console.log(`Selected Color: ${selectedColor}`);
46+
} catch (err) {
47+
if (err?.message === 'cancelled') {
48+
console.log('User cancelled the color picker');
49+
} else {
50+
throw err;
51+
}
52+
}
4053
```
4154

42-
In this example, the `colorPicker` component is used to open a color picker dialog box with the default color set to red. The selected color is then logged to the console, demonstrating how to retrieve and utilize the user's color selection.
55+
In this example, the `colorPicker` component opens with red as the default. The selected color is logged, or cancellation is handled explicitly.

0 commit comments

Comments
 (0)