From e0667bdc086aad91895aed8f1b33f433cebd1919 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:59:33 +0000 Subject: [PATCH] Simplify state management to fix web test failures Co-Authored-By: t.yic.yt@gmail.com --- src/commands/registry.ts | 9 +----- src/emulator.ts | 68 +++++++++++++--------------------------- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/src/commands/registry.ts b/src/commands/registry.ts index 8a35496b23..41be3eb0ef 100644 --- a/src/commands/registry.ts +++ b/src/commands/registry.ts @@ -22,19 +22,12 @@ export class EmacsCommandRegistry { const command = this.commands.get(commandName); if (command) { this.lastExecutedCommandId = commandName; - this.currentCommandId = commandName; - // Reset currentCommandId after command execution - setTimeout(() => { - this.currentCommandId = undefined; - }, 0); } return command; } public getCurrentCommandId(): string | undefined { - // Return the current command ID if it exists, otherwise return the last executed command - // This helps track command context during document changes that happen after command execution - return this.currentCommandId || this.lastExecutedCommandId; + return this.lastExecutedCommandId; } public onInterrupt(): void { diff --git a/src/emulator.ts b/src/emulator.ts index c438496688..e482c84ca1 100644 --- a/src/emulator.ts +++ b/src/emulator.ts @@ -371,40 +371,26 @@ export class EmacsEmulator implements IEmacsController, vscode.Disposable { public onDidChangeTextDocument(e: vscode.TextDocumentChangeEvent): void { // XXX: Is this a correct way to check the identity of document? if (e.document.uri.toString() === this.textEditor.document.uri.toString()) { - const currentCommandId = this.commandRegistry.getCurrentCommandId(); + if ( + e.contentChanges.some((contentChange) => + this.textEditor.selections.some( + (selection) => typeof contentChange.range.intersection(selection) !== "undefined", + ), + ) + ) { + this.exitMarkMode(); + } - // Define safe commands that can modify document without interrupting state - const safeModifyingCommands = new Set([ - "universalArgument", - "digitArgument", - "negativeArgument", - "subsequentArgumentDigit", - ]); - - const isPartOfSafeCommand = currentCommandId && safeModifyingCommands.has(currentCommandId); - - if (!isPartOfSafeCommand) { - this._wasDocumentChanged = true; - if ( - e.contentChanges.some((contentChange) => - this.textEditor.selections.some( - (selection) => typeof contentChange.range.intersection(selection) !== "undefined", - ), - ) - ) { - this.exitMarkMode(); - } + // Only trigger interruption for non-prefix-argument commands + const currentCommandId = this.commandRegistry.getCurrentCommandId(); + const isPrefixCommand = + currentCommandId?.startsWith("universalArgument") || + currentCommandId?.startsWith("digitArgument") || + currentCommandId?.startsWith("negativeArgument"); - // Only trigger interruption for non-safe commands + if (!isPrefixCommand) { this.onDidInterruptTextEditor(); - } else { - logger.debug("[EmacsEmulator] Ignoring document change from safe command"); } - - // Reset document changed flag after handling - setTimeout(() => { - this._wasDocumentChanged = false; - }, 0); } } @@ -725,25 +711,15 @@ export class EmacsEmulator implements IEmacsController, vscode.Disposable { } private onDidInterruptTextEditor() { - // Only set interrupted state if we're not in a safe command const currentCommandId = this.commandRegistry.getCurrentCommandId(); - const safeCommands = new Set([ - "moveToWindowLineTopBottom", - "universalArgument", - "digitArgument", - "negativeArgument", - "subsequentArgumentDigit", - ]); + const isSafeCommand = + currentCommandId === "moveToWindowLineTopBottom" || + currentCommandId?.startsWith("universalArgument") || + currentCommandId?.startsWith("digitArgument") || + currentCommandId?.startsWith("negativeArgument"); - if (!currentCommandId || !safeCommands.has(currentCommandId)) { - this._isInterrupted = true; + if (!isSafeCommand) { this.commandRegistry.onInterrupt(); - // Reset interrupted state after handling - setTimeout(() => { - this._isInterrupted = false; - }, 0); - } else { - logger.debug(`[EmacsEmulator] Ignoring interruption during safe command: ${currentCommandId}`); } } }