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

Function undoByCount

apps/kimi-code/src/tui/commands/undo.ts:80–125  ·  view source on GitHub ↗
(host: SlashCommandHost, count: number)

Source from the content-addressed store, hash-verified

78}
79
80async function undoByCount(host: SlashCommandHost, count: number): Promise<boolean> {
81 const session = host.session;
82 if (session === undefined) {
83 host.showError(NO_ACTIVE_SESSION_MESSAGE);
84 return false;
85 }
86
87 const entries = host.state.transcriptEntries;
88 const lastUserIndex = findUndoAnchorEntryIndex(entries, count);
89 if (lastUserIndex === undefined) {
90 showUndoLimitStatus(host, 'Nothing to undo.');
91 return false;
92 }
93
94 try {
95 await session.undoHistory(count);
96 } catch (error) {
97 const limit = undoLimitFromError(error);
98 if (limit !== undefined) {
99 showUndoLimitStatus(host, formatUndoLimitMessage(limit.requestedCount, limit));
100 return false;
101 }
102 const message = formatErrorMessage(error);
103 host.showError(`Failed to undo: ${message}`);
104 return false;
105 }
106
107 const children = host.state.transcriptContainer.children;
108 const lastUserComponentIndex = findUndoAnchorComponentIndex(children, count);
109 if (lastUserComponentIndex !== undefined) {
110 removeUndoContextComponents(children, lastUserComponentIndex);
111 host.state.transcriptContainer.invalidate();
112 }
113
114 const preservedEntries = entries.slice(lastUserIndex).filter(
115 (entry) => !isUndoContextEntry(entry),
116 );
117 entries.splice(lastUserIndex, entries.length - lastUserIndex, ...preservedEntries);
118
119 if (entries.length === 0) {
120 renderWelcome(host);
121 }
122
123 host.state.ui.requestRender();
124 return true;
125}
126
127async function showUndoSelector(host: SlashCommandHost): Promise<void> {
128 if (host.session === undefined) {

Callers 2

handleUndoCommandFunction · 0.85
showUndoSelectorFunction · 0.85

Calls 13

formatErrorMessageFunction · 0.90
findUndoAnchorEntryIndexFunction · 0.85
showUndoLimitStatusFunction · 0.85
undoLimitFromErrorFunction · 0.85
formatUndoLimitMessageFunction · 0.85
isUndoContextEntryFunction · 0.85
renderWelcomeFunction · 0.85
showErrorMethod · 0.65
invalidateMethod · 0.65
requestRenderMethod · 0.65

Tested by

no test coverage detected