@bhsd/codemirror-mediawiki 2.30.0 → 2.30.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.
@@ -22,7 +22,7 @@ import { tagModes, getStaticMwConfig } from './static';
22
22
  import bidiIsolation from './bidi';
23
23
  import toolKeymap from './keymap';
24
24
  import statusBar from './statusBar';
25
- import { detectIndent, noDetectionLangs } from './indent';
25
+ import { detectIndent } from './indent';
26
26
  import bracketMatching from './matchBrackets';
27
27
  import javascript from './javascript';
28
28
  import css from './css';
@@ -185,8 +185,8 @@ export class CodeMirror6 {
185
185
  textarea.value = doc.toString();
186
186
  textarea.dispatchEvent(new Event('input'));
187
187
  }, 400);
188
- if (!noDetectionLangs.has(this.lang) && !startDoc.toString().trim()) {
189
- this.setIndent(detectIndent(doc.toString(), this.#indentStr, this.lang));
188
+ if (!startDoc.toString().trim()) {
189
+ this.setIndent(this.#indentStr);
190
190
  }
191
191
  }
192
192
  if (focusChanged) {
@@ -335,7 +335,7 @@ export class CodeMirror6 {
335
335
  */
336
336
  setIndent(indent) {
337
337
  if (this.#view) {
338
- this.#effects(this.#indent.reconfigure(indentUnit.of(indent)));
338
+ this.#effects(this.#indent.reconfigure(indentUnit.of(detectIndent(this.#view.state.doc, indent, this.#lang))));
339
339
  }
340
340
  else {
341
341
  this.#indentStr = indent;
package/dist/indent.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export declare const noDetectionLangs: Set<string>;
1
+ import type { Text } from '@codemirror/state';
2
2
  /**
3
3
  * 检测文本的缩进方式
4
4
  * @param text 文本内容
5
5
  * @param defaultIndent 默认缩进方式
6
6
  * @param lang 语言
7
7
  */
8
- export declare const detectIndent: (text: string, defaultIndent: string, lang: string) => string;
8
+ export declare const detectIndent: (text: string | Text, defaultIndent: string, lang: string) => string;
package/dist/indent.js CHANGED
@@ -1,4 +1,4 @@
1
- export const noDetectionLangs = new Set(['plain', 'mediawiki', 'html']);
1
+ const noDetectionLangs = new Set(['plain', 'mediawiki', 'html']);
2
2
  /**
3
3
  * 检测文本的缩进方式
4
4
  * @param text 文本内容
@@ -9,9 +9,9 @@ export const detectIndent = (text, defaultIndent, lang) => {
9
9
  if (noDetectionLangs.has(lang)) {
10
10
  return defaultIndent;
11
11
  }
12
- const lineSpaces = [];
12
+ const lineSpaces = [], lines = typeof text === 'string' ? text.split('\n') : text.text;
13
13
  let tabLines = 0;
14
- for (const line of text.split('\n')) {
14
+ for (const line of lines) {
15
15
  if (!line.trim()) {
16
16
  continue;
17
17
  }