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

Function findFirst

external/.scrollLibs.js:835–854  ·  view source on GitHub ↗
(pred, from, to)

Source from the content-addressed store, hash-verified

833 // `pred` and is closest to `from`. Assumes that at least `to`
834 // satisfies `pred`. Supports `from` being greater than `to`.
835 function findFirst(pred, from, to) {
836 // At any point we are certain `to` satisfies `pred`, don't know
837 // whether `from` does.
838 var dir = from > to ? -1 : 1
839 for (;;) {
840 if (from == to) {
841 return from
842 }
843 var midF = (from + to) / 2,
844 mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF)
845 if (mid == from) {
846 return pred(mid) ? from : to
847 }
848 if (pred(mid)) {
849 to = mid
850 } else {
851 from = mid + dir
852 }
853 }
854 }
855
856 // The display handles the DOM integration, both for input reading
857 // and content drawing. It holds references to DOM nodes and

Callers 4

wrappedLineExtentFunction · 0.85
coordsCharInnerFunction · 0.85
coordsBidiPartFunction · 0.85
endOfLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected