@bhsd/codemirror-mediawiki 3.6.7 → 3.7.0
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/dist/codemirror.d.ts +2 -4
- package/dist/fold.js +8 -1
- package/dist/lintsource.d.ts +4 -1
- package/dist/lintsource.js +7 -2
- package/dist/main.min.js +26 -26
- package/dist/matchBrackets.d.ts +6 -0
- package/dist/matchBrackets.js +36 -2
- package/dist/mw.min.js +31 -31
- package/dist/openLinks.js +5 -9
- package/dist/statusBar.js +4 -1
- package/dist/wiki.min.js +31 -31
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/package.json +4 -3
package/dist/matchBrackets.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Extension, EditorState } from '@codemirror/state';
|
|
2
2
|
import type { Config, MatchResult } from '@codemirror/language';
|
|
3
3
|
import type { SyntaxNode } from '@lezer/common';
|
|
4
|
+
export interface Selection {
|
|
5
|
+
anchor: number;
|
|
6
|
+
head: number;
|
|
7
|
+
}
|
|
4
8
|
export declare const findEnclosingBrackets: (node: SyntaxNode, pos: number, brackets: string) => MatchResult | undefined;
|
|
5
9
|
export declare const findEnclosingPlainBrackets: (state: EditorState, pos: number, config: Required<Config>) => MatchResult | null;
|
|
10
|
+
export declare const trySelectMatchingBrackets: (state: EditorState, pos: number, dir: 1 | -1, config?: Config, inside?: boolean) => Selection | false;
|
|
11
|
+
export declare const selectMatchingBrackets: (state: EditorState, pos: number, config?: Config) => Selection | false;
|
|
6
12
|
declare const _default: (configs?: Config) => Extension;
|
|
7
13
|
export default _default;
|
package/dist/matchBrackets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Decoration } from '@codemirror/view';
|
|
1
|
+
import { Decoration, EditorView } from '@codemirror/view';
|
|
2
2
|
import { bracketMatching, matchBrackets, syntaxTree } from '@codemirror/language';
|
|
3
3
|
export const findEnclosingBrackets = (node, pos, brackets) => {
|
|
4
4
|
let parent = node;
|
|
@@ -26,6 +26,20 @@ export const findEnclosingPlainBrackets = (state, pos, config) => {
|
|
|
26
26
|
}
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
|
+
export const trySelectMatchingBrackets = (state, pos, dir, config, inside = false) => {
|
|
30
|
+
if (pos < 0) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const match = matchBrackets(state, pos, dir, config) || false, rightInside = dir === 1 === inside;
|
|
34
|
+
return match && match.matched && {
|
|
35
|
+
anchor: match.start[rightInside ? 'to' : 'from'],
|
|
36
|
+
head: match.end[rightInside ? 'from' : 'to'],
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export const selectMatchingBrackets = (state, pos, config) => trySelectMatchingBrackets(state, pos, -1, config)
|
|
40
|
+
|| trySelectMatchingBrackets(state, pos, 1, config)
|
|
41
|
+
|| trySelectMatchingBrackets(state, pos + 1, -1, config, true)
|
|
42
|
+
|| trySelectMatchingBrackets(state, pos - 1, 1, config, true);
|
|
29
43
|
export default (configs) => {
|
|
30
44
|
const extension = bracketMatching(configs), [{ facet }, [field]] = extension;
|
|
31
45
|
Object.assign(field, {
|
|
@@ -52,5 +66,25 @@ export default (configs) => {
|
|
|
52
66
|
return Decoration.set(decorations, true);
|
|
53
67
|
},
|
|
54
68
|
});
|
|
55
|
-
return
|
|
69
|
+
return [
|
|
70
|
+
extension,
|
|
71
|
+
EditorView.domEventHandlers({
|
|
72
|
+
/**
|
|
73
|
+
* @ignore
|
|
74
|
+
* @todo 由于括号高亮的重绘,双击会被识别为两次单击,导致功能失效
|
|
75
|
+
*/
|
|
76
|
+
dblclick(e, view) {
|
|
77
|
+
const pos = view.posAtCoords(e);
|
|
78
|
+
if (pos === null) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const { state } = view, selection = selectMatchingBrackets(state, pos, state.facet(facet));
|
|
82
|
+
if (selection) {
|
|
83
|
+
view.dispatch({ selection });
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
];
|
|
56
90
|
};
|