@bhsd/codemirror-mediawiki 2.6.0 → 2.6.2

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.
@@ -17,37 +17,40 @@ export const textSelection = {
17
17
  return getInstance(this).view.state.doc.toString();
18
18
  },
19
19
  setContents(this: JQuery<HTMLTextAreaElement>, content: string): JQuery<HTMLTextAreaElement> {
20
- getInstance(this).setContent(content);
20
+ const cm = getInstance(this),
21
+ {view: {scrollDOM}} = cm,
22
+ {scrollTop} = scrollDOM;
23
+ cm.setContent(content);
24
+ scrollDOM.scrollTop = scrollTop;
21
25
  return this;
22
26
  },
23
27
  getSelection(this: JQuery<HTMLTextAreaElement>): string {
24
- const {view: {state}} = getInstance(this);
25
- return state.sliceDoc(state.selection.main.from, state.selection.main.to);
28
+ const {view: {state}} = getInstance(this),
29
+ {selection: {main: {from, to}}} = state;
30
+ return state.sliceDoc(from, to);
26
31
  },
27
32
  setSelection(
28
33
  this: JQuery<HTMLTextAreaElement>,
29
- {start, end}: {start: number, end?: number},
34
+ {start, end = start}: {start: number, end?: number},
30
35
  ): JQuery<HTMLTextAreaElement> {
31
- const {view} = getInstance(this);
32
- view.dispatch({
33
- selection: {anchor: start, head: end ?? start},
36
+ getInstance(this).view.dispatch({
37
+ selection: {anchor: start, head: end},
34
38
  });
35
- view.focus();
36
39
  return this;
37
40
  },
38
41
  replaceSelection(this: JQuery<HTMLTextAreaElement>, value: string): JQuery<HTMLTextAreaElement> {
39
- const {view} = getInstance(this),
40
- {state: {selection: {main: {from, to}}}} = view;
41
- view.dispatch({selection: {anchor: from, head: to}});
42
+ const {view} = getInstance(this);
43
+ view.dispatch({selection: view.state.selection.asSingle()});
42
44
  view.dispatch(view.state.replaceSelection(value));
43
45
  return this;
44
46
  },
45
47
  getCaretPosition(this: JQuery<HTMLTextAreaElement>, option?: {startAndEnd?: boolean}): [number, number] | number {
46
- const {view: {state: {selection: {main}}}} = getInstance(this);
47
- return option?.startAndEnd ? [main.from, main.to] : main.head;
48
+ const {view: {state: {selection: {main: {from, to, head}}}}} = getInstance(this);
49
+ return option?.startAndEnd ? [from, to] : head;
48
50
  },
49
51
  scrollToCaretPosition(this: JQuery<HTMLTextAreaElement>): JQuery<HTMLTextAreaElement> {
50
- getInstance(this).view.dispatch({scrollIntoView: true});
52
+ const cm = getInstance(this);
53
+ cm.scrollTo();
51
54
  return this;
52
55
  },
53
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",