MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / binarySearchBoundary

Method binarySearchBoundary

src/utils/Cursor.ts:1173–1205  ·  view source on GitHub ↗

* Binary search for boundaries. * @param boundaries: Sorted array of boundaries * @param target: Target offset * @param findNext: If true, finds first boundary > target. If false, finds last boundary < target. * @returns The found boundary index, or appropriate default

(
    boundaries: number[],
    target: number,
    findNext: boolean,
  )

Source from the content-addressed store, hash-verified

1171 * @returns The found boundary index, or appropriate default
1172 */
1173 private binarySearchBoundary(
1174 boundaries: number[],
1175 target: number,
1176 findNext: boolean,
1177 ): number {
1178 let left = 0
1179 let right = boundaries.length - 1
1180 let result = findNext ? this.text.length : 0
1181
1182 while (left <= right) {
1183 const mid = Math.floor((left + right) / 2)
1184 const boundary = boundaries[mid]
1185 if (boundary === undefined) break
1186
1187 if (findNext) {
1188 if (boundary > target) {
1189 result = boundary
1190 right = mid - 1
1191 } else {
1192 left = mid + 1
1193 }
1194 } else {
1195 if (boundary < target) {
1196 result = boundary
1197 left = mid + 1
1198 } else {
1199 right = mid - 1
1200 }
1201 }
1202 }
1203
1204 return result
1205 }
1206
1207 // Convert string index to display width
1208 public stringIndexToDisplayWidth(text: string, index: number): number {

Callers 2

nextOffsetMethod · 0.95
prevOffsetMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected