@bhsd/codemirror-mediawiki 3.6.2 → 3.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![npm version](https://badge.fury.io/js/@bhsd%2Fcodemirror-mediawiki.svg)](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
2
+ [![CodeQL](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml/badge.svg)](https://github.com/bhsd-harry/codemirror-mediawiki/actions/workflows/codeql.yml)
2
3
  [![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/npm/hm/%40bhsd/codemirror-mediawiki)](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki)
3
4
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/972fd5f6684c4fd8ac2f26e01d349948)](https://app.codacy.com/gh/bhsd-harry/codemirror-mediawiki/dashboard)
4
5
 
package/dist/fold.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface DocRange {
15
15
  */
16
16
  export declare const foldable: (state: EditorState, posOrNode: number | SyntaxNode, tree?: Tree | null, refOnly?: boolean) => DocRange | false;
17
17
  export declare const foldableLine: ({ state, viewport: { to: end }, viewportLineBlocks }: EditorView, { from: f, to: t }: DocRange) => DocRange | false;
18
- export declare const foldRef: Command;
18
+ export declare const foldRef: Command, unfoldRef: Command;
19
19
  declare const _default: (e?: Extension | undefined) => Extension;
20
20
  export default _default;
21
21
  export declare const mediaWikiFold: Extension;
package/dist/fold.js CHANGED
@@ -321,10 +321,23 @@ const defaultFoldExtension = /* @__PURE__ */ (() => [foldGutter(), keymap.of(fol
321
321
  * @param refOnly 是否仅检查`<ref>`标签
322
322
  */
323
323
  const foldCommand = (refOnly) => view => {
324
- const { state } = view, tree = syntaxTree(state), effects = [], anchor = traverse(state, tree, effects, tree.topNode.firstChild, Infinity, getAnchor(state), updateAll, refOnly);
324
+ const { state } = view, tree = ensureSyntaxTree(state, state.doc.length, 1e3) ?? syntaxTree(state), effects = [], anchor = traverse(state, tree, effects, tree.topNode.firstChild, Infinity, getAnchor(state), updateAll, refOnly);
325
325
  return execute(view, effects, anchor);
326
326
  };
327
- export const foldRef = /* @__PURE__ */ foldCommand(true);
327
+ export const foldRef = /* @__PURE__ */ foldCommand(true), unfoldRef = (view) => {
328
+ const { state } = view, tree = syntaxTree(state), effects = [];
329
+ foldedRanges(state).between(0, state.doc.length, (i, j) => {
330
+ const node = tree.resolve(i, -1);
331
+ if (isExtBracket(node) && isExt(node.nextSibling, true)) {
332
+ effects.push(unfoldEffect.of({ from: i, to: j }));
333
+ }
334
+ });
335
+ if (effects.length > 0) {
336
+ view.dispatch({ effects });
337
+ return true;
338
+ }
339
+ return false;
340
+ };
328
341
  export default ((e = defaultFoldExtension) => e);
329
342
  export const mediaWikiFold = /* @__PURE__ */ (() => [
330
343
  codeFolding({