From 9d03817f77ce717d9c2e9f20632dc4fb35ec60c4 Mon Sep 17 00:00:00 2001 From: d4vid Date: Sat, 17 May 2025 22:41:21 +0200 Subject: [PATCH] Skip adding entry to history if it matches latest entry --- ConsoleImprovements/ConsoleImprovements/manifest.jecs | 2 +- .../src/client/CommandHistoryPatch.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ConsoleImprovements/ConsoleImprovements/manifest.jecs b/ConsoleImprovements/ConsoleImprovements/manifest.jecs index eabe279..d46ac86 100644 --- a/ConsoleImprovements/ConsoleImprovements/manifest.jecs +++ b/ConsoleImprovements/ConsoleImprovements/manifest.jecs @@ -1,7 +1,7 @@ ID: D4VID_ConsoleImprovements Name: ConsoleImprovements Author: D4VID -Version: 1.0.0 +Version: 1.1.0 Priority: 0 ClientOnly: true Dependencies: diff --git a/ConsoleImprovements/ConsoleImprovements/src/client/CommandHistoryPatch.cs b/ConsoleImprovements/ConsoleImprovements/src/client/CommandHistoryPatch.cs index e1e27a8..3432672 100644 --- a/ConsoleImprovements/ConsoleImprovements/src/client/CommandHistoryPatch.cs +++ b/ConsoleImprovements/ConsoleImprovements/src/client/CommandHistoryPatch.cs @@ -83,6 +83,13 @@ namespace ConsoleImprovements.Client { // ReSharper disable once InconsistentNaming public static bool HookCommandSubmit(Console __instance, ref string line) { + _command = null; // Clear the command pointer + + // Skip adding the line to the history if it matches the last item + if (_history.Count > 0 && line == _history.First!.Value) { + return true; + } + // Keep the set max number of entries in the history if (_history.Count >= HistLength) { _history.RemoveLast(); @@ -90,8 +97,6 @@ namespace ConsoleImprovements.Client { _history.AddFirst(line); - _command = null; // Clear the command pointer - return true; // Resume original functionality } }