@codemirror/language 6.1.0 → 6.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 6.2.0 (2022-06-30)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that prevented bracket matching to recognize plain brackets inside a language parsed as an overlay.
6
+
7
+ ### New features
8
+
9
+ The `indentRange` function provides an easy way to programatically auto-indent a range of the document.
10
+
1
11
  ## 6.1.0 (2022-06-20)
2
12
 
3
13
  ### New features
package/dist/index.cjs CHANGED
@@ -818,6 +818,31 @@ function getIndentation(context, pos) {
818
818
  return tree ? syntaxIndentation(context, tree, pos) : null;
819
819
  }
820
820
  /**
821
+ Create a change set that auto-indents all lines touched by the
822
+ given document range.
823
+ */
824
+ function indentRange(state, from, to) {
825
+ let updated = Object.create(null);
826
+ let context = new IndentContext(state, { overrideIndentation: start => { var _a; return (_a = updated[start]) !== null && _a !== void 0 ? _a : -1; } });
827
+ let changes = [];
828
+ for (let pos = from; pos <= to;) {
829
+ let line = state.doc.lineAt(pos);
830
+ let indent = getIndentation(context, line.from);
831
+ if (indent == null)
832
+ continue;
833
+ if (!/\S/.test(line.text))
834
+ indent = 0;
835
+ let cur = /^\s*/.exec(line.text)[0];
836
+ let norm = indentString(state, indent);
837
+ if (cur != norm) {
838
+ updated[line.from] = indent;
839
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
840
+ }
841
+ pos = line.to + 1;
842
+ }
843
+ return state.changes(changes);
844
+ }
845
+ /**
821
846
  Indentation contexts are used when calling [indentation
822
847
  services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
823
848
  useful in indentation logic, and can selectively override the
@@ -1799,7 +1824,7 @@ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, b
1799
1824
  let basePos = pos + distance * dir;
1800
1825
  for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
1801
1826
  let found = brackets.indexOf(text[pos]);
1802
- if (found < 0 || tree.resolve(basePos + pos, 1).type != tokenType)
1827
+ if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
1803
1828
  continue;
1804
1829
  if ((found % 2 == 0) == (dir > 0)) {
1805
1830
  depth++;
@@ -2373,6 +2398,7 @@ exports.getIndentation = getIndentation;
2373
2398
  exports.highlightingFor = highlightingFor;
2374
2399
  exports.indentNodeProp = indentNodeProp;
2375
2400
  exports.indentOnInput = indentOnInput;
2401
+ exports.indentRange = indentRange;
2376
2402
  exports.indentService = indentService;
2377
2403
  exports.indentString = indentString;
2378
2404
  exports.indentUnit = indentUnit;
package/dist/index.d.ts CHANGED
@@ -383,6 +383,11 @@ be determined, and null otherwise.
383
383
  */
384
384
  declare function getIndentation(context: IndentContext | EditorState, pos: number): number | null;
385
385
  /**
386
+ Create a change set that auto-indents all lines touched by the
387
+ given document range.
388
+ */
389
+ declare function indentRange(state: EditorState, from: number, to: number): _codemirror_state.ChangeSet;
390
+ /**
386
391
  Indentation contexts are used when calling [indentation
387
392
  services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
388
393
  useful in indentation logic, and can selectively override the
@@ -1072,4 +1077,4 @@ declare class StreamLanguage<State> extends Language {
1072
1077
  get allowsNesting(): boolean;
1073
1078
  }
1074
1079
 
1075
- export { Config, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, TagStyle, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
1080
+ export { Config, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, TagStyle, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentRange, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
package/dist/index.js CHANGED
@@ -814,6 +814,31 @@ function getIndentation(context, pos) {
814
814
  return tree ? syntaxIndentation(context, tree, pos) : null;
815
815
  }
816
816
  /**
817
+ Create a change set that auto-indents all lines touched by the
818
+ given document range.
819
+ */
820
+ function indentRange(state, from, to) {
821
+ let updated = Object.create(null);
822
+ let context = new IndentContext(state, { overrideIndentation: start => { var _a; return (_a = updated[start]) !== null && _a !== void 0 ? _a : -1; } });
823
+ let changes = [];
824
+ for (let pos = from; pos <= to;) {
825
+ let line = state.doc.lineAt(pos);
826
+ let indent = getIndentation(context, line.from);
827
+ if (indent == null)
828
+ continue;
829
+ if (!/\S/.test(line.text))
830
+ indent = 0;
831
+ let cur = /^\s*/.exec(line.text)[0];
832
+ let norm = indentString(state, indent);
833
+ if (cur != norm) {
834
+ updated[line.from] = indent;
835
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
836
+ }
837
+ pos = line.to + 1;
838
+ }
839
+ return state.changes(changes);
840
+ }
841
+ /**
817
842
  Indentation contexts are used when calling [indentation
818
843
  services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
819
844
  useful in indentation logic, and can selectively override the
@@ -1795,7 +1820,7 @@ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, b
1795
1820
  let basePos = pos + distance * dir;
1796
1821
  for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
1797
1822
  let found = brackets.indexOf(text[pos]);
1798
- if (found < 0 || tree.resolve(basePos + pos, 1).type != tokenType)
1823
+ if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
1799
1824
  continue;
1800
1825
  if ((found % 2 == 0) == (dir > 0)) {
1801
1826
  depth++;
@@ -2334,4 +2359,4 @@ function docID(data) {
2334
2359
  return type;
2335
2360
  }
2336
2361
 
2337
- export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
2362
+ export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentRange, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",