Scroll to matching bracket?

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');
    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.

How exactly do I use that? I tried editor.findMatchingBracket(); in my function but it returns and error Cannot read property 'line' of undefined

Are there any demos for this? I couldn’t find any online…

There’s no demo, but the function is described in the docs as taking at least one argument (the start position).

@marijn How do I syntax this? Here is what I have tried:

$(document).on("keydown", ".CodeMirror", function(e) {
  var inner = $(this).closest(".widget-inner");
  var editor = inner[0].editor;
  var line = editor.getCursor().line;
  var ch = editor.getCursor().ch;
  if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === "m") {
    editor.findMatchingBracket({line: line, ch: ch});
    // or
    editor.findMatchingBracket({line, ch});
    // or