@bhsd/codemirror-mediawiki 2.7.5 → 2.7.7
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 +1 -1
- package/dist/codemirror.d.ts +2 -1
- package/dist/main.min.js +1 -1
- package/dist/mw.min.js +5 -7
- package/dist/mw.min.js.map +3 -3
- package/i18n/en.json +1 -1
- package/i18n/zh-hans.json +1 -1
- package/i18n/zh-hant.json +1 -1
- package/mw/base.ts +1 -1
- package/mw/msg.ts +1 -1
- package/mw/openLinks.ts +5 -3
- package/mw/textSelection.ts +27 -30
- package/package.json +1 -1
package/mw/textSelection.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {CodeMirror} from './base';
|
|
1
|
+
import {CodeMirror} from './base';
|
|
3
2
|
|
|
4
3
|
export const instances = new WeakMap<HTMLTextAreaElement, CodeMirror>();
|
|
5
4
|
|
|
@@ -65,30 +64,32 @@ export const textSelection = {
|
|
|
65
64
|
}: EncapsulateOptions): JQuery<HTMLTextAreaElement> {
|
|
66
65
|
const {view} = getInstance(this),
|
|
67
66
|
{state} = view;
|
|
68
|
-
const handleOwnline = (from: number, to: number, text: string): string => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
}
|
|
77
79
|
}
|
|
78
|
-
return text;
|
|
79
|
-
/* eslint-enable no-param-reassign */
|
|
80
|
+
return [text, start, end];
|
|
80
81
|
};
|
|
81
82
|
if (ownline && replace && !pre && !post && selectionStart === undefined && /^\s*=.*=\s*$/u.test(peri)) {
|
|
82
83
|
// 单独处理改变标题层级
|
|
83
84
|
const {selection: {main: {from, to}}} = state,
|
|
84
|
-
insertText = handleOwnline(from, to, peri);
|
|
85
|
+
[insertText] = handleOwnline(from, to, peri);
|
|
85
86
|
view.dispatch({
|
|
86
87
|
changes: {from, to, insert: insertText},
|
|
87
88
|
selection: {anchor: from + insertText.length},
|
|
88
89
|
});
|
|
89
90
|
return this;
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
+
CodeMirror.replaceSelections(view, (_, {from, to}) => {
|
|
92
93
|
if (selectionStart !== undefined) {
|
|
93
94
|
/* eslint-disable no-param-reassign */
|
|
94
95
|
from = selectionStart;
|
|
@@ -96,21 +97,17 @@ export const textSelection = {
|
|
|
96
97
|
/* eslint-enable no-param-reassign */
|
|
97
98
|
}
|
|
98
99
|
const isSample = selectPeri && from === to,
|
|
99
|
-
selText = replace || from === to ? peri : state.sliceDoc(from, to)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
? {anchor: from + pre.length, head: head - post.length}
|
|
111
|
-
: {anchor: head, head}) as SelectionRange,
|
|
112
|
-
};
|
|
113
|
-
}));
|
|
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];
|
|
110
|
+
});
|
|
114
111
|
return this;
|
|
115
112
|
},
|
|
116
113
|
getCaretPosition(this: JQuery<HTMLTextAreaElement>, option?: {startAndEnd?: boolean}): [number, number] | number {
|