diff --git a/client/src/main/execute/insert-history.ts b/client/src/main/execute/insert-history.ts index 483715f..1685feb 100644 --- a/client/src/main/execute/insert-history.ts +++ b/client/src/main/execute/insert-history.ts @@ -22,13 +22,4 @@ export default class InsertHistory { return value.text; } - - normalize(text: string, app: string) { - const value = this.latest(app); - if (value && text.startsWith(value)) { - text = text.substring(value.length); - } - - return text; - } } diff --git a/client/src/main/execute/native-commands.ts b/client/src/main/execute/native-commands.ts index 3cb3778..2ff01c6 100644 --- a/client/src/main/execute/native-commands.ts +++ b/client/src/main/execute/native-commands.ts @@ -84,9 +84,8 @@ class TypeText implements Operation { ) {} async execute() { - const text = this.insertHistory.normalize(this.text, this.active.app); - this.insertHistory.add(text, this.active.app); - await this.system.typeText(text, this.active.app); + this.insertHistory.add(this.text, this.active.app); + await this.system.typeText(this.text, this.active.app); } keystrokesCount(): number { diff --git a/core/src/main/java/core/evaluator/CallbackEvaluator.java b/core/src/main/java/core/evaluator/CallbackEvaluator.java index 3ecf4c0..e9f7285 100644 --- a/core/src/main/java/core/evaluator/CallbackEvaluator.java +++ b/core/src/main/java/core/evaluator/CallbackEvaluator.java @@ -178,10 +178,6 @@ private CommandsResponse paste(EditorStateWithMetadata state, String directionNa .build(); } - private void addToHistory(String token, String transcript) { - history.add(token, transcript); - } - public Optional evaluate( CallbackRequest request, EditorStateWithMetadata state @@ -210,7 +206,10 @@ public Optional evaluate( } else if (request.getType() == CallbackType.CALLBACK_TYPE_PASTE) { return Optional.of(paste(state, request.getText())); } else if (request.getType() == CallbackType.CALLBACK_TYPE_ADD_TO_HISTORY) { - addToHistory(state.getToken(), request.getText()); + history.add(state.getToken(), request.getText()); + return Optional.empty(); + } else if (request.getType() == CallbackType.CALLBACK_TYPE_CLEAR_HISTORY) { + history.clear(state.getToken()); return Optional.empty(); } } catch (Exception e) { diff --git a/core/src/test/java/core/BaseServiceTest.java b/core/src/test/java/core/BaseServiceTest.java index d00efac..b6baaa9 100644 --- a/core/src/test/java/core/BaseServiceTest.java +++ b/core/src/test/java/core/BaseServiceTest.java @@ -9,26 +9,16 @@ import core.gen.rpc.Command; import core.gen.rpc.CommandType; import core.gen.rpc.CommandsResponse; -import core.gen.rpc.CommandsResponseAlternative; import core.gen.rpc.EditorState; import core.gen.rpc.EvaluateRequest; -import core.gen.rpc.EvaluateResponse; import core.gen.rpc.EvaluateTextRequest; import core.gen.rpc.InitializeRequest; import core.gen.rpc.Language; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import java.io.UnsupportedEncodingException; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -36,7 +26,7 @@ public class BaseServiceTest extends BaseTest { - private CoreClient client; + protected CoreClient client; @BeforeEach public void baseServiceBefore() { diff --git a/core/src/test/java/core/visitor/CommandsVisitorTest.java b/core/src/test/java/core/visitor/CommandsVisitorTest.java index dfb9114..4d75951 100644 --- a/core/src/test/java/core/visitor/CommandsVisitorTest.java +++ b/core/src/test/java/core/visitor/CommandsVisitorTest.java @@ -5,11 +5,13 @@ import com.google.protobuf.ByteString; import core.BaseServiceTest; +import core.gen.rpc.CallbackRequest; +import core.gen.rpc.CallbackType; import core.gen.rpc.Command; import core.gen.rpc.CommandType; import core.gen.rpc.CommandsResponse; -import core.gen.rpc.CommandsResponseAlternative; import core.gen.rpc.EditorState; +import core.gen.rpc.EvaluateRequest; import core.gen.rpc.EvaluateTextRequest; import core.gen.rpc.Language; import java.util.Arrays; @@ -17,7 +19,6 @@ import java.util.List; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; -import toolbelt.state.History; // test commands that exist in every language but can't be captured in YAML tests // we happen to use Python here, but none of this is Python-specific. @@ -25,6 +26,32 @@ public class CommandsVisitorTest extends BaseServiceTest { private Language language = Language.LANGUAGE_PYTHON; + private void clearHistory() { + client.send( + EvaluateRequest + .newBuilder() + .setCallbackRequest( + CallbackRequest.newBuilder().setType(CallbackType.CALLBACK_TYPE_CLEAR_HISTORY).build() + ) + .build() + ); + } + + private void addToHistory(String command) { + client.send( + EvaluateRequest + .newBuilder() + .setCallbackRequest( + CallbackRequest + .newBuilder() + .setType(CallbackType.CALLBACK_TYPE_ADD_TO_HISTORY) + .setText(command) + .build() + ) + .build() + ); + } + @Test public void testAlternatives() { CommandsResponse response = makeRequest( @@ -533,30 +560,22 @@ public void testQuantifier() { @Test public void testRepeat() { - // local environments use the in-memory data store, but the test process and the core - // process don't share memory, so this test won't work - if (System.getenv("IN_MEMORY") != null && System.getenv("IN_MEMORY").equals("1")) { - return; - } - - History history = component.history(); - - history.clear(token); - history.add(token, "new tab"); + clearHistory(); + addToHistory("new tab"); assertCommandType("", 0, "repeat", language, CommandType.COMMAND_TYPE_CREATE_TAB); - history.clear(token); - history.add(token, "new tab"); - history.add(token, "close tab"); + clearHistory(); + addToHistory("new tab"); + addToHistory("close tab"); assertCommandType("", 0, "repeat", language, CommandType.COMMAND_TYPE_CLOSE_TAB); assertCommandType("", 0, "repeat new", language, CommandType.COMMAND_TYPE_CREATE_TAB); assertCommandType("", 0, "repeat close", language, CommandType.COMMAND_TYPE_CLOSE_TAB); assertCommandType("", 0, "repeat", language, CommandType.COMMAND_TYPE_CLOSE_TAB); // test we don't loop infinitely. - history.clear(token); - history.add(token, "change word to bar"); - history.add(token, "end of line repeat change"); + clearHistory(); + addToHistory("change word to bar"); + addToHistory("end of line repeat change"); assertCommandTypes( "foo\n", 1, @@ -568,14 +587,8 @@ public void testRepeat() { @Test public void testRepeatQuantifier() { - // see testRepeat - if (System.getenv("IN_MEMORY") != null && System.getenv("IN_MEMORY").equals("1")) { - return; - } - - History history = component.history(); - history.clear(token); - history.add(token, "delete character"); + clearHistory(); + addToHistory("delete character"); assertCommandTypes( "abcdefghijklmn\n", diff --git a/toolbelt/src/main/proto/core.proto b/toolbelt/src/main/proto/core.proto index c1c75bf..a60ae24 100644 --- a/toolbelt/src/main/proto/core.proto +++ b/toolbelt/src/main/proto/core.proto @@ -10,6 +10,7 @@ enum CallbackType { CALLBACK_TYPE_OPEN_FILE = 2; CALLBACK_TYPE_PASTE = 3; CALLBACK_TYPE_ADD_TO_HISTORY = 4; + CALLBACK_TYPE_CLEAR_HISTORY = 5; } enum CommandType {