| 12516 | } |
| 12517 | }; |
| 12518 | function findSymbol(cm, repeat, forward, symb) { |
| 12519 | var cur = copyCursor(cm.getCursor()); |
| 12520 | var increment = forward ? 1 : -1; |
| 12521 | var endLine = forward ? cm.lineCount() : -1; |
| 12522 | var curCh = cur.ch; |
| 12523 | var line = cur.line; |
| 12524 | var lineText = cm.getLine(line); |
| 12525 | var state = { |
| 12526 | lineText: lineText, |
| 12527 | nextCh: lineText.charAt(curCh), |
| 12528 | lastCh: null, |
| 12529 | index: curCh, |
| 12530 | symb: symb, |
| 12531 | reverseSymb: (forward ? { ')': '(', '}': '{' } : { '(': ')', '{': '}' })[symb], |
| 12532 | forward: forward, |
| 12533 | depth: 0, |
| 12534 | curMoveThrough: false |
| 12535 | }; |
| 12536 | var mode = symbolToMode[symb]; |
| 12537 | if (!mode)return cur; |
| 12538 | var init = findSymbolModes[mode].init; |
| 12539 | var isComplete = findSymbolModes[mode].isComplete; |
| 12540 | if (init) { init(state); } |
| 12541 | while (line !== endLine && repeat) { |
| 12542 | state.index += increment; |
| 12543 | state.nextCh = state.lineText.charAt(state.index); |
| 12544 | if (!state.nextCh) { |
| 12545 | line += increment; |
| 12546 | state.lineText = cm.getLine(line) || ''; |
| 12547 | if (increment > 0) { |
| 12548 | state.index = 0; |
| 12549 | } else { |
| 12550 | var lineLen = state.lineText.length; |
| 12551 | state.index = (lineLen > 0) ? (lineLen-1) : 0; |
| 12552 | } |
| 12553 | state.nextCh = state.lineText.charAt(state.index); |
| 12554 | } |
| 12555 | if (isComplete(state)) { |
| 12556 | cur.line = line; |
| 12557 | cur.ch = state.index; |
| 12558 | repeat--; |
| 12559 | } |
| 12560 | } |
| 12561 | if (state.nextCh || state.curMoveThrough) { |
| 12562 | return Pos(line, state.index); |
| 12563 | } |
| 12564 | return cur; |
| 12565 | } |
| 12566 | |
| 12567 | /** |
| 12568 | * Returns the boundaries of the next word. If the cursor in the middle of |