373 lines
9.1 KiB
C#
373 lines
9.1 KiB
C#
using System;
|
|
|
|
namespace UnityEngine.Experimental.UIElements
|
|
{
|
|
// Token: 0x02000352 RID: 850
|
|
internal class KeyboardTextEditor : TextEditor
|
|
{
|
|
// Token: 0x06003404 RID: 13316 RVA: 0x00052DFC File Offset: 0x00050FFC
|
|
public KeyboardTextEditor(TextField textField)
|
|
: base(textField)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06003405 RID: 13317 RVA: 0x00052E14 File Offset: 0x00051014
|
|
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
|
|
{
|
|
base.SyncTextEditor();
|
|
this.m_Changed = false;
|
|
EventPropagation eventPropagation = EventPropagation.Continue;
|
|
EventType type = evt.type;
|
|
switch (type)
|
|
{
|
|
case EventType.MouseDown:
|
|
eventPropagation = this.DoMouseDown(evt);
|
|
break;
|
|
case EventType.MouseUp:
|
|
eventPropagation = this.DoMouseUp(evt);
|
|
break;
|
|
default:
|
|
if (type != EventType.ValidateCommand)
|
|
{
|
|
if (type == EventType.ExecuteCommand)
|
|
{
|
|
eventPropagation = this.DoExecuteCommand(evt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
eventPropagation = this.DoValidateCommand(evt);
|
|
}
|
|
break;
|
|
case EventType.MouseDrag:
|
|
eventPropagation = this.DoMouseDrag(evt);
|
|
break;
|
|
case EventType.KeyDown:
|
|
eventPropagation = this.DoKeyDown(evt);
|
|
break;
|
|
}
|
|
if (this.m_Changed)
|
|
{
|
|
if (base.maxLength >= 0 && base.text != null && base.text.Length > base.maxLength)
|
|
{
|
|
base.text = base.text.Substring(0, base.maxLength);
|
|
}
|
|
base.textField.text = base.text;
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
base.UpdateScrollOffset();
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x06003406 RID: 13318 RVA: 0x00052F28 File Offset: 0x00051128
|
|
private EventPropagation DoMouseDown(Event evt)
|
|
{
|
|
this.TakeCapture();
|
|
EventPropagation eventPropagation;
|
|
if (!this.m_HasFocus)
|
|
{
|
|
this.m_HasFocus = true;
|
|
base.MoveCursorToPosition_Internal(evt.mousePosition, evt.shift);
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
else
|
|
{
|
|
if (evt.clickCount == 2 && base.doubleClickSelectsWord)
|
|
{
|
|
base.SelectCurrentWord();
|
|
base.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
|
|
base.MouseDragSelectsWholeWords(true);
|
|
this.m_DragToPosition = false;
|
|
}
|
|
else if (evt.clickCount == 3 && base.tripleClickSelectsLine)
|
|
{
|
|
base.SelectCurrentParagraph();
|
|
base.MouseDragSelectsWholeWords(true);
|
|
base.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
|
|
this.m_DragToPosition = false;
|
|
}
|
|
else
|
|
{
|
|
base.MoveCursorToPosition_Internal(evt.mousePosition, evt.shift);
|
|
this.m_SelectAllOnMouseUp = false;
|
|
}
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x06003407 RID: 13319 RVA: 0x00053000 File Offset: 0x00051200
|
|
private EventPropagation DoMouseUp(Event evt)
|
|
{
|
|
EventPropagation eventPropagation;
|
|
if (!this.HasCapture())
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else
|
|
{
|
|
if (this.m_Dragged && this.m_DragToPosition)
|
|
{
|
|
base.MoveSelectionToAltCursor();
|
|
}
|
|
else if (this.m_PostPoneMove)
|
|
{
|
|
base.MoveCursorToPosition_Internal(evt.mousePosition, evt.shift);
|
|
}
|
|
else if (this.m_SelectAllOnMouseUp)
|
|
{
|
|
this.m_SelectAllOnMouseUp = false;
|
|
}
|
|
base.MouseDragSelectsWholeWords(false);
|
|
this.ReleaseCapture();
|
|
this.m_DragToPosition = true;
|
|
this.m_Dragged = false;
|
|
this.m_PostPoneMove = false;
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x06003408 RID: 13320 RVA: 0x000530A8 File Offset: 0x000512A8
|
|
private EventPropagation DoMouseDrag(Event evt)
|
|
{
|
|
EventPropagation eventPropagation;
|
|
if (!this.HasCapture())
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else
|
|
{
|
|
if (!evt.shift && base.hasSelection && this.m_DragToPosition)
|
|
{
|
|
base.MoveAltCursorToPosition(Event.current.mousePosition);
|
|
}
|
|
else
|
|
{
|
|
if (evt.shift)
|
|
{
|
|
base.MoveCursorToPosition_Internal(evt.mousePosition, evt.shift);
|
|
}
|
|
else
|
|
{
|
|
base.SelectToPosition(evt.mousePosition);
|
|
}
|
|
this.m_DragToPosition = false;
|
|
this.m_SelectAllOnMouseUp = !base.hasSelection;
|
|
}
|
|
this.m_Dragged = true;
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x06003409 RID: 13321 RVA: 0x0005315C File Offset: 0x0005135C
|
|
private EventPropagation DoKeyDown(Event evt)
|
|
{
|
|
EventPropagation eventPropagation;
|
|
if (!base.textField.hasFocus)
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else if (base.HandleKeyEvent(evt))
|
|
{
|
|
this.m_Changed = true;
|
|
base.textField.text = base.text;
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
else if (evt.keyCode == KeyCode.Tab || evt.character == '\t')
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else
|
|
{
|
|
char character = evt.character;
|
|
if (character == '\n' && !this.multiline && !evt.alt)
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else if ((base.textField.font != null && base.textField.font.HasCharacter(character)) || character == '\n')
|
|
{
|
|
base.Insert(character);
|
|
this.m_Changed = true;
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else if (character == '\0')
|
|
{
|
|
if (!string.IsNullOrEmpty(Input.compositionString))
|
|
{
|
|
base.ReplaceSelection("");
|
|
this.m_Changed = true;
|
|
}
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
else
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x0600340A RID: 13322 RVA: 0x00053280 File Offset: 0x00051480
|
|
private EventPropagation DoValidateCommand(Event evt)
|
|
{
|
|
EventPropagation eventPropagation;
|
|
if (!base.textField.hasFocus)
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else
|
|
{
|
|
string commandName = evt.commandName;
|
|
if (commandName != null)
|
|
{
|
|
if (!(commandName == "Cut") && !(commandName == "Copy"))
|
|
{
|
|
if (!(commandName == "Paste"))
|
|
{
|
|
if (!(commandName == "SelectAll") && !(commandName == "Delete"))
|
|
{
|
|
if (!(commandName == "UndoRedoPerformed"))
|
|
{
|
|
}
|
|
}
|
|
}
|
|
else if (!base.CanPaste())
|
|
{
|
|
return EventPropagation.Continue;
|
|
}
|
|
}
|
|
else if (!base.hasSelection)
|
|
{
|
|
return EventPropagation.Continue;
|
|
}
|
|
}
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x0600340B RID: 13323 RVA: 0x00053358 File Offset: 0x00051558
|
|
private EventPropagation DoExecuteCommand(Event evt)
|
|
{
|
|
bool flag = false;
|
|
string text = base.text;
|
|
EventPropagation eventPropagation;
|
|
if (!base.textField.hasFocus)
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
else
|
|
{
|
|
string commandName = evt.commandName;
|
|
if (commandName != null)
|
|
{
|
|
if (commandName == "OnLostFocus")
|
|
{
|
|
return EventPropagation.Stop;
|
|
}
|
|
if (!(commandName == "Cut"))
|
|
{
|
|
if (commandName == "Copy")
|
|
{
|
|
base.Copy();
|
|
return EventPropagation.Stop;
|
|
}
|
|
if (!(commandName == "Paste"))
|
|
{
|
|
if (commandName == "SelectAll")
|
|
{
|
|
base.SelectAll();
|
|
return EventPropagation.Stop;
|
|
}
|
|
if (commandName == "Delete")
|
|
{
|
|
if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
|
|
{
|
|
base.Delete();
|
|
}
|
|
else
|
|
{
|
|
base.Cut();
|
|
}
|
|
flag = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
base.Paste();
|
|
flag = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
base.Cut();
|
|
flag = true;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
if (text != base.text)
|
|
{
|
|
this.m_Changed = true;
|
|
}
|
|
eventPropagation = EventPropagation.Stop;
|
|
}
|
|
else
|
|
{
|
|
eventPropagation = EventPropagation.Continue;
|
|
}
|
|
}
|
|
return eventPropagation;
|
|
}
|
|
|
|
// Token: 0x0600340C RID: 13324 RVA: 0x00053488 File Offset: 0x00051688
|
|
public void PreDrawCursor(string newText)
|
|
{
|
|
base.SyncTextEditor();
|
|
this.m_PreDrawCursorText = base.text;
|
|
int num = base.cursorIndex;
|
|
if (!string.IsNullOrEmpty(Input.compositionString))
|
|
{
|
|
base.text = newText.Substring(0, base.cursorIndex) + Input.compositionString + newText.Substring(base.selectIndex);
|
|
num += Input.compositionString.Length;
|
|
}
|
|
else
|
|
{
|
|
base.text = newText;
|
|
}
|
|
if (base.maxLength >= 0 && base.text != null && base.text.Length > base.maxLength)
|
|
{
|
|
base.text = base.text.Substring(0, base.maxLength);
|
|
num = Math.Min(num, base.maxLength - 1);
|
|
}
|
|
this.graphicalCursorPos = this.style.GetCursorPixelPosition(this.localPosition, new GUIContent(base.text), num);
|
|
}
|
|
|
|
// Token: 0x0600340D RID: 13325 RVA: 0x00053580 File Offset: 0x00051780
|
|
public void PostDrawCursor()
|
|
{
|
|
base.text = this.m_PreDrawCursorText;
|
|
}
|
|
|
|
// Token: 0x04000AF8 RID: 2808
|
|
internal bool m_Changed;
|
|
|
|
// Token: 0x04000AF9 RID: 2809
|
|
private bool m_Dragged;
|
|
|
|
// Token: 0x04000AFA RID: 2810
|
|
private bool m_DragToPosition = true;
|
|
|
|
// Token: 0x04000AFB RID: 2811
|
|
private bool m_PostPoneMove;
|
|
|
|
// Token: 0x04000AFC RID: 2812
|
|
private bool m_SelectAllOnMouseUp = true;
|
|
|
|
// Token: 0x04000AFD RID: 2813
|
|
private string m_PreDrawCursorText;
|
|
}
|
|
}
|