MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / handleBackspace

Method handleBackspace

packages/pi-tui/src/components/editor.ts:1370–1425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1368 }
1369
1370 private handleBackspace(): void {
1371 this.exitHistoryBrowsing();
1372 this.lastAction = null;
1373
1374 if (this.state.cursorCol > 0) {
1375 this.pushUndoSnapshot();
1376
1377 // Delete grapheme before cursor (handles emojis, combining characters, etc.)
1378 const line = this.state.lines[this.state.cursorLine] || "";
1379 const beforeCursor = line.slice(0, this.state.cursorCol);
1380
1381 // Find the last grapheme in the text before cursor
1382 const graphemes = [...this.segment(beforeCursor, "grapheme")];
1383 const lastGrapheme = graphemes[graphemes.length - 1];
1384 const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
1385
1386 const before = line.slice(0, this.state.cursorCol - graphemeLength);
1387 const after = line.slice(this.state.cursorCol);
1388
1389 this.state.lines[this.state.cursorLine] = before + after;
1390 this.setCursorCol(this.state.cursorCol - graphemeLength);
1391 } else if (this.state.cursorLine > 0) {
1392 this.pushUndoSnapshot();
1393
1394 // Merge with previous line
1395 const currentLine = this.state.lines[this.state.cursorLine] || "";
1396 const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1397
1398 this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1399 this.state.lines.splice(this.state.cursorLine, 1);
1400
1401 this.state.cursorLine--;
1402 this.setCursorCol(previousLine.length);
1403 }
1404
1405 if (this.onChange) {
1406 this.onChange(this.getText());
1407 }
1408
1409 // Update or re-trigger autocomplete after backspace
1410 if (this.autocompleteState) {
1411 this.updateAutocomplete();
1412 } else {
1413 // If autocomplete was cancelled (no matches), re-trigger if we're in a completable context
1414 const currentLine = this.state.lines[this.state.cursorLine] || "";
1415 const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1416 // Slash command context
1417 if (this.isInSlashCommandContext(textBeforeCursor)) {
1418 this.tryTriggerAutocomplete();
1419 }
1420 // Symbol-based completion context like @, #, or provider triggers
1421 else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1422 this.tryTriggerAutocomplete();
1423 }
1424 }
1425 }
1426
1427 /**

Callers 1

handleInputMethod · 0.95

Calls 8

exitHistoryBrowsingMethod · 0.95
pushUndoSnapshotMethod · 0.95
segmentMethod · 0.95
setCursorColMethod · 0.95
getTextMethod · 0.95
updateAutocompleteMethod · 0.95

Tested by

no test coverage detected