@bhsd/codemirror-mediawiki 2.7.6 → 2.8.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/main.min.js +11 -11
- package/dist/mw.min.js +5 -7
- package/dist/mw.min.js.map +2 -2
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/mediawiki.css +16 -16
- package/mw/base.ts +1 -1
- package/mw/msg.ts +1 -1
- package/mw/textSelection.ts +24 -21
- package/package.json +2 -2
package/mw/textSelection.ts
CHANGED
|
@@ -64,23 +64,25 @@ export const textSelection = {
|
|
|
64
64
|
}: EncapsulateOptions): JQuery<HTMLTextAreaElement> {
|
|
65
65
|
const {view} = getInstance(this),
|
|
66
66
|
{state} = view;
|
|
67
|
-
const handleOwnline = (from: number, to: number, text: string): string => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
const handleOwnline = (from: number, to: number, text: string): [string, number, number] => {
|
|
68
|
+
let start = 0,
|
|
69
|
+
end = 0;
|
|
70
|
+
if (ownline) {
|
|
71
|
+
if (from > 0 && !/[\n\r]/u.test(state.sliceDoc(from - 1, from))) {
|
|
72
|
+
text = `\n${text}`; // eslint-disable-line no-param-reassign
|
|
73
|
+
start = 1;
|
|
74
|
+
}
|
|
75
|
+
if (!/[\n\r]/u.test(state.sliceDoc(to, to + 1))) {
|
|
76
|
+
text += '\n'; // eslint-disable-line no-param-reassign
|
|
77
|
+
end = 1;
|
|
78
|
+
}
|
|
76
79
|
}
|
|
77
|
-
return text;
|
|
78
|
-
/* eslint-enable no-param-reassign */
|
|
80
|
+
return [text, start, end];
|
|
79
81
|
};
|
|
80
82
|
if (ownline && replace && !pre && !post && selectionStart === undefined && /^\s*=.*=\s*$/u.test(peri)) {
|
|
81
83
|
// 单独处理改变标题层级
|
|
82
84
|
const {selection: {main: {from, to}}} = state,
|
|
83
|
-
insertText = handleOwnline(from, to, peri);
|
|
85
|
+
[insertText] = handleOwnline(from, to, peri);
|
|
84
86
|
view.dispatch({
|
|
85
87
|
changes: {from, to, insert: insertText},
|
|
86
88
|
selection: {anchor: from + insertText.length},
|
|
@@ -95,15 +97,16 @@ export const textSelection = {
|
|
|
95
97
|
/* eslint-enable no-param-reassign */
|
|
96
98
|
}
|
|
97
99
|
const isSample = selectPeri && from === to,
|
|
98
|
-
selText = replace || from === to ? peri : state.sliceDoc(from, to)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
selText = replace || from === to ? peri : state.sliceDoc(from, to),
|
|
101
|
+
[insertText, start, end] = handleOwnline(
|
|
102
|
+
from,
|
|
103
|
+
to,
|
|
104
|
+
splitlines
|
|
105
|
+
? selText.split('\n').map(line => `${pre}${line}${post}`).join('\n')
|
|
106
|
+
: `${pre}${selText}${post}`,
|
|
107
|
+
),
|
|
108
|
+
head = from + insertText.length;
|
|
109
|
+
return isSample ? [insertText, from + pre.length + start, head - post.length - end] : [insertText, head];
|
|
107
110
|
});
|
|
108
111
|
return this;
|
|
109
112
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-mediawiki",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@codemirror/state": "^6.4.1",
|
|
54
54
|
"@codemirror/view": "^6.24.1",
|
|
55
55
|
"@lezer/highlight": "^1.2.0",
|
|
56
|
-
"wikiparser-node": "^1.5.
|
|
56
|
+
"wikiparser-node": "^1.5.7"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@lezer/common": "^1.1.2",
|