How can I scroll to the matching bracket, similar to the toMatchingTag option?
I could not find a toMatchingBracket option or anything similar… is there one?
I have tried this, to at least get to the end matching bracket, but it does not work since codemirror refreshes the lines on scroll, at least I think that’s what’s happening…
$(document).on('keydown', '.CodeMirror', function ( e ) {
if ((e.metaKey || e.ctrlKey) && ( String.fromCharCode(e.which).toLowerCase() === 'm') ) {
console.log( "You pressed CTRL + M" );
var closeBracket = $(this).find('.CodeMirror-matchingbracket').last();
var cursor = $(this).find('.CodeMirror-cursor');
$('.CodeMirror-scroll').scrollTop(closeBracket.offset().top);
cursor.offset({ top: closeBracket.offset().top, left: closeBracket.offset().left });
}
});
The matchbrackets addon exports a findMatchingBracket method. That, in combination with the scrollIntoView method should be able to get you the effect you’re looking for.