| 2624 | } |
| 2625 | |
| 2626 | function skipAtomic(doc, pos, bias, mayClear) { |
| 2627 | var flipped = false, curPos = pos; |
| 2628 | var dir = bias || 1; |
| 2629 | doc.cantEdit = false; |
| 2630 | search: for (;;) { |
| 2631 | var line = getLine(doc, curPos.line); |
| 2632 | if (line.markedSpans) { |
| 2633 | for (var i = 0; i < line.markedSpans.length; ++i) { |
| 2634 | var sp = line.markedSpans[i], m = sp.marker; |
| 2635 | if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) && |
| 2636 | (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) { |
| 2637 | if (mayClear) { |
| 2638 | signal(m, "beforeCursorEnter"); |
| 2639 | if (m.explicitlyCleared) { |
| 2640 | if (!line.markedSpans) break; |
| 2641 | else {--i; continue;} |
| 2642 | } |
| 2643 | } |
| 2644 | if (!m.atomic) continue; |
| 2645 | var newPos = m.find()[dir < 0 ? "from" : "to"]; |
| 2646 | if (posEq(newPos, curPos)) { |
| 2647 | newPos.ch += dir; |
| 2648 | if (newPos.ch < 0) { |
| 2649 | if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1)); |
| 2650 | else newPos = null; |
| 2651 | } else if (newPos.ch > line.text.length) { |
| 2652 | if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0); |
| 2653 | else newPos = null; |
| 2654 | } |
| 2655 | if (!newPos) { |
| 2656 | if (flipped) { |
| 2657 | // Driven in a corner -- no valid cursor position found at all |
| 2658 | // -- try again *with* clearing, if we didn't already |
| 2659 | if (!mayClear) return skipAtomic(doc, pos, bias, true); |
| 2660 | // Otherwise, turn off editing until further notice, and return the start of the doc |
| 2661 | doc.cantEdit = true; |
| 2662 | return Pos(doc.first, 0); |
| 2663 | } |
| 2664 | flipped = true; newPos = pos; dir = -dir; |
| 2665 | } |
| 2666 | } |
| 2667 | curPos = newPos; |
| 2668 | continue search; |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | return curPos; |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | // SCROLLING |
| 2677 | |