From 65a4f4540c81d5bafba728d3688ecf0d13ab8fcb Mon Sep 17 00:00:00 2001 From: TheMrGong Date: Fri, 30 Apr 2021 23:04:52 -0400 Subject: [PATCH] fix: add copy paste fallback detection --- src/UI/Main/CSConsole/CSharpConsole.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/UI/Main/CSConsole/CSharpConsole.cs b/src/UI/Main/CSConsole/CSharpConsole.cs index 9a13ba5..e055899 100644 --- a/src/UI/Main/CSConsole/CSharpConsole.cs +++ b/src/UI/Main/CSConsole/CSharpConsole.cs @@ -201,12 +201,17 @@ The following helper methods are available: internal static bool IsUserCopyPasting() { + return inputsWithinThreshold > inputThreshold; return (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl)) && InputManager.GetKeyDown(KeyCode.V); } public void UpdateConsole() { + if (inputsWithinThreshold > 0 && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - lastInputChange >= inputSpamThresholdMs * 2) + { + inputsWithinThreshold = 0; + } if (s_copyPasteBuffer != null) { if (!IsUserCopyPasting()) @@ -289,9 +294,27 @@ The following helper methods are available: } internal static string s_copyPasteBuffer; + + internal static long lastInputChange; + internal static int inputsWithinThreshold; + + internal static readonly long inputSpamThresholdMs = 5; + internal static readonly long inputThreshold = 1; public void OnInputChanged(string newText, bool forceUpdate = false) { + var timeSinceLastInput = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - lastInputChange; + lastInputChange = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; + + if (timeSinceLastInput < lastInputChange) + { + inputsWithinThreshold++; + } + else + { + inputsWithinThreshold = 0; + } + if (IsUserCopyPasting()) { //Console.WriteLine("Copy+Paste detected!");