MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / findCharacter

Method findCharacter

src/utils/Cursor.ts:1037–1080  ·  view source on GitHub ↗

* Find a character using vim f/F/t/T semantics. * * @param char - The character to find * @param type - 'f' (forward to), 'F' (backward to), 't' (forward till), 'T' (backward till) * @param count - Find the Nth occurrence * @returns The target offset, or null if not found

(
    char: string,
    type: 'f' | 'F' | 't' | 'T',
    count: number = 1,
  )

Source from the content-addressed store, hash-verified

1035 * @returns The target offset, or null if not found
1036 */
1037 findCharacter(
1038 char: string,
1039 type: 'f' | 'F' | 't' | 'T',
1040 count: number = 1,
1041 ): number | null {
1042 const text = this.text
1043 const forward = type === 'f' || type === 't'
1044 const till = type === 't' || type === 'T'
1045 let found = 0
1046
1047 if (forward) {
1048 let pos = this.measuredText.nextOffset(this.offset)
1049 while (pos < text.length) {
1050 const grapheme = this.graphemeAt(pos)
1051 if (grapheme === char) {
1052 found++
1053 if (found === count) {
1054 return till
1055 ? Math.max(this.offset, this.measuredText.prevOffset(pos))
1056 : pos
1057 }
1058 }
1059 pos = this.measuredText.nextOffset(pos)
1060 }
1061 } else {
1062 if (this.offset === 0) return null
1063 let pos = this.measuredText.prevOffset(this.offset)
1064 while (pos >= 0) {
1065 const grapheme = this.graphemeAt(pos)
1066 if (grapheme === char) {
1067 found++
1068 if (found === count) {
1069 return till
1070 ? Math.min(this.offset, this.measuredText.nextOffset(pos))
1071 : pos
1072 }
1073 }
1074 if (pos === 0) break
1075 pos = this.measuredText.prevOffset(pos)
1076 }
1077 }
1078
1079 return null
1080 }
1081}
1082
1083class WrappedLine {

Callers 3

executeOperatorFindFunction · 0.80
fromFindFunction · 0.80
executeRepeatFindFunction · 0.80

Calls 4

graphemeAtMethod · 0.95
nextOffsetMethod · 0.80
maxMethod · 0.80
prevOffsetMethod · 0.80

Tested by

no test coverage detected