Skip to content

Commit 4685006

Browse files
authored
Only reset history counter when executing a command (#140)
This helps reducing considerably the events sent through the socket as we don't need to send messages anymore when a different key is pressed.
1 parent 86bd644 commit 4685006

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

assets/js/app.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ Hooks.CommandInput = {
3737
this.pushEventTo('#commandInput', 'cycle_history_up');
3838
} else if (e.code === 'ArrowDown') {
3939
this.pushEventTo('#commandInput', 'cycle_history_down');
40-
} else {
41-
this.pushEventTo('#commandInput', 'reset_history', {});
4240
}
4341
});
4442
},

lib/elixir_console_web/live/console_live/command_input_component.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ defmodule ElixirConsoleWeb.ConsoleLive.CommandInputComponent do
7878
)}
7979
end
8080

81-
def handle_event("reset_history", _key, socket) do
82-
{:noreply, assign(socket, history_counter: -1, input_value: "")}
83-
end
84-
8581
def handle_event("execute", %{"command" => command}, socket) do
8682
send(self(), {:execute_command, command})
87-
{:noreply, push_event(socket, "reset", %{})}
83+
84+
socket =
85+
socket
86+
|> assign(history_counter: -1, input_value: "")
87+
|> push_event("reset", %{})
88+
89+
{:noreply, socket}
8890
end
8991

9092
defp get_previous_history_entry([], _counter), do: {"", 0}

0 commit comments

Comments
 (0)