(cm, cur, symb)
| 1766 | } |
| 1767 | |
| 1768 | function findMatchedSymbol(cm, cur, symb) { |
| 1769 | var line = cur.line; |
| 1770 | symb = symb ? symb : cm.getLine(line).charAt(cur.ch); |
| 1771 | |
| 1772 | // Are we at the opening or closing char |
| 1773 | var forwards = inArray(symb, ['(', '[', '{']); |
| 1774 | |
| 1775 | var reverseSymb = ({ |
| 1776 | '(': ')', ')': '(', |
| 1777 | '[': ']', ']': '[', |
| 1778 | '{': '}', '}': '{'})[symb]; |
| 1779 | |
| 1780 | // Couldn't find a matching symbol, abort |
| 1781 | if (!reverseSymb) { |
| 1782 | return cur; |
| 1783 | } |
| 1784 | |
| 1785 | // set our increment to move forward (+1) or backwards (-1) |
| 1786 | // depending on which bracket we're matching |
| 1787 | var increment = ({'(': 1, '{': 1, '[': 1})[symb] || -1; |
| 1788 | var depth = 1, nextCh = symb, index = cur.ch, lineText = cm.getLine(line); |
| 1789 | // Simple search for closing paren--just count openings and closings till |
| 1790 | // we find our match |
| 1791 | // TODO: use info from CodeMirror to ignore closing brackets in comments |
| 1792 | // and quotes, etc. |
| 1793 | while (nextCh && depth > 0) { |
| 1794 | index += increment; |
| 1795 | nextCh = lineText.charAt(index); |
| 1796 | if (!nextCh) { |
| 1797 | line += increment; |
| 1798 | lineText = cm.getLine(line) || ''; |
| 1799 | if (increment > 0) { |
| 1800 | index = 0; |
| 1801 | } else { |
| 1802 | var lineLen = lineText.length; |
| 1803 | index = (lineLen > 0) ? (lineLen-1) : 0; |
| 1804 | } |
| 1805 | nextCh = lineText.charAt(index); |
| 1806 | } |
| 1807 | if (nextCh === symb) { |
| 1808 | depth++; |
| 1809 | } else if (nextCh === reverseSymb) { |
| 1810 | depth--; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | if (nextCh) { |
| 1815 | return { line: line, ch: index }; |
| 1816 | } |
| 1817 | return cur; |
| 1818 | } |
| 1819 | |
| 1820 | function selectCompanionObject(cm, revSymb, inclusive) { |
| 1821 | var cur = cm.getCursor(); |
no test coverage detected