mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-08 10:33:52 +08:00
Prevent GC Mark Overflow on C# Console copy+paste
This commit is contained in:
parent
9c5596ace4
commit
69912d7ea4
@ -32,7 +32,7 @@ namespace UnityExplorer.CSConsole
|
|||||||
private Text inputHighlightText;
|
private Text inputHighlightText;
|
||||||
|
|
||||||
private readonly CSharpLexer highlightLexer;
|
private readonly CSharpLexer highlightLexer;
|
||||||
private readonly StringBuilder sbHighlight;
|
//private readonly StringBuilder sbHighlight;
|
||||||
|
|
||||||
internal int m_lastCaretPos;
|
internal int m_lastCaretPos;
|
||||||
internal int m_fixCaretPos;
|
internal int m_fixCaretPos;
|
||||||
@ -68,7 +68,6 @@ The following helper methods are available:
|
|||||||
|
|
||||||
public CodeEditor()
|
public CodeEditor()
|
||||||
{
|
{
|
||||||
sbHighlight = new StringBuilder();
|
|
||||||
highlightLexer = new CSharpLexer();
|
highlightLexer = new CSharpLexer();
|
||||||
|
|
||||||
ConstructUI();
|
ConstructUI();
|
||||||
@ -76,8 +75,24 @@ The following helper methods are available:
|
|||||||
InputField.onValueChanged.AddListener((string s) => { OnInputChanged(s); });
|
InputField.onValueChanged.AddListener((string s) => { OnInputChanged(s); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool IsUserCopyPasting()
|
||||||
|
{
|
||||||
|
return (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
|
||||||
|
&& InputManager.GetKeyDown(KeyCode.V);
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
if (s_copyPasteBuffer != null)
|
||||||
|
{
|
||||||
|
if (!IsUserCopyPasting())
|
||||||
|
{
|
||||||
|
OnInputChanged(s_copyPasteBuffer);
|
||||||
|
|
||||||
|
s_copyPasteBuffer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (EnableCtrlRShortcut)
|
if (EnableCtrlRShortcut)
|
||||||
{
|
{
|
||||||
if ((InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
|
if ((InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
|
||||||
@ -149,11 +164,18 @@ The following helper methods are available:
|
|||||||
AutoCompleter.ClearAutocompletes();
|
AutoCompleter.ClearAutocompletes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnInputChanged(string newInput, bool forceUpdate = false)
|
internal static string s_copyPasteBuffer;
|
||||||
{
|
|
||||||
string newText = newInput;
|
|
||||||
|
|
||||||
UpdateIndent(newInput);
|
public void OnInputChanged(string newText, bool forceUpdate = false)
|
||||||
|
{
|
||||||
|
if (IsUserCopyPasting())
|
||||||
|
{
|
||||||
|
//Console.WriteLine("Copy+Paste detected!");
|
||||||
|
s_copyPasteBuffer = newText;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateIndent(newText);
|
||||||
|
|
||||||
if (!forceUpdate && string.IsNullOrEmpty(newText))
|
if (!forceUpdate && string.IsNullOrEmpty(newText))
|
||||||
inputHighlightText.text = string.Empty;
|
inputHighlightText.text = string.Empty;
|
||||||
@ -203,35 +225,29 @@ The following helper methods are available:
|
|||||||
{
|
{
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
sbHighlight.Length = 0;
|
//Console.WriteLine("Highlighting input text:\r\n" + inputText);
|
||||||
|
|
||||||
|
string ret = "";
|
||||||
|
|
||||||
foreach (LexerMatchInfo match in highlightLexer.GetMatches(inputText))
|
foreach (LexerMatchInfo match in highlightLexer.GetMatches(inputText))
|
||||||
{
|
{
|
||||||
for (int i = offset; i < match.startIndex; i++)
|
for (int i = offset; i < match.startIndex; i++)
|
||||||
{
|
ret += inputText[i];
|
||||||
sbHighlight.Append(inputText[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sbHighlight.Append($"{match.htmlColor}");
|
ret += $"{match.htmlColor}";
|
||||||
|
|
||||||
for (int i = match.startIndex; i < match.endIndex; i++)
|
for (int i = match.startIndex; i < match.endIndex; i++)
|
||||||
{
|
ret += inputText[i];
|
||||||
sbHighlight.Append(inputText[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
sbHighlight.Append(CLOSE_COLOR_TAG);
|
ret += CLOSE_COLOR_TAG;
|
||||||
|
|
||||||
offset = match.endIndex;
|
offset = match.endIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = offset; i < inputText.Length; i++)
|
for (int i = offset; i < inputText.Length; i++)
|
||||||
{
|
ret += inputText[i];
|
||||||
sbHighlight.Append(inputText[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputText = sbHighlight.ToString();
|
return ret;
|
||||||
|
|
||||||
return inputText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AutoIndentCaret()
|
private void AutoIndentCaret()
|
||||||
|
@ -4,20 +4,18 @@ using System.Reflection;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using UnityExplorer.Config;
|
using UnityExplorer.Config;
|
||||||
|
using UnityExplorer.Helpers;
|
||||||
using UnityExplorer.Input;
|
using UnityExplorer.Input;
|
||||||
using UnityExplorer.Inspectors;
|
using UnityExplorer.Inspectors;
|
||||||
using UnityExplorer.UI;
|
using UnityExplorer.UI;
|
||||||
using UnityExplorer.UI.Modules;
|
using UnityExplorer.UI.Modules;
|
||||||
#if CPP
|
|
||||||
using UnityExplorer.Helpers;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace UnityExplorer
|
namespace UnityExplorer
|
||||||
{
|
{
|
||||||
public class ExplorerCore
|
public class ExplorerCore
|
||||||
{
|
{
|
||||||
public const string NAME = "UnityExplorer";
|
public const string NAME = "UnityExplorer";
|
||||||
public const string VERSION = "3.1.8";
|
public const string VERSION = "3.1.9";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.unityexplorer";
|
public const string GUID = "com.sinai.unityexplorer";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user