diff --git a/common/markdown_parser/parser.ts b/common/markdown_parser/parser.ts index ebcdea5a..ab32b716 100644 --- a/common/markdown_parser/parser.ts +++ b/common/markdown_parser/parser.ts @@ -68,7 +68,8 @@ const WikiLink: MarkdownConfig = { ], }; -export const commandLinkRegex = /^\{\[([^\]\|]+)(\|([^\]]+))?\](\(([^\)]+)\))?\}/; +export const commandLinkRegex = + /^\{\[([^\]\|]+)(\|([^\]]+))?\](\(([^\)]+)\))?\}/; const CommandLink: MarkdownConfig = { defineNodes: [ @@ -107,7 +108,8 @@ const CommandLink: MarkdownConfig = { let argsElts: any[] = []; if (argsPart) { - const argsStartPos = pos + 2 + command.length + (pipePart?.length ?? 0); + const argsStartPos = pos + 2 + command.length + + (pipePart?.length ?? 0); argsElts = [ cx.elt("CommandLinkMark", argsStartPos, argsStartPos + 2), cx.elt( @@ -270,6 +272,8 @@ const directiveEnd = /^\s*\s*/; import { parser as directiveParser } from "./parse-query.js"; import { parser as expressionParser } from "./parse-expression.js"; import { Table } from "./table_parser.ts"; +import { foldNodeProp } from "@codemirror/language"; +import { lezerToParseTree } from "./parse_tree.ts"; export const highlightingDirectiveParser = directiveParser.configure({ props: [ @@ -453,9 +457,19 @@ export default function buildMarkdown(mdExtensions: MDExt[]): Language { Strikethrough, Table, ...mdExtensions.map(mdExtensionSyntaxConfig), - { props: [ + foldNodeProp.add({ + // Don't fold at the list level + BulletList: () => null, + OrderedList: () => null, + // Fold list items + ListItem: (tree, state) => ({ + from: state.doc.lineAt(tree.from).to, + to: tree.to, + }), + }), + styleTags({ Task: ct.TaskTag, TaskMark: ct.TaskMarkTag, diff --git a/plugs/editor/editor.plug.yaml b/plugs/editor/editor.plug.yaml index 198e62d1..40c041d1 100644 --- a/plugs/editor/editor.plug.yaml +++ b/plugs/editor/editor.plug.yaml @@ -146,35 +146,6 @@ functions: path: ./embed.ts:embedWidget codeWidget: embed - # Folding commands - foldCommand: - path: ./editor.ts:foldCommand - command: - name: "Fold: Fold" - mac: "Cmd-Alt-[" - key: "Ctrl-Shift-[" - unfoldCommand: - path: ./editor.ts:unfoldCommand - command: - name: "Fold: Unfold" - mac: "Cmd-Alt-]" - key: "Ctrl-Shift-]" - toggleFoldCommand: - path: ./editor.ts:toggleFoldCommand - command: - name: "Fold: Toggle Fold" - mac: "Cmd-Alt-f" - key: "Ctrl-Alt-f" - foldAllCommand: - path: ./editor.ts:foldAllCommand - command: - name: "Fold: Fold All" - key: "Ctrl-Alt-[" - unfoldAllCommand: - path: ./editor.ts:unfoldAllCommand - command: - name: "Fold: Unfold All" - key: "Ctrl-Alt-]" # Vim toggleVimMode: @@ -227,6 +198,7 @@ functions: command: name: "Upload: File" + # Outline commands outlineMoveUp: path: ./outline.ts:moveItemUp command: @@ -251,6 +223,36 @@ functions: name: "Outline: Move Left" key: "Alt-ArrowLeft" + # Outline folding commands + foldCommand: + path: ./outline.ts:foldCommand + command: + name: "Outline: Fold" + key: "Alt-Shift-ArrowLeft" + unfoldCommand: + path: ./outline.ts:unfoldCommand + command: + name: "Outline: Unfold" + key: "Alt-Shift-ArrowRight" + toggleFoldCommand: + path: ./outline.ts:toggleFoldCommand + command: + name: "Outline: Toggle Fold" + mac: "Alt-Shift-f" + key: "Alt-Shift-f" + foldAllCommand: + path: ./outline.ts:foldAllCommand + command: + name: "Outline: Fold All" + key: "Alt-Shift-ArrowUp" + unfoldAllCommand: + path: ./outline.ts:unfoldAllCommand + command: + name: "Outline: Unfold All" + key: "Alt-Shift-ArrowDown" + + + # Demo customFlashMessage: path: editor.ts:customFlashMessage command: diff --git a/plugs/editor/editor.ts b/plugs/editor/editor.ts index 2d0c401f..26557cb8 100644 --- a/plugs/editor/editor.ts +++ b/plugs/editor/editor.ts @@ -17,26 +17,6 @@ export async function toggleDarkMode() { await editor.reloadUI(); } -export async function foldCommand() { - await editor.fold(); -} - -export async function unfoldCommand() { - await editor.unfold(); -} - -export async function toggleFoldCommand() { - await editor.toggleFold(); -} - -export async function foldAllCommand() { - await editor.foldAll(); -} - -export async function unfoldAllCommand() { - await editor.unfoldAll(); -} - export async function centerCursorCommand() { const pos = await editor.getCursor(); await editor.moveCursor(pos, true); diff --git a/plugs/editor/outline.ts b/plugs/editor/outline.ts index ad42f74a..1161febe 100644 --- a/plugs/editor/outline.ts +++ b/plugs/editor/outline.ts @@ -223,3 +223,23 @@ function determineItemBounds( indentLevel, }; } + +export async function foldCommand() { + await editor.fold(); +} + +export async function unfoldCommand() { + await editor.unfold(); +} + +export async function toggleFoldCommand() { + await editor.toggleFold(); +} + +export async function foldAllCommand() { + await editor.foldAll(); +} + +export async function unfoldAllCommand() { + await editor.unfoldAll(); +}