@codemirror/matchbrackets
Advanced tools
Comparing version 0.18.0 to 0.19.0
@@ -0,3 +1,13 @@ | ||
## 0.19.0 (2021-08-11) | ||
### Breaking changes | ||
Update dependencies to 0.19.0 | ||
## 0.18.0 (2021-03-03) | ||
### Breaking changes | ||
Update dependencies to 0.18. | ||
## 0.17.2 (2021-01-06) | ||
@@ -4,0 +14,0 @@ |
import { Extension, EditorState } from '@codemirror/state'; | ||
interface Config { | ||
/** | ||
Whether the bracket matching should look at the character after | ||
the cursor when matching (if the one before isn't a bracket). | ||
Defaults to true. | ||
*/ | ||
afterCursor?: boolean; | ||
/** | ||
The bracket characters to match, as a string of pairs. Defaults | ||
to `"()[]{}"`. Note that these are only used as fallback when | ||
there is no [matching | ||
information](https://lezer.codemirror.net/docs/ref/#common.NodeProp^closedBy) | ||
in the syntax tree. | ||
*/ | ||
brackets?: string; | ||
/** | ||
The maximum distance to scan for matching brackets. This is only | ||
relevant for brackets not encoded in the syntax tree. Defaults | ||
to 10 000. | ||
*/ | ||
maxScanDistance?: number; | ||
} | ||
/** | ||
Create an extension that enables bracket matching. Whenever the | ||
cursor is next to a bracket, that bracket and the one it matches | ||
are highlighted. Or, when no matching bracket is found, another | ||
highlighting style is used to indicate this. | ||
*/ | ||
declare function bracketMatching(config?: Config): Extension; | ||
/** | ||
The result returned from `matchBrackets`. | ||
*/ | ||
interface MatchResult { | ||
/** | ||
The extent of the bracket token found. | ||
*/ | ||
start: { | ||
@@ -14,2 +43,5 @@ from: number; | ||
}; | ||
/** | ||
The extent of the matched token, if any was found. | ||
*/ | ||
end?: { | ||
@@ -19,6 +51,16 @@ from: number; | ||
}; | ||
/** | ||
Whether the tokens match. This can be false even when `end` has | ||
a value, if that token doesn't match the opening token. | ||
*/ | ||
matched: boolean; | ||
} | ||
/** | ||
Find the matching bracket for the token at `pos`, scanning | ||
direction `dir`. Only the `brackets` and `maxScanDistance` | ||
properties are used from `config`, if given. Returns null if no | ||
bracket was found at `pos`, or a match result otherwise. | ||
*/ | ||
declare function matchBrackets(state: EditorState, pos: number, dir: -1 | 1, config?: Config): MatchResult | null; | ||
export { Config, MatchResult, bracketMatching, matchBrackets }; |
import { Facet, combineConfig, StateField } from '@codemirror/state'; | ||
import { syntaxTree } from '@codemirror/language'; | ||
import { EditorView, Decoration } from '@codemirror/view'; | ||
import { NodeProp } from 'lezer-tree'; | ||
import { NodeProp } from '@lezer/common'; | ||
const baseTheme = EditorView.baseTheme({ | ||
const baseTheme = /*@__PURE__*/EditorView.baseTheme({ | ||
".cm-matchingBracket": { color: "#0b0" }, | ||
@@ -11,3 +11,3 @@ ".cm-nonmatchingBracket": { color: "#a22" } | ||
const DefaultScanDist = 10000, DefaultBrackets = "()[]{}"; | ||
const bracketMatchingConfig = Facet.define({ | ||
const bracketMatchingConfig = /*@__PURE__*/Facet.define({ | ||
combine(configs) { | ||
@@ -21,4 +21,4 @@ return combineConfig(configs, { | ||
}); | ||
const matchingMark = Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = Decoration.mark({ class: "cm-nonmatchingBracket" }); | ||
const bracketMatchingState = StateField.define({ | ||
const matchingMark = /*@__PURE__*/Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = /*@__PURE__*/Decoration.mark({ class: "cm-nonmatchingBracket" }); | ||
const bracketMatchingState = /*@__PURE__*/StateField.define({ | ||
create() { return Decoration.none; }, | ||
@@ -53,6 +53,8 @@ update(deco, tr) { | ||
]; | ||
/// Create an extension that enables bracket matching. Whenever the | ||
/// cursor is next to a bracket, that bracket and the one it matches | ||
/// are highlighted. Or, when no matching bracket is found, another | ||
/// highlighting style is used to indicate this. | ||
/** | ||
Create an extension that enables bracket matching. Whenever the | ||
cursor is next to a bracket, that bracket and the one it matches | ||
are highlighted. Or, when no matching bracket is found, another | ||
highlighting style is used to indicate this. | ||
*/ | ||
function bracketMatching(config = {}) { | ||
@@ -72,6 +74,8 @@ return [bracketMatchingConfig.of(config), bracketMatchingUnique]; | ||
} | ||
/// Find the matching bracket for the token at `pos`, scanning | ||
/// direction `dir`. Only the `brackets` and `maxScanDistance` | ||
/// properties are used from `config`, if given. Returns null if no | ||
/// bracket was found at `pos`, or a match result otherwise. | ||
/** | ||
Find the matching bracket for the token at `pos`, scanning | ||
direction `dir`. Only the `brackets` and `maxScanDistance` | ||
properties are used from `config`, if given. Returns null if no | ||
bracket was found at `pos`, or a match result otherwise. | ||
*/ | ||
function matchBrackets(state, pos, dir, config = {}) { | ||
@@ -78,0 +82,0 @@ let maxScanDistance = config.maxScanDistance || DefaultScanDist, brackets = config.brackets || DefaultBrackets; |
{ | ||
"name": "@codemirror/matchbrackets", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "Bracket matching for the CodeMirror code editor", | ||
"scripts": { | ||
"test": "echo 'No tests'", | ||
"prepare": "tsc -p tsconfig.local.json && rollup -c" | ||
"test": "cm-runtests", | ||
"prepare": "cm-buildhelper src/matchbrackets.ts" | ||
}, | ||
@@ -29,11 +29,9 @@ "keywords": [ | ||
"dependencies": { | ||
"@codemirror/language": "^0.18.0", | ||
"@codemirror/state": "^0.18.0", | ||
"@codemirror/view": "^0.18.0", | ||
"lezer-tree": "^0.13.0" | ||
"@codemirror/language": "^0.19.0", | ||
"@codemirror/state": "^0.19.0", | ||
"@codemirror/view": "^0.19.0", | ||
"@lezer/common": "^0.14.0" | ||
}, | ||
"devDependencies": { | ||
"rollup": "^2.35.1", | ||
"rollup-plugin-dts": "^2.0.1", | ||
"typescript": "^4.1.3" | ||
"@codemirror/buildhelper": "^0.1.0" | ||
}, | ||
@@ -40,0 +38,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
337
2
18597
8
+ Added@lezer/common@^0.14.0
+ Added@codemirror/language@0.19.10(transitive)
+ Added@codemirror/rangeset@0.19.9(transitive)
+ Added@codemirror/state@0.19.9(transitive)
+ Added@codemirror/text@0.19.6(transitive)
+ Added@codemirror/view@0.19.48(transitive)
+ Added@lezer/common@0.15.121.2.1(transitive)
+ Added@lezer/lr@0.15.8(transitive)
- Removedlezer-tree@^0.13.0
- Removed@codemirror/language@0.18.2(transitive)
- Removed@codemirror/rangeset@0.18.5(transitive)
- Removed@codemirror/state@0.18.7(transitive)
- Removed@codemirror/text@0.18.1(transitive)
- Removed@codemirror/view@0.18.19(transitive)
- Removedlezer@0.13.5(transitive)
- Removedlezer-tree@0.13.2(transitive)
Updated@codemirror/language@^0.19.0
Updated@codemirror/state@^0.19.0
Updated@codemirror/view@^0.19.0