Skip to content

Commit

Permalink
Fix autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 31, 2024
1 parent e1602cb commit 349ed00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Winch/Patches/TerminalPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ public static bool Terminal_OnDisable_Prefix(Terminal __instance)
return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(CommandAutocomplete), nameof(CommandAutocomplete.Register))]
public static bool CommandAutocomplete_Register_Postfix(this CommandAutocomplete __instance, string word)
{
__instance.known_words.SafeAdd(word.ToLower());
return false;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(CommandShell), nameof(CommandShell.AddCommand), new Type[2] { typeof(string), typeof(CommandInfo) })]
public static void CommandShell_AddCommand_Postfix(string name)
{
Terminal.Autocomplete.Register(name.ToUpper());
}

[HarmonyPostfix]
[HarmonyPatch(typeof(CommandShell), nameof(CommandShell.RemoveCommand), new Type[1] { typeof(string) })]
public static void CommandShell_RemoveCommand_Postfix(string name)
{
Terminal.Autocomplete.Unregister(name.ToUpper());
}

public static List<string> previouslyLogged = new List<string>();

public static void CustomHandleUnityLog(this Terminal terminal, string message, string stack_trace, LogType type)
Expand Down
4 changes: 4 additions & 0 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ public static void RegisterCommands(this CommandShell shell, Assembly assembly)
shell.HandleRejectedCommands(rejectedCommands);
}

public static bool Unregister(this CommandAutocomplete autocomplete, string word)
{
return autocomplete.known_words.Remove(word.ToLower());
}

public static JToken ToJToken(this object? value) => value != null ? JToken.FromObject(value, JSONConfig.jsonSerializer) : JValue.CreateNull();

Expand Down

0 comments on commit 349ed00

Please sign in to comment.