@@ -32,7 +32,7 @@ public class CodeEditor
32
32
private Text inputHighlightText ;
33
33
34
34
private readonly CSharpLexer highlightLexer ;
35
- private readonly StringBuilder sbHighlight ;
35
+ // private readonly StringBuilder sbHighlight;
36
36
37
37
internal int m_lastCaretPos ;
38
38
internal int m_fixCaretPos ;
@@ -68,16 +68,31 @@ public class CodeEditor
68
68
69
69
public CodeEditor ( )
70
70
{
71
- sbHighlight = new StringBuilder ( ) ;
72
71
highlightLexer = new CSharpLexer ( ) ;
73
72
74
73
ConstructUI ( ) ;
75
74
76
75
InputField . onValueChanged . AddListener ( ( string s ) => { OnInputChanged ( s ) ; } ) ;
77
76
}
78
77
78
+ internal static bool IsUserCopyPasting ( )
79
+ {
80
+ return ( InputManager . GetKey ( KeyCode . LeftControl ) || InputManager . GetKey ( KeyCode . RightControl ) )
81
+ && InputManager . GetKeyDown ( KeyCode . V ) ;
82
+ }
83
+
79
84
public void Update ( )
80
85
{
86
+ if ( s_copyPasteBuffer != null )
87
+ {
88
+ if ( ! IsUserCopyPasting ( ) )
89
+ {
90
+ OnInputChanged ( s_copyPasteBuffer ) ;
91
+
92
+ s_copyPasteBuffer = null ;
93
+ }
94
+ }
95
+
81
96
if ( EnableCtrlRShortcut )
82
97
{
83
98
if ( ( InputManager . GetKey ( KeyCode . LeftControl ) || InputManager . GetKey ( KeyCode . RightControl ) )
@@ -149,11 +164,18 @@ public void UseAutocomplete(string suggestion)
149
164
AutoCompleter . ClearAutocompletes ( ) ;
150
165
}
151
166
152
- public void OnInputChanged ( string newInput , bool forceUpdate = false )
167
+ internal static string s_copyPasteBuffer ;
168
+
169
+ public void OnInputChanged ( string newText , bool forceUpdate = false )
153
170
{
154
- string newText = newInput ;
171
+ if ( IsUserCopyPasting ( ) )
172
+ {
173
+ //Console.WriteLine("Copy+Paste detected!");
174
+ s_copyPasteBuffer = newText ;
175
+ return ;
176
+ }
155
177
156
- UpdateIndent ( newInput ) ;
178
+ UpdateIndent ( newText ) ;
157
179
158
180
if ( ! forceUpdate && string . IsNullOrEmpty ( newText ) )
159
181
inputHighlightText . text = string . Empty ;
@@ -203,35 +225,29 @@ private string SyntaxHighlightContent(string inputText)
203
225
{
204
226
int offset = 0 ;
205
227
206
- sbHighlight . Length = 0 ;
228
+ //Console.WriteLine("Highlighting input text:\r\n" + inputText);
229
+
230
+ string ret = "" ;
207
231
208
232
foreach ( LexerMatchInfo match in highlightLexer . GetMatches ( inputText ) )
209
233
{
210
234
for ( int i = offset ; i < match . startIndex ; i ++ )
211
- {
212
- sbHighlight . Append ( inputText [ i ] ) ;
213
- }
235
+ ret += inputText [ i ] ;
214
236
215
- sbHighlight . Append ( $ "{ match . htmlColor } ") ;
237
+ ret += $ "{ match . htmlColor } ";
216
238
217
239
for ( int i = match . startIndex ; i < match . endIndex ; i ++ )
218
- {
219
- sbHighlight . Append ( inputText [ i ] ) ;
220
- }
240
+ ret += inputText [ i ] ;
221
241
222
- sbHighlight . Append ( CLOSE_COLOR_TAG ) ;
242
+ ret += CLOSE_COLOR_TAG ;
223
243
224
244
offset = match . endIndex ;
225
245
}
226
246
227
247
for ( int i = offset ; i < inputText . Length ; i ++ )
228
- {
229
- sbHighlight . Append ( inputText [ i ] ) ;
230
- }
231
-
232
- inputText = sbHighlight . ToString ( ) ;
248
+ ret += inputText [ i ] ;
233
249
234
- return inputText ;
250
+ return ret ;
235
251
}
236
252
237
253
private void AutoIndentCaret ( )
0 commit comments