MCPcopy Create free account
hub / github.com/witheve/Eve / selectCompanionObject

Function selectCompanionObject

src/codemirror.js:12804–12844  ·  view source on GitHub ↗
(cm, head, symb, inclusive)

Source from the content-addressed store, hash-verified

12802 // TODO: perhaps this finagling of start and end positions belonds
12803 // in codemirror/replaceRange?
12804 function selectCompanionObject(cm, head, symb, inclusive) {
12805 var cur = head, start, end;
12806
12807 var bracketRegexp = ({
12808 '(': /[()]/, ')': /[()]/,
12809 '[': /[[\]]/, ']': /[[\]]/,
12810 '{': /[{}]/, '}': /[{}]/})[symb];
12811 var openSym = ({
12812 '(': '(', ')': '(',
12813 '[': '[', ']': '[',
12814 '{': '{', '}': '{'})[symb];
12815 var curChar = cm.getLine(cur.line).charAt(cur.ch);
12816 // Due to the behavior of scanForBracket, we need to add an offset if the
12817 // cursor is on a matching open bracket.
12818 var offset = curChar === openSym ? 1 : 0;
12819
12820 start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, null, {'bracketRegex': bracketRegexp});
12821 end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, null, {'bracketRegex': bracketRegexp});
12822
12823 if (!start || !end) {
12824 return { start: cur, end: cur };
12825 }
12826
12827 start = start.pos;
12828 end = end.pos;
12829
12830 if ((start.line == end.line && start.ch > end.ch)
12831 || (start.line > end.line)) {
12832 var tmp = start;
12833 start = end;
12834 end = tmp;
12835 }
12836
12837 if (inclusive) {
12838 end.ch += 1;
12839 } else {
12840 start.ch += 1;
12841 }
12842
12843 return { start: start, end: end };
12844 }
12845
12846 // Takes in a symbol and a cursor and tries to simulate text objects that
12847 // have identical opening and closing symbols

Callers 1

VimFunction · 0.85

Calls 1

getLineMethod · 0.80

Tested by

no test coverage detected