| 1 |
import type { Command } from "@codemirror/view"; |
| 2 |
|
| 3 |
import { put } from "../api"; |
| 4 |
import { notify_err } from "../notifications"; |
| 5 |
import { replaceContents } from "./editor-transactions"; |
| 6 |
|
| 7 |
export const beancountFormat: Command = (cm) => { |
| 8 |
put("format_source", { source: cm.state.sliceDoc() }).then( |
| 9 |
(data) => { |
| 10 |
cm.dispatch(replaceContents(cm.state, data)); |
| 11 |
}, |
| 12 |
(error: unknown) => { |
| 13 |
notify_err(error, (err) => `Formatting source failed: ${err.message}`); |
| 14 |
}, |
| 15 |
); |
| 16 |
return true; |
| 17 |
}; |