From dbb2645c3d7d2e23042a36e6eb673c8e2f237d2f Mon Sep 17 00:00:00 2001 From: Travis Heppe <heppe@heppe-macbookpro4.roam.corp.google.com> Date: Thu, 15 Jun 2017 07:59:21 -0700 Subject: [PATCH] [matchbrackets addon] Add afterCursor option Default this to true when the fat-cursor style is active. Issue #4803 --- addon/edit/matchbrackets.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/addon/edit/matchbrackets.js b/addon/edit/matchbrackets.js index 76754ed55..7d1a43c1b 100644 --- a/addon/edit/matchbrackets.js +++ b/addon/edit/matchbrackets.js @@ -18,7 +18,25 @@ function findMatchingBracket(cm, where, strict, config) { var line = cm.getLineHandle(where.line), pos = where.ch - 1; - var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)]; + var match; + var afterCursor; + if (!config || config.afterCursor === undefined) { + var paddedClassName = ' ' + cm.getWrapperElement().className + ' '; + afterCursor = (paddedClassName.indexOf(' cm-fat-cursor ') > -1); + } else { + afterCursor = config.afterCursor; + } + + // A cursor is defined as between two characters, but in in vim command mode + // (i.e. not insert mode), the cursor is visually represented as a + // highlighted box on top of the 2nd character. Otherwise, we allow matches + // from before or after the cursor. + if (afterCursor) { + match = matching[line.text.charAt(++pos)]; + } else { + match = (pos >= 0 && matching[line.text.charAt(pos)]) || + matching[line.text.charAt(++pos)]; + } if (!match) return null; var dir = match.charAt(1) == ">" ? 1 : -1; if (strict && (dir > 0) != (pos == where.ch)) return null; -- GitLab