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

Method binarySearchBoundary

src/utils/Cursor.ts:1198–1230  ·  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

1196 * @returns The found boundary index, or appropriate default
1197 */
1198 private binarySearchBoundary(
1199 boundaries: number[],
1200 target: number,
1201 findNext: boolean,
1202 ): number {
1203 let left = 0
1204 let right = boundaries.length - 1
1205 let result = findNext ? this.text.length : 0
1206
1207 while (left <= right) {
1208 const mid = Math.floor((left + right) / 2)
1209 const boundary = boundaries[mid]
1210 if (boundary === undefined) break
1211
1212 if (findNext) {
1213 if (boundary > target) {
1214 result = boundary
1215 right = mid - 1
1216 } else {
1217 left = mid + 1
1218 }
1219 } else {
1220 if (boundary < target) {
1221 result = boundary
1222 left = mid + 1
1223 } else {
1224 right = mid - 1
1225 }
1226 }
1227 }
1228
1229 return result
1230 }
1231
1232 // Convert string index to display width
1233 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