MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / deleteTokenBefore

Method deleteTokenBefore

source code/utils/Cursor.ts:939–971  ·  view source on GitHub ↗

* Deletes a token before the cursor if one exists. * Supports pasted text refs: [Pasted text #1], [Pasted text #1 +10 lines], * [...Truncated text #1 +10 lines...] * * Note: @mentions are NOT tokenized since users may want to correct typos * in file paths. Use Ctrl/Cmd+backspace for w

()

Source from the content-addressed store, hash-verified

937 * Only triggers when cursor is at end of token (followed by whitespace or EOL).
938 */
939 deleteTokenBefore(): Cursor | null {
940 // Cursor at chip.start is the "selected" state — backspace deletes the
941 // chip forward, not the char before it.
942 const chipAfter = this.imageRefStartingAt(this.offset)
943 if (chipAfter) {
944 const end =
945 this.text[chipAfter.end] === ' ' ? chipAfter.end + 1 : chipAfter.end
946 return this.modifyText(new Cursor(this.measuredText, end))
947 }
948
949 if (this.isAtStart()) {
950 return null
951 }
952
953 // Only trigger if cursor is at a word boundary (whitespace or end of string after cursor)
954 const charAfter = this.text[this.offset]
955 if (charAfter !== undefined && !/\s/.test(charAfter)) {
956 return null
957 }
958
959 const textBefore = this.text.slice(0, this.offset)
960
961 // Check for pasted/truncated text refs: [Pasted text #1] or [...Truncated text #1 +50 lines...]
962 const pasteMatch = textBefore.match(
963 /(^|\s)\[(Pasted text #\d+(?: \+\d+ lines)?|Image #\d+|\.\.\.Truncated text #\d+ \+\d+ lines\.\.\.)\]$/,
964 )
965 if (pasteMatch) {
966 const matchStart = pasteMatch.index! + pasteMatch[1]!.length
967 return new Cursor(this.measuredText, matchStart).modifyText(this)
968 }
969
970 return null
971 }
972
973 deleteWordAfter(): Cursor {
974 if (this.isAtEnd()) {

Callers 3

useTextInputFunction · 0.80
mapKeyFunction · 0.80
onInputFunction · 0.80

Calls 3

imageRefStartingAtMethod · 0.95
modifyTextMethod · 0.95
isAtStartMethod · 0.95

Tested by

no test coverage detected