MCPcopy Create free account
hub / github.com/TruthHun/BookStack / moveVisually

Function moveVisually

static/editor.md/lib/codemirror/lib/codemirror.js:8443–8464  ·  view source on GitHub ↗
(line, start, dir, byUnit)

Source from the content-addressed store, hash-verified

8441 // LTR text touch each other. This often requires the cursor offset
8442 // to move more than one unit, in order to visually move one unit.
8443 function moveVisually(line, start, dir, byUnit) {
8444 var bidi = getOrder(line);
8445 if (!bidi) return moveLogically(line, start, dir, byUnit);
8446 var pos = getBidiPartAt(bidi, start), part = bidi[pos];
8447 var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
8448
8449 for (;;) {
8450 if (target > part.from && target < part.to) return target;
8451 if (target == part.from || target == part.to) {
8452 if (getBidiPartAt(bidi, target) == pos) return target;
8453 part = bidi[pos += dir];
8454 return (dir > 0) == part.level % 2 ? part.to : part.from;
8455 } else {
8456 part = bidi[pos += dir];
8457 if (!part) return null;
8458 if ((dir > 0) == part.level % 2)
8459 target = moveInLine(line, part.to, -1, byUnit);
8460 else
8461 target = moveInLine(line, part.from, 1, byUnit);
8462 }
8463 }
8464 }
8465
8466 function moveLogically(line, start, dir, byUnit) {
8467 var target = start + dir;

Callers 1

coordsCharInnerFunction · 0.70

Calls 4

getOrderFunction · 0.70
moveLogicallyFunction · 0.70
getBidiPartAtFunction · 0.70
moveInLineFunction · 0.70

Tested by

no test coverage detected