[rd-editor] IJPL-192250 Do not use shared stacks for speculative undo/redo

GitOrigin-RevId: 6e3c40f48d7975bb78660c7f725c7524df7b2a2c
This commit is contained in:
Alexander Trushev
2025-06-18 20:01:32 +00:00
committed by intellij-monorepo-bot
parent 60fa02426b
commit a21d6414d8
3 changed files with 24 additions and 4 deletions
@@ -2,14 +2,19 @@
package com.intellij.openapi.command.impl;
import com.intellij.openapi.command.undo.AdjustableUndoableAction;
import com.intellij.openapi.command.undo.BasicUndoableAction;
import com.intellij.openapi.command.undo.DocumentReference;
import com.intellij.openapi.command.undo.MutableActionChangeRange;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ApiStatus.Experimental
final class MockEditorChangeAction extends BasicUndoableAction {
final class MockEditorChangeAction extends BasicUndoableAction implements AdjustableUndoableAction {
MockEditorChangeAction(@NotNull DocumentReference docRef) {
super(docRef);
@@ -22,4 +27,9 @@ final class MockEditorChangeAction extends BasicUndoableAction {
@Override
public void redo() {
}
@Override
public @NotNull List<MutableActionChangeRange> getChangeRanges(@NotNull DocumentReference reference) {
return Collections.emptyList();
}
}
@@ -11,10 +11,12 @@ import java.util.*;
@ApiStatus.Internal
final class SharedUndoRedoStacksHolder extends UndoRedoStacksHolderBase<ImmutableActionChangeRange> {
private final SharedAdjustableUndoableActionsHolder myAdjustableUndoableActionsHolder;
private final boolean myIsPerClientSupported;
SharedUndoRedoStacksHolder(boolean isUndo, SharedAdjustableUndoableActionsHolder undoableActionsHolder) {
SharedUndoRedoStacksHolder(SharedAdjustableUndoableActionsHolder undoableActionsHolder, boolean isPerClientSupported, boolean isUndo) {
super(isUndo);
myAdjustableUndoableActionsHolder = undoableActionsHolder;
myIsPerClientSupported = isPerClientSupported;
}
void addToStack(@NotNull DocumentReference reference, @NotNull ImmutableActionChangeRange changeRange) {
@@ -58,6 +60,9 @@ final class SharedUndoRedoStacksHolder extends UndoRedoStacksHolderBase<Immutabl
}
@NotNull MovementAvailability canMoveToStackTop(@NotNull DocumentReference reference, @NotNull Map<Integer, MutableActionChangeRange> rangesToMove) {
if (!myIsPerClientSupported) {
return MovementAvailability.ALREADY_MOVED;
}
UndoRedoList<ImmutableActionChangeRange> stack = getStack(reference);
ImmutableActionChangeRange[] affected = getAffectedRanges(stack, rangesToMove);
if (affected == null) {
@@ -81,8 +81,8 @@ public class UndoManagerImpl extends UndoManager {
protected UndoManagerImpl(@Nullable ComponentManager componentManager) {
myProject = componentManager instanceof Project project ? project : null;
myAdjustableUndoableActionsHolder = new SharedAdjustableUndoableActionsHolder();
mySharedUndoStacksHolder = new SharedUndoRedoStacksHolder(true, myAdjustableUndoableActionsHolder);
mySharedRedoStacksHolder = new SharedUndoRedoStacksHolder(false, myAdjustableUndoableActionsHolder);
mySharedUndoStacksHolder = new SharedUndoRedoStacksHolder(myAdjustableUndoableActionsHolder, isPerClientSupported(), true);
mySharedRedoStacksHolder = new SharedUndoRedoStacksHolder(myAdjustableUndoableActionsHolder, isPerClientSupported(), false);
}
@Override
@@ -335,6 +335,11 @@ public class UndoManagerImpl extends UndoManager {
return true;
}
@ApiStatus.Internal
protected boolean isPerClientSupported() {
return true;
}
@ApiStatus.Internal
protected final int getStackSize(@Nullable DocumentReference docRef, boolean isUndo) {
UndoClientState state = Objects.requireNonNull(getClientState(), "undo/redo is not available");