MCPcopy Index your code
hub / github.com/DHTMLX/gantt / bidiSimplify

Function bidiSimplify

samples/common/codehighlight/codemirror.js:7571–7601  ·  view source on GitHub ↗
(cm, range)

Source from the content-addressed store, hash-verified

7569 // Used when mouse-selecting to adjust the anchor to the proper side
7570 // of a bidi jump depending on the visual position of the head.
7571 function bidiSimplify(cm, range) {
7572 var anchor = range.anchor;
7573 var head = range.head;
7574 var anchorLine = getLine(cm.doc, anchor.line);
7575 if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
7576 var order = getOrder(anchorLine);
7577 if (!order) { return range }
7578 var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
7579 if (part.from != anchor.ch && part.to != anchor.ch) { return range }
7580 var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
7581 if (boundary == 0 || boundary == order.length) { return range }
7582
7583 // Compute the relative visual position of the head compared to the
7584 // anchor (<0 is to the left, >0 to the right)
7585 var leftSide;
7586 if (head.line != anchor.line) {
7587 leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
7588 } else {
7589 var headIndex = getBidiPartAt(order, head.ch, head.sticky);
7590 var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
7591 if (headIndex == boundary - 1 || headIndex == boundary)
7592 { leftSide = dir < 0; }
7593 else
7594 { leftSide = dir > 0; }
7595 }
7596
7597 var usePart = order[boundary + (leftSide ? -1 : 0)];
7598 var from = leftSide == (usePart.level == 1);
7599 var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
7600 return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
7601 }
7602
7603
7604 // Determines whether an event happened in the gutter, and fires the

Callers 1

extendToFunction · 0.85

Calls 4

getLineFunction · 0.85
cmpFunction · 0.85
getOrderFunction · 0.85
getBidiPartAtFunction · 0.85

Tested by

no test coverage detected