@bhsd/codemirror-mediawiki 3.12.0 → 3.12.1

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.
@@ -30,6 +30,11 @@ export declare const trySelectMatchingBrackets: (state: EditorState, pos: number
30
30
  * @test
31
31
  */
32
32
  export declare const selectMatchingBrackets: (state: EditorState, pos: number, config?: Config) => Selection | false;
33
+ /**
34
+ * @ignore
35
+ * @test
36
+ */
37
+ export declare const selectLineBlock: (state: EditorState, pos: number, config?: Config) => Selection | false;
33
38
  /**
34
39
  * @ignore
35
40
  * @test
@@ -56,6 +56,25 @@ export const selectMatchingBrackets = (state, pos, config) => trySelectMatchingB
56
56
  || trySelectMatchingBrackets(state, pos, 1, config)
57
57
  || trySelectMatchingBrackets(state, pos + 1, -1, config, true)
58
58
  || trySelectMatchingBrackets(state, pos - 1, 1, config, true);
59
+ const tryMatchBracetks = (state, pos, config) => matchBrackets(state, pos, -1, config)
60
+ || pos > 0 && matchBrackets(state, pos - 1, 1, config)
61
+ || config.afterCursor && (matchBrackets(state, pos, 1, config)
62
+ || pos < state.doc.length && matchBrackets(state, pos + 1, -1, config));
63
+ /**
64
+ * @ignore
65
+ * @test
66
+ */
67
+ export const selectLineBlock = (state, pos, config) => {
68
+ const { doc } = state, matching = tryMatchBracetks(state, pos, { ...config, afterCursor: true });
69
+ if (!matching || !matching.matched) {
70
+ return false;
71
+ }
72
+ const { start, end } = matching, a = doc.lineAt(start.from), b = doc.lineAt(end.from), dir = a.from < b.from;
73
+ return {
74
+ anchor: (dir ? a : b).from,
75
+ head: Math.min(doc.length, (dir ? b : a).to + 1),
76
+ };
77
+ };
59
78
  /**
60
79
  * @ignore
61
80
  * @test
@@ -67,10 +86,7 @@ export const bracketDeco = (state, config) => {
67
86
  continue;
68
87
  }
69
88
  const tree = syntaxTree(state), excluded = exclude?.(state, head), match = !excluded && // eslint-disable-line @stylistic/operator-linebreak
70
- (matchBrackets(state, head, -1, config)
71
- || head > 0 && matchBrackets(state, head - 1, 1, config)
72
- || afterCursor && (matchBrackets(state, head, 1, config)
73
- || head < state.doc.length && matchBrackets(state, head + 1, -1, config)))
89
+ tryMatchBracetks(state, head, config)
74
90
  || findEnclosingBrackets(tree.resolveInner(head, -1), head, brackets)
75
91
  || afterCursor && findEnclosingBrackets(tree.resolveInner(head, 1), head, brackets)
76
92
  || // eslint-disable-line @stylistic/operator-linebreak
@@ -82,6 +98,19 @@ export const bracketDeco = (state, config) => {
82
98
  }
83
99
  return Decoration.set(decorations, true);
84
100
  };
101
+ const clickHandler = (e, view, facet, select) => {
102
+ const pos = view.posAtCoords(e), { state } = view, config = state.facet(facet);
103
+ if (pos === null
104
+ || config.exclude?.(state, pos)) {
105
+ return false;
106
+ }
107
+ const selection = select(state, pos, config);
108
+ if (selection) {
109
+ view.dispatch({ selection });
110
+ return true;
111
+ }
112
+ return false;
113
+ };
85
114
  export default (configs) => {
86
115
  const extension = bracketMatching(configs), [{ facet }, plugins] = extension;
87
116
  plugins[0] = ViewPlugin.fromClass(class {
@@ -109,22 +138,16 @@ export default (configs) => {
109
138
  return [
110
139
  extension,
111
140
  EditorView.domEventHandlers({
141
+ /** @ignore */
142
+ click(e, view) {
143
+ return e.detail === 3 && clickHandler(e, view, facet, selectLineBlock);
144
+ },
112
145
  /**
113
146
  * @ignore
114
147
  * @todo 由于括号高亮的重绘,双击会被识别为两次单击,导致功能失效
115
148
  */
116
149
  dblclick(e, view) {
117
- const pos = view.posAtCoords(e), { state } = view, config = state.facet(facet);
118
- if (pos === null
119
- || config.exclude?.(state, pos)) {
120
- return false;
121
- }
122
- const selection = selectMatchingBrackets(state, pos, config);
123
- if (selection) {
124
- view.dispatch({ selection });
125
- return true;
126
- }
127
- return false;
150
+ return clickHandler(e, view, facet, selectMatchingBrackets);
128
151
  },
129
152
  }),
130
153
  ];
package/dist/matchTag.js CHANGED
@@ -3,7 +3,7 @@ import { StateField } from '@codemirror/state';
3
3
  import { ensureSyntaxTree } from '@codemirror/language';
4
4
  import { voidHtmlTags, selfClosingTags } from './config.js';
5
5
  import { matchingCls, nonmatchingCls } from './constants.js';
6
- import { sliceDoc } from './util.js';
6
+ import { sliceDoc, pushDecoration } from './util.js';
7
7
  /** @test */
8
8
  export class Tag {
9
9
  get closing() {
@@ -128,15 +128,15 @@ export default /* @__PURE__ */ StateField.define({
128
128
  if (range.empty) {
129
129
  const match = matchTag(state, range.head);
130
130
  if (match) {
131
- const mark = match.matched ? matchingMark : nonmatchingMark, { start: { from, to, closing }, end } = match;
132
- decorations.push(mark.range(from, to));
131
+ const mark = match.matched ? matchingMark : nonmatchingMark, { start, end } = match;
132
+ pushDecoration(decorations, mark, start);
133
133
  if (end) {
134
- decorations[closing ? 'unshift' : 'push'](mark.range(end.from, end.to));
134
+ pushDecoration(decorations, mark, end);
135
135
  }
136
136
  }
137
137
  }
138
138
  }
139
- return Decoration.set(decorations);
139
+ return Decoration.set(decorations, true);
140
140
  },
141
141
  provide(f) {
142
142
  return EditorView.decorations.from(f);