mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-07-09 17:28:45 +00:00
fix(tui): decrement paste counter on paste marker delete and terminal clear (#6397)
* fix(tui): decrement paste counter on paste marker delete * fix(tui): fix case of markers after the removed one and ctrl+c * fix(tui): formatting
This commit is contained in:
parent
2b00dade7c
commit
8a2ce5a540
1 changed files with 27 additions and 1 deletions
|
|
@ -999,6 +999,8 @@ export class Editor implements Component, Focusable {
|
|||
this.cancelAutocomplete();
|
||||
this.lastAction = null;
|
||||
this.exitHistoryBrowsing();
|
||||
this.pastes.clear();
|
||||
this.pasteCounter = 0;
|
||||
const normalized = this.normalizeText(text);
|
||||
// Push undo snapshot if content differs (makes programmatic changes undoable)
|
||||
if (this.getText() !== normalized) {
|
||||
|
|
@ -1267,13 +1269,37 @@ export class Editor implements Component, Focusable {
|
|||
this.pushUndoSnapshot();
|
||||
|
||||
// Delete grapheme before cursor (handles emojis, combining characters, etc.)
|
||||
const line = this.state.lines[this.state.cursorLine] || "";
|
||||
let line = this.state.lines[this.state.cursorLine] || "";
|
||||
const beforeCursor = line.slice(0, this.state.cursorCol);
|
||||
|
||||
// Find the last grapheme in the text before cursor
|
||||
const graphemes = [...this.segment(beforeCursor, "grapheme")];
|
||||
const lastGrapheme = graphemes[graphemes.length - 1];
|
||||
const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
|
||||
const isPastedSegmented = PASTE_MARKER_SINGLE.exec(lastGrapheme.segment);
|
||||
|
||||
if (isPastedSegmented) {
|
||||
// This contains the id part e.g 4 from [paste #4 +123 lines]
|
||||
const targetId = Number(isPastedSegmented[1]);
|
||||
this.pastes.delete(targetId);
|
||||
this.pasteCounter--;
|
||||
|
||||
// We got to update id of markers which are greater than the removed one
|
||||
this.state.lines = this.state.lines.map((line) =>
|
||||
line.replace(PASTE_MARKER_REGEX, (fullMatch, idGroup, suffixGroup) => {
|
||||
const x = Number(idGroup);
|
||||
if (x <= targetId) return fullMatch;
|
||||
|
||||
// [paste #3] become [paste #2] if we remove [paste #1]
|
||||
const newText = `[paste #${x - 1}${suffixGroup}]`;
|
||||
this.pastes.set(x - 1, this.pastes.get(x) ?? newText);
|
||||
this.pastes.delete(x);
|
||||
return newText;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
line = this.state.lines[this.state.cursorLine] || "";
|
||||
|
||||
const before = line.slice(0, this.state.cursorCol - graphemeLength);
|
||||
const after = line.slice(this.state.cursorCol);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue