MCPcopy
hub / github.com/DHTMLX/gantt / coordsBidiPartWrapped

Function coordsBidiPartWrapped

samples/common/codehighlight/codemirror.js:2834–2865  ·  view source on GitHub ↗
(cm, lineObj, _lineNo, preparedMeasure, order, x, y)

Source from the content-addressed store, hash-verified

2832 }
2833
2834 function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
2835 // In a wrapped line, rtl text on wrapping boundaries can do things
2836 // that don't correspond to the ordering in our `order` array at
2837 // all, so a binary search doesn't work, and we want to return a
2838 // part that only spans one line so that the binary search in
2839 // coordsCharInner is safe. As such, we first find the extent of the
2840 // wrapped line, and then do a flat search in which we discard any
2841 // spans that aren't on the line.
2842 var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
2843 var begin = ref.begin;
2844 var end = ref.end;
2845 if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
2846 var part = null, closestDist = null;
2847 for (var i = 0; i < order.length; i++) {
2848 var p = order[i];
2849 if (p.from >= end || p.to <= begin) { continue }
2850 var ltr = p.level != 1;
2851 var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
2852 // Weigh against spans ending before this, so that they are only
2853 // picked if nothing ends after
2854 var dist = endX < x ? x - endX + 1e9 : endX - x;
2855 if (!part || closestDist > dist) {
2856 part = p;
2857 closestDist = dist;
2858 }
2859 }
2860 if (!part) { part = order[order.length - 1]; }
2861 // Clip the part to the wrapped line.
2862 if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
2863 if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
2864 return part
2865 }
2866
2867 var measureText;
2868 // Compute the default text height.

Callers

nothing calls this directly

Calls 2

wrappedLineExtentFunction · 0.85
measureCharPreparedFunction · 0.85

Tested by

no test coverage detected