I used match brackets addon to show the brackets matching. I am doing a feature in my JSON editor app
that selects the value of the key in the editor for this any option is available in codeMirror ? or can I get the position values of the match brackets by entering the key name? can I get any help from you?
If you’re looking to find out the size of some syntactic construct (like the value of a JSON property), the syntax tree is probably the best source for that.
thanks for your reply,I’ll check syntax tree
what I needed was to take the key as an input value and to select the value of the particular key
for that I’ve done like this
this.selectKey = function () {
let searchKey = this.searchKey.value;
let searchValue;
if (this.indented) {
searchValue = `"${searchKey}": `;
} else {
searchValue = `"${searchKey}":`;
}
let start;
let cursor = this.codeEditorElement.getSearchCursor(searchValue, null, { caseFold: false });
if (cursor.findNext()) {
console.log(cursor);
start = cursor.to();
console.log(start);
var matchingBracket = this.codeEditorElement.findMatchingBracket(start);
if (matchingBracket) {
console.log("Matching bracket found:");
console.log("From:", matchingBracket.from);
console.log("To:", matchingBracket.to);
this.codeEditorElement.setSelection(matchingBracket.from, matchingBracket.to)
} else {
console.log("No matching bracket found at the cursor position.");
}
}
}
it worked for me, Is it the correct way or any methods for this is already in editor?
Ah, no version 5 has no syntax tree. I guess the findMatchingBracket
solution works, if you don’t need to select non-bracketed values like numbers or strings.
Thanks for you reply, yes the findMatchingBracket solution works for bracketed values, for non-bracketed values I should think of another logic.