MCPcopy Create free account
hub / github.com/breck7/scroll / bidiSimplify

Function bidiSimplify

external/.scrollLibs.js:10342–10383  ·  view source on GitHub ↗
(cm, range$$1)

Source from the content-addressed store, hash-verified

10340 // Used when mouse-selecting to adjust the anchor to the proper side
10341 // of a bidi jump depending on the visual position of the head.
10342 function bidiSimplify(cm, range$$1) {
10343 var anchor = range$$1.anchor
10344 var head = range$$1.head
10345 var anchorLine = getLine(cm.doc, anchor.line)
10346 if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) {
10347 return range$$1
10348 }
10349 var order = getOrder(anchorLine)
10350 if (!order) {
10351 return range$$1
10352 }
10353 var index = getBidiPartAt(order, anchor.ch, anchor.sticky),
10354 part = order[index]
10355 if (part.from != anchor.ch && part.to != anchor.ch) {
10356 return range$$1
10357 }
10358 var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1)
10359 if (boundary == 0 || boundary == order.length) {
10360 return range$$1
10361 }
10362
10363 // Compute the relative visual position of the head compared to the
10364 // anchor (<0 is to the left, >0 to the right)
10365 var leftSide
10366 if (head.line != anchor.line) {
10367 leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0
10368 } else {
10369 var headIndex = getBidiPartAt(order, head.ch, head.sticky)
10370 var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1)
10371 if (headIndex == boundary - 1 || headIndex == boundary) {
10372 leftSide = dir < 0
10373 } else {
10374 leftSide = dir > 0
10375 }
10376 }
10377
10378 var usePart = order[boundary + (leftSide ? -1 : 0)]
10379 var from = leftSide == (usePart.level == 1)
10380 var ch = from ? usePart.from : usePart.to,
10381 sticky = from ? "after" : "before"
10382 return anchor.ch == ch && anchor.sticky == sticky ? range$$1 : new Range(new Pos(anchor.line, ch, sticky), head)
10383 }
10384
10385 // Determines whether an event happened in the gutter, and fires the
10386 // handlers for the corresponding event.

Callers 1

extendToFunction · 0.85

Calls 4

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

Tested by

no test coverage detected