public class TextEditor : IKeyboardControl
{
// Fields
public GUIContent content = new GUIContent();
public int controlID;
public Vector2 graphicalCursorPos;
public Vector2 graphicalSelectCursorPos;
public bool hasHorizontalCursorPos;
public bool isPasswordField;
private bool m_bJustSelected;
private int m_DblClickInitPos;
private DblClickSnapping m_DblClickSnap;
private int m_iAltCursorPos = -1;
private bool m_MouseDragSelectsWholeWords;
public bool multiline;
private int oldPos;
private int oldSelectPos;
private string oldText;
public int pos;
public Rect position;
private static Hashtable s_Keyactions;
public Vector2 scrollOffset = Vector2.zero;
public int selectPos;
public GUIStyle style = GUIStyle.none;
// Methods
public bool Backspace()
{
if (this.hasSelection)
{
this.DeleteSelection();
return true;
}
if (this.pos > 0)
{
this.content.text = this.content.text.Remove(this.pos - 1, 1);
int num = this.pos - 1;
this.pos = num;
this.selectPos = num;
this.ClearCursorPos();
return true;
}
return false;
}
public bool CanPaste()
{
return (GUIUtility.systemCopyBuffer.Length != 0);
}
public void ClampPos()
{
if (this.pos < 0)
{
this.pos = 0;
}
else if (this.pos > this.content.text.Length)
{
this.pos = this.content.text.Length;
}
if (this.selectPos < 0)
{
this.selectPos = 0;
}
else if (this.selectPos > this.content.text.Length)
{
this.selectPos = this.content.text.Length;
}
if (this.m_iAltCursorPos > this.content.text.Length)
{
this.m_iAltCursorPos = this.content.text.Length;
}
}
private CharacterType ClassifyChar(char c)
{
if (char.IsWhiteSpace(c))
{
return CharacterType.WhiteSpace;
}
if (!char.IsLetterOrDigit(c) && (c != '\''))
{
return CharacterType.Symbol;
}
return CharacterType.LetterLike;
}
private void ClearCursorPos()
{
this.hasHorizontalCursorPos = false;
this.m_iAltCursorPos = -1;
}
public void Copy()
{
if ((this.selectPos != this.pos) && !this.isPasswordField)
{
string str;
if (this.pos < this.selectPos)
{
str = this.content.text.Substring(this.pos, this.selectPos - this.pos);
}
else
{
str = this.content.text.Substring(this.selectPos, this.pos - this.selectPos);
}
GUIUtility.systemCopyBuffer = str;
}
}
public bool Cut()
{
if (this.isPasswordField)
{
return false;
}
this.Copy();
return this.DeleteSelection();
}
public void DblClickSnap(DblClickSnapping snapping)
{
this.m_DblClickSnap = snapping;
}
public bool Delete()
{
if (this.hasSelection)
{
this.DeleteSelection();
return true;
}
if (this.pos < this.content.text.Length)
{
this.content.text = this.content.text.Remove(this.pos, 1);
return true;
}
return false;
}
public bool DeleteSelection()
{
int length = this.content.text.Length;
if (this.pos > length)
{
this.pos = length;
}
if (this.selectPos > length)
{
this.selectPos = length;
}
if (this.pos == this.selectPos)
{
return false;
}
if (this.pos < this.selectPos)
{
this.content.text = this.content.text.Substring(0, this.pos) + this.content.text.Substring(this.selectPos, this.content.text.Length - this.selectPos);
this.selectPos = this.pos;
}
else
{
this.content.text = this.content.text.Substring(0, this.selectPos) + this.content.text.Substring(this.pos, this.content.text.Length - this.pos);
this.pos = this.selectPos;
}
this.ClearCursorPos();
return true;
}
public void DrawCursor(string text)
{
string str = this.content.text;
this.content.text = text;
Rect position = new Rect(0f, 0f, this.position.width, this.position.height);
this.graphicalCursorPos = this.style.GetCursorPixelPosition(position, this.content, this.pos);
Rect rect = this.style.padding.Remove(this.position);
Vector2 vector = this.style.CalcSize(this.content);
if (vector.x < rect.width)
{
this.scrollOffset.x = 0f;
}
else
{
if (this.graphicalCursorPos.x < this.scrollOffset.x)
{
this.scrollOffset.x = this.graphicalCursorPos.x;
}
else if (this.graphicalCursorPos.x > (this.scrollOffset.x + rect.width))
{
this.scrollOffset.x = (this.graphicalCursorPos.x - rect.width) + 1f;
}
if ((this.scrollOffset.x + rect.width) > vector.x)
{
this.scrollOffset.x = (vector.x - rect.width) + 1f;
}
}
if (vector.y < rect.height)
{
this.scrollOffset.y = 0f;
}
else
{
if (this.graphicalCursorPos.y < this.scrollOffset.y)
{
this.scrollOffset.y = this.graphicalCursorPos.y + 1f;
}
else if (this.graphicalCursorPos.y >= ((this.scrollOffset.y + rect.height) - 3.0))
{
this.scrollOffset.y = this.graphicalCursorPos.y + 1f;
}
if ((this.scrollOffset.y + rect.height) > vector.y)
{
this.scrollOffset.y = (vector.y - rect.height) + 1f;
}
}
this.scrollOffset.y = (this.scrollOffset.y >= 0f) ? this.scrollOffset.y : 0f;
this.style.contentOffset = Vector2.op_UnaryNegation(this.scrollOffset);
this.style.Internal_clipOffset = this.scrollOffset;
this.style.DrawWithTextSelection(this.position, this.content, this.controlID, this.pos, this.selectPos);
if (this.m_iAltCursorPos != -1)
{
this.style.DrawCursor(this.position, this.content, this.controlID, this.m_iAltCursorPos);
}
this.style.contentOffset = Vector2.zero;
this.style.Internal_clipOffset = Vector2.zero;
this.content.text = str;
}
public void ExpandSelectGraphicalLineEnd()
{
this.ClearCursorPos();
if (this.pos > this.selectPos)
{
this.pos = this.GetGraphicalLineEnd(this.pos);
}
else
{
int pos = this.pos;
this.pos = this.GetGraphicalLineEnd(this.selectPos);
this.selectPos = pos;
}
}
public void ExpandSelectGraphicalLineStart()
{
this.ClearCursorPos();
if (this.pos < this.selectPos)
{
this.pos = this.GetGraphicalLineStart(this.pos);
}
else
{
int pos = this.pos;
this.pos = this.GetGraphicalLineStart(this.selectPos);
this.selectPos = pos;
}
}
private int FindEndOfClassification(int p, int dir)
{
int length = this.content.text.Length;
if (p >= length)
{
return p;
}
CharacterType type = this.ClassifyChar(this.content.text[p]);
do
{
p += dir;
if (p < 0)
{
return 0;
}
if (p >= length)
{
return length;
}
}
while (this.ClassifyChar(this.content.text[p]) == type);
if (dir == 1)
{
return p;
}
return (p + 1);
}
private int FindEndOfPreviousWord(int p)
{
if (p != 0)
{
p--;
while ((p > 0) && (this.content.text[p] == ' '))
{
p--;
}
CharacterType type = this.ClassifyChar(this.content.text[p]);
if (type == CharacterType.WhiteSpace)
{
return p;
}
while ((p > 0) && (this.ClassifyChar(this.content.text[p - 1]) == type))
{
p--;
}
}
return p;
}
private int FindNextSeperator(int startPos)
{
int length = this.content.text.Length;
while ((startPos < length) && !isLetterLikeChar(this.content.text[startPos]))
{
startPos++;
}
while ((startPos < length) && isLetterLikeChar(this.content.text[startPos]))
{
startPos++;
}
return startPos;
}
private int FindPrevSeperator(int startPos)
{
startPos--;
while ((startPos > 0) && !isLetterLikeChar(this.content.text[startPos]))
{
startPos--;
}
while ((startPos >= 0) && isLetterLikeChar(this.content.text[startPos]))
{
startPos--;
}
return (startPos + 1);
}
public int FindStartOfNextWord(int p)
{
int length = this.content.text.Length;
if (p != length)
{
char c = this.content.text[p];
CharacterType type = this.ClassifyChar(c);
if (type != CharacterType.WhiteSpace)
{
p++;
while ((p < length) && (this.ClassifyChar(this.content.text[p]) == type))
{
p++;
}
}
else
{
switch (c)
{
case '\t':
case '\n':
return (p + 1);
}
}
if (p != length)
{
switch (this.content.text[p])
{
case ' ':
while ((p < length) && char.IsWhiteSpace(this.content.text[p]))
{
p++;
}
return p;
}
}
}
return p;
}
private int GetGraphicalLineEnd(int p)
{
Vector2 cursorPixelPosition = this.style.GetCursorPixelPosition(this.position, this.content, p);
cursorPixelPosition.x += 5000f;
return this.style.GetCursorStringIndex(this.position, this.content, cursorPixelPosition);
}
private int GetGraphicalLineStart(int p)
{
Vector2 cursorPixelPosition = this.style.GetCursorPixelPosition(this.position, this.content, p);
cursorPixelPosition.x = 0f;
return this.style.GetCursorStringIndex(this.position, this.content, cursorPixelPosition);
}
private void GrabGraphicalCursorPos()
{
if (!this.hasHorizontalCursorPos)
{
this.graphicalCursorPos = this.style.GetCursorPixelPosition(this.position, this.content, this.pos);
this.graphicalSelectCursorPos = this.style.GetCursorPixelPosition(this.position, this.content, this.selectPos);
this.hasHorizontalCursorPos = false;
}
}
public bool HandleKeyEvent(Event e)
{
this.InitKeyActions();
Event.Modifiers modifiers = e.modifiers;
e.modifiers &= ~Event.Modifiers.CapsLock;
if (s_Keyactions.Contains(e))
{
TextEditOp operation = (TextEditOp) s_Keyactions[e];
this.PerformOperation(operation);
e.modifiers = modifiers;
return true;
}
e.modifiers = modifiers;
return false;
}
private void InitKeyActions()
{
if (s_Keyactions == null)
{
s_Keyactions = new Hashtable();
MapKey("left", TextEditOp.MoveLeft);
MapKey("right", TextEditOp.MoveRight);
MapKey("up", TextEditOp.MoveUp);
MapKey("down", TextEditOp.MoveDown);
MapKey("#left", TextEditOp.SelectLeft);
MapKey("#right", TextEditOp.SelectRight);
MapKey("#up", TextEditOp.SelectUp);
MapKey("#down", TextEditOp.SelectDown);
MapKey("delete", TextEditOp.Delete);
MapKey("backspace", TextEditOp.Backspace);
MapKey("#backspace", TextEditOp.Backspace);
if (((Application.platform != RuntimePlatform.WindowsPlayer) && (Application.platform != RuntimePlatform.WindowsWebPlayer)) && (Application.platform != RuntimePlatform.WindowsEditor))
{
MapKey("^left", TextEditOp.MoveGraphicalLineStart);
MapKey("^right", TextEditOp.MoveGraphicalLineEnd);
MapKey("&left", TextEditOp.MoveWordLeft);
MapKey("&right", TextEditOp.MoveWordRight);
MapKey("&up", TextEditOp.MoveParagraphBackward);
MapKey("&down", TextEditOp.MoveParagraphForward);
MapKey("%left", TextEditOp.MoveGraphicalLineStart);
MapKey("%right", TextEditOp.MoveGraphicalLineEnd);
MapKey("%up", TextEditOp.MoveTextStart);
MapKey("%down", TextEditOp.MoveTextEnd);
MapKey("#home", TextEditOp.SelectTextStart);
MapKey("#end", TextEditOp.SelectTextEnd);
MapKey("#^left", TextEditOp.ExpandSelectGraphicalLineStart);
MapKey("#^right", TextEditOp.ExpandSelectGraphicalLineEnd);
MapKey("#^up", TextEditOp.SelectParagraphBackward);
MapKey("#^down", TextEditOp.SelectParagraphForward);
MapKey("#&left", TextEditOp.SelectWordLeft);
MapKey("#&right", TextEditOp.SelectWordRight);
MapKey("#&up", TextEditOp.SelectParagraphBackward);
MapKey("#&down", TextEditOp.SelectParagraphForward);
MapKey("#%left", TextEditOp.ExpandSelectGraphicalLineStart);
MapKey("#%right", TextEditOp.ExpandSelectGraphicalLineEnd);
MapKey("#%up", TextEditOp.SelectTextStart);
MapKey("#%down", TextEditOp.SelectTextEnd);
MapKey("%a", TextEditOp.SelectAll);
MapKey("%x", TextEditOp.Cut);
MapKey("%c", TextEditOp.Copy);
MapKey("%v", TextEditOp.Paste);
MapKey("^d", TextEditOp.Delete);
MapKey("^h", TextEditOp.Backspace);
MapKey("^b", TextEditOp.MoveLeft);
MapKey("^f", TextEditOp.MoveRight);
MapKey("^a", TextEditOp.MoveLineStart);
MapKey("^e", TextEditOp.MoveLineEnd);
}
else
{
MapKey("home", TextEditOp.MoveGraphicalLineStart);
MapKey("end", TextEditOp.MoveGraphicalLineEnd);
MapKey("%left", TextEditOp.MoveWordLeft);
MapKey("%right", TextEditOp.MoveWordRight);
MapKey("%up", TextEditOp.MoveParagraphBackward);
MapKey("%down", TextEditOp.MoveParagraphForward);
MapKey("^left", TextEditOp.MoveToEndOfPreviousWord);
MapKey("^right", TextEditOp.MoveToStartOfNextWord);
MapKey("^up", TextEditOp.MoveParagraphBackward);
MapKey("^down", TextEditOp.MoveParagraphForward);
MapKey("#^left", TextEditOp.SelectToEndOfPreviousWord);
MapKey("#^right", TextEditOp.SelectToStartOfNextWord);
MapKey("#^up", TextEditOp.SelectParagraphBackward);
MapKey("#^down", TextEditOp.SelectParagraphForward);
MapKey("#home", TextEditOp.SelectGraphicalLineStart);
MapKey("#end", TextEditOp.SelectGraphicalLineEnd);
MapKey("^a", TextEditOp.SelectAll);
MapKey("^x", TextEditOp.Cut);
MapKey("^c", TextEditOp.Copy);
MapKey("^v", TextEditOp.Paste);
}
}
}
public void Insert(char c)
{
char[] chArray = new char[] { c };
this.ReplaceSelection(new string(chArray));
}
private static bool isLetterLikeChar(char c)
{
return (char.IsLetterOrDigit(c) || (c == '\''));
}
public bool IsOverSelection(Vector2 cursorPosition)
{
int num = this.style.GetCursorStringIndex(this.position, this.content, cursorPosition + this.scrollOffset);
return ((num < Mathf.Max(this.pos, this.selectPos)) && (num > Mathf.Min(this.pos, this.selectPos)));
}
private static void MapKey(string key, TextEditOp action)
{
s_Keyactions[Event.KeyboardEvent(key)] = action;
}
public void MouseDragSelectsWholeWords(bool on)
{
this.m_MouseDragSelectsWholeWords = on;
this.m_DblClickInitPos = this.pos;
}
public void MoveAltCursorToPosition(Vector2 cursorPosition)
{
this.m_iAltCursorPos = this.style.GetCursorStringIndex(this.position, this.content, cursorPosition + this.scrollOffset);
this.ClampPos();
}
public void MoveCursorToPosition(Vector2 cursorPosition)
{
this.selectPos = this.style.GetCursorStringIndex(this.position, this.content, cursorPosition + this.scrollOffset);
if (!Event.current.shift)
{
this.pos = this.selectPos;
}
this.ClampPos();
}
public void MoveDown()
{
if (this.selectPos > this.pos)
{
this.selectPos = this.pos;
}
else
{
this.pos = this.selectPos;
}
this.GrabGraphicalCursorPos();
this.graphicalCursorPos.y += this.style.lineHeight + 5f;
int num = this.style.GetCursorStringIndex(this.position, this.content, this.graphicalCursorPos);
this.selectPos = num;
this.pos = num;
if (this.pos == this.content.text.Length)
{
this.ClearCursorPos();
}
}
public void MoveGraphicalLineEnd()
{
int graphicalLineEnd = this.GetGraphicalLineEnd((this.pos <= this.selectPos) ? this.selectPos : this.pos);
this.selectPos = graphicalLineEnd;
this.pos = graphicalLineEnd;
}
public void MoveGraphicalLineStart()
{
int graphicalLineStart = this.GetGraphicalLineStart((this.pos >= this.selectPos) ? this.selectPos : this.pos);
this.selectPos = graphicalLineStart;
this.pos = graphicalLineStart;
}
public void MoveLeft()
{
if (this.selectPos == this.pos)
{
this.pos--;
if (this.pos < 0)
{
this.pos = 0;
}
this.selectPos = this.pos;
}
else if (this.selectPos > this.pos)
{
this.selectPos = this.pos;
}
else
{
this.pos = this.selectPos;
}
this.ClearCursorPos();
}
public void MoveLineEnd()
{
int num4;
int num = (this.selectPos <= this.pos) ? this.pos : this.selectPos;
int num2 = num;
int length = this.content.text.Length;
while (num2 < length)
{
if (this.content.text[num2] == '\n')
{
num4 = num2;
this.pos = num4;
this.selectPos = num4;
return;
}
num2++;
}
num4 = length;
this.pos = num4;
this.selectPos = num4;
}
public void MoveLineStart()
{
int num = (this.selectPos >= this.pos) ? this.pos : this.selectPos;
int num2 = num;
while (num2-- != 0)
{
if (this.content.text[num2] == '\n')
{
int num3 = num2 + 1;
this.pos = num3;
this.selectPos = num3;
return;
}
}
this.pos = 0;
this.selectPos = 0;
}
public void MoveParagraphBackward()
{
this.pos = (this.pos >= this.selectPos) ? this.selectPos : this.pos;
if (this.pos > 1)
{
int num = this.content.text.LastIndexOf('\n', this.pos - 2) + 1;
this.pos = num;
this.selectPos = num;
}
else
{
this.pos = 0;
this.selectPos = 0;
}
}
public void MoveParagraphForward()
{
this.pos = (this.pos <= this.selectPos) ? this.selectPos : this.pos;
if (this.pos < this.content.text.Length)
{
int index = this.content.text.IndexOf('\n', this.pos + 1);
this.pos = index;
this.selectPos = index;
if (this.pos == -1)
{
index = this.content.text.Length;
this.pos = index;
this.selectPos = index;
}
}
}
public void MoveRight()
{
this.ClearCursorPos();
if (this.selectPos == this.pos)
{
this.pos++;
this.ClampPos();
this.selectPos = this.pos;
}
else if (this.selectPos > this.pos)
{
this.pos = this.selectPos;
}
else
{
this.selectPos = this.pos;
}
}
public void MoveSelectionToAltCursor()
{
if (this.m_iAltCursorPos != -1)
{
int iAltCursorPos = this.m_iAltCursorPos;
string selectedText = this.SelectedText;
this.content.text = this.content.text.Insert(iAltCursorPos, selectedText);
if (iAltCursorPos < this.pos)
{
this.pos += selectedText.Length;
this.selectPos += selectedText.Length;
}
this.DeleteSelection();
int num2 = iAltCursorPos;
this.pos = num2;
this.selectPos = num2;
this.ClearCursorPos();
}
}
public void MoveTextEnd()
{
int length = this.content.text.Length;
this.pos = length;
this.selectPos = length;
}
public void MoveTextStart()
{
this.pos = 0;
this.selectPos = 0;
}
public void MoveToEndOfPreviousWord()
{
this.ClearCursorPos();
if (this.pos != this.selectPos)
{
this.MoveLeft();
}
else
{
int num = this.FindEndOfPreviousWord(this.pos);
this.selectPos = num;
this.pos = num;
}
}
public void MoveToStartOfNextWord()
{
this.ClearCursorPos();
if (this.pos != this.selectPos)
{
this.MoveRight();
}
else
{
int num = this.FindStartOfNextWord(this.pos);
this.selectPos = num;
this.pos = num;
}
}
public void MoveUp()
{
if (this.selectPos < this.pos)
{
this.selectPos = this.pos;
}
else
{
this.pos = this.selectPos;
}
this.GrabGraphicalCursorPos();
this.graphicalCursorPos.y--;
int num = this.style.GetCursorStringIndex(this.position, this.content, this.graphicalCursorPos);
this.selectPos = num;
this.pos = num;
if (this.pos <= 0)
{
this.ClearCursorPos();
}
}
public void MoveWordLeft()
{
this.pos = (this.pos >= this.selectPos) ? this.selectPos : this.pos;
this.pos = this.FindPrevSeperator(this.pos);
this.selectPos = this.pos;
}
public void MoveWordRight()
{
this.pos = (this.pos <= this.selectPos) ? this.selectPos : this.pos;
int num = this.FindNextSeperator(this.pos);
this.selectPos = num;
this.pos = num;
this.ClearCursorPos();
}
public void OnFocus()
{
if (this.multiline)
{
this.selectPos = 0;
this.pos = 0;
}
else
{
this.SelectAll();
}
}
public virtual void OnLostFocus()
{
this.scrollOffset = Vector2.zero;
}
public bool Paste()
{
string systemCopyBuffer = GUIUtility.systemCopyBuffer;
if (systemCopyBuffer != "")
{
this.ReplaceSelection(systemCopyBuffer);
return true;
}
return false;
}
private bool PerformOperation(TextEditOp operation)
{
switch (operation)
{
case TextEditOp.MoveLeft:
this.MoveLeft();
break;
case TextEditOp.MoveRight:
this.MoveRight();
break;
case TextEditOp.MoveUp:
this.MoveUp();
break;
case TextEditOp.MoveDown:
this.MoveDown();
break;
case TextEditOp.MoveLineStart:
this.MoveLineStart();
break;
case TextEditOp.MoveLineEnd:
this.MoveLineEnd();
break;
case TextEditOp.MoveTextStart:
this.MoveTextStart();
break;
case TextEditOp.MoveTextEnd:
this.MoveTextEnd();
break;
case TextEditOp.MoveGraphicalLineStart:
this.MoveGraphicalLineStart();
break;
case TextEditOp.MoveGraphicalLineEnd:
this.MoveGraphicalLineEnd();
break;
case TextEditOp.MoveWordLeft:
this.MoveWordLeft();
break;
case TextEditOp.MoveWordRight:
this.MoveWordRight();
break;
case TextEditOp.MoveParagraphForward:
this.MoveParagraphForward();
break;
case TextEditOp.MoveParagraphBackward:
this.MoveParagraphBackward();
break;
case TextEditOp.MoveToStartOfNextWord:
this.MoveToStartOfNextWord();
break;
case TextEditOp.MoveToEndOfPreviousWord:
this.MoveToEndOfPreviousWord();
break;
case TextEditOp.SelectLeft:
this.SelectLeft();
break;
case TextEditOp.SelectRight:
this.SelectRight();
break;
case TextEditOp.SelectUp:
this.SelectUp();
break;
case TextEditOp.SelectDown:
this.SelectDown();
break;
case TextEditOp.SelectTextStart:
this.SelectTextStart();
break;
case TextEditOp.SelectTextEnd:
this.SelectTextEnd();
break;
case TextEditOp.ExpandSelectGraphicalLineStart:
this.ExpandSelectGraphicalLineStart();
break;
case TextEditOp.ExpandSelectGraphicalLineEnd:
this.ExpandSelectGraphicalLineEnd();
break;
case TextEditOp.SelectGraphicalLineStart:
this.SelectGraphicalLineStart();
break;
case TextEditOp.SelectGraphicalLineEnd:
this.SelectGraphicalLineEnd();
break;
case TextEditOp.SelectWordLeft:
this.SelectWordLeft();
break;
case TextEditOp.SelectWordRight:
this.SelectWordRight();
break;
case TextEditOp.SelectToEndOfPreviousWord:
this.SelectToEndOfPreviousWord();
break;
case TextEditOp.SelectToStartOfNextWord:
this.SelectToStartOfNextWord();
break;
case TextEditOp.SelectParagraphBackward:
this.SelectParagraphBackward();
break;
case TextEditOp.SelectParagraphForward:
this.SelectParagraphForward();
break;
case TextEditOp.Delete:
return this.Delete();
case TextEditOp.Backspace:
return this.Backspace();
case TextEditOp.Cut:
return this.Cut();
case TextEditOp.Copy:
this.Copy();
break;
case TextEditOp.Paste:
return this.Paste();
case TextEditOp.SelectAll:
this.SelectAll();
break;
case TextEditOp.SelectNone:
this.SelectNone();
break;
default:
Debug.Log("Unimplemented: " + operation);
break;
}
return false;
}
public void ReplaceSelection(string replace)
{
this.DeleteSelection();
this.content.text = this.content.text.Insert(this.pos, replace);
int num = this.pos + replace.Length;
this.pos = num;
this.selectPos = num;
this.ClearCursorPos();
}
public void SaveBackup()
{
this.oldText = this.content.text;
this.oldPos = this.pos;
this.oldSelectPos = this.selectPos;
}
public void SelectAll()
{
this.pos = 0;
this.selectPos = this.content.text.Length;
this.ClearCursorPos();
}
public void SelectCurrentParagraph()
{
this.ClearCursorPos();
int length = this.content.text.Length;
if (this.pos < length)
{
this.pos = this.content.text.IndexOf('\n', this.pos);
if (this.pos == -1)
{
this.pos = this.content.text.Length;
}
else
{
this.pos++;
}
}
if (this.selectPos != 0)
{
this.selectPos = this.content.text.LastIndexOf('\n', this.selectPos - 1) + 1;
}
}
public void SelectCurrentWord()
{
this.ClearCursorPos();
int length = this.content.text.Length;
this.selectPos = this.pos;
if (length != 0)
{
if (this.pos >= length)
{
this.pos = length - 1;
}
if (this.selectPos >= length)
{
this.selectPos--;
}
if (this.pos < this.selectPos)
{
this.pos = this.FindEndOfClassification(this.pos, -1);
this.selectPos = this.FindEndOfClassification(this.selectPos, 1);
}
else
{
this.pos = this.FindEndOfClassification(this.pos, 1);
this.selectPos = this.FindEndOfClassification(this.selectPos, -1);
}
this.m_bJustSelected = true;
}
}
public void SelectDown()
{
this.GrabGraphicalCursorPos();
this.graphicalCursorPos.y += this.style.lineHeight + 5f;
this.pos = this.style.GetCursorStringIndex(this.position, this.content, this.graphicalCursorPos);
}
public void SelectGraphicalLineEnd()
{
this.ClearCursorPos();
this.pos = this.GetGraphicalLineEnd(this.pos);
}
public void SelectGraphicalLineStart()
{
this.ClearCursorPos();
this.pos = this.GetGraphicalLineStart(this.pos);
}
public void SelectLeft()
{
if (this.m_bJustSelected && (this.pos > this.selectPos))
{
int pos = this.pos;
this.pos = this.selectPos;
this.selectPos = pos;
}
this.m_bJustSelected = false;
this.pos--;
if (this.pos < 0)
{
this.pos = 0;
}
}
public void SelectNone()
{
this.selectPos = this.pos;
this.ClearCursorPos();
}
public void SelectParagraphBackward()
{
this.ClearCursorPos();
bool flag = this.pos > this.selectPos;
if (this.pos > 1)
{
this.pos = this.content.text.LastIndexOf('\n', this.pos - 2) + 1;
if (flag && (this.pos < this.selectPos))
{
this.pos = this.selectPos;
}
}
else
{
this.pos = 0;
this.selectPos = 0;
}
}
public void SelectParagraphForward()
{
this.ClearCursorPos();
bool flag = this.pos < this.selectPos;
if (this.pos < this.content.text.Length)
{
this.pos = this.content.text.IndexOf('\n', this.pos + 1);
if (this.pos == -1)
{
this.pos = this.content.text.Length;
}
if (flag && (this.pos > this.selectPos))
{
this.pos = this.selectPos;
}
}
}
public void SelectRight()
{
if (this.m_bJustSelected && (this.pos < this.selectPos))
{
int pos = this.pos;
this.pos = this.selectPos;
this.selectPos = pos;
}
this.m_bJustSelected = false;
this.pos++;
int length = this.content.text.Length;
if (this.pos > length)
{
this.pos = length;
}
}
public void SelectTextEnd()
{
this.pos = this.content.text.Length;
}
public void SelectTextStart()
{
this.pos = 0;
}
public void SelectToEndOfPreviousWord()
{
this.ClearCursorPos();
this.pos = this.FindEndOfPreviousWord(this.pos);
}
public void SelectToPosition(Vector2 cursorPosition)
{
if (!this.m_MouseDragSelectsWholeWords)
{
this.pos = this.style.GetCursorStringIndex(this.position, this.content, cursorPosition + this.scrollOffset);
}
else
{
int p = this.style.GetCursorStringIndex(this.position, this.content, cursorPosition + this.scrollOffset);
if (this.m_DblClickSnap == DblClickSnapping.WORDS)
{
if (p < this.m_DblClickInitPos)
{
this.pos = this.FindEndOfClassification(p, -1);
this.selectPos = this.FindEndOfClassification(this.m_DblClickInitPos, 1);
}
else
{
if (p >= this.content.text.Length)
{
p = this.content.text.Length - 1;
}
this.pos = this.FindEndOfClassification(p, 1);
this.selectPos = this.FindEndOfClassification(this.m_DblClickInitPos - 1, -1);
}
}
else if (p < this.m_DblClickInitPos)
{
if (p > 0)
{
this.pos = this.content.text.LastIndexOf('\n', p - 2) + 1;
}
else
{
this.pos = 0;
}
this.selectPos = this.content.text.LastIndexOf('\n', this.m_DblClickInitPos);
}
else
{
if (p < this.content.text.Length)
{
this.pos = this.content.text.IndexOf('\n', p + 1) + 1;
if (this.pos <= 0)
{
this.pos = this.content.text.Length;
}
}
else
{
this.pos = this.content.text.Length;
}
this.selectPos = this.content.text.LastIndexOf('\n', this.m_DblClickInitPos - 2) + 1;
}
}
}
public void SelectToStartOfNextWord()
{
this.ClearCursorPos();
this.pos = this.FindStartOfNextWord(this.pos);
}
public void SelectUp()
{
this.GrabGraphicalCursorPos();
this.graphicalCursorPos.y--;
this.pos = this.style.GetCursorStringIndex(this.position, this.content, this.graphicalCursorPos);
}
public void SelectWordLeft()
{
this.ClearCursorPos();
int selectPos = this.selectPos;
if (this.pos > this.selectPos)
{
this.selectPos = this.pos;
this.MoveWordLeft();
this.selectPos = selectPos;
this.pos = (this.pos <= this.selectPos) ? this.selectPos : this.pos;
}
else
{
this.selectPos = this.pos;
this.MoveWordLeft();
this.selectPos = selectPos;
}
}
public void SelectWordRight()
{
this.ClearCursorPos();
int selectPos = this.selectPos;
if (this.pos < this.selectPos)
{
this.selectPos = this.pos;
this.MoveWordRight();
this.selectPos = selectPos;
this.pos = (this.pos >= this.selectPos) ? this.selectPos : this.pos;
}
else
{
this.selectPos = this.pos;
this.MoveWordRight();
this.selectPos = selectPos;
}
}
public void Undo()
{
this.content.text = this.oldText;
this.pos = this.oldPos;
this.selectPos = this.oldSelectPos;
}
// Properties
public bool hasSelection
{
get
{
return (this.pos != this.selectPos);
}
}
public string SelectedText
{
get
{
int length = this.content.text.Length;
if (this.pos > length)
{
this.pos = length;
}
if (this.selectPos > length)
{
this.selectPos = length;
}
if (this.pos == this.selectPos)
{
return "";
}
if (this.pos < this.selectPos)
{
return this.content.text.Substring(this.pos, this.selectPos - this.pos);
}
return this.content.text.Substring(this.selectPos, this.pos - this.selectPos);
}
}
// Nested Types
private enum CharacterType
{
LetterLike,
Symbol,
Symbol2,
WhiteSpace
}
public enum DblClickSnapping : byte
{
PARAGRAPHS = 1,
WORDS = 0
}
private enum TextEditOp
{
MoveLeft,
MoveRight,
MoveUp,
MoveDown,
MoveLineStart,
MoveLineEnd,
MoveTextStart,
MoveTextEnd,
MovePageUp,
MovePageDown,
MoveGraphicalLineStart,
MoveGraphicalLineEnd,
MoveWordLeft,
MoveWordRight,
MoveParagraphForward,
MoveParagraphBackward,
MoveToStartOfNextWord,
MoveToEndOfPreviousWord,
SelectLeft,
SelectRight,
SelectUp,
SelectDown,
SelectTextStart,
SelectTextEnd,
SelectPageUp,
SelectPageDown,
ExpandSelectGraphicalLineStart,
ExpandSelectGraphicalLineEnd,
SelectGraphicalLineStart,
SelectGraphicalLineEnd,
SelectWordLeft,
SelectWordRight,
SelectToEndOfPreviousWord,
SelectToStartOfNextWord,
SelectParagraphBackward,
SelectParagraphForward,
Delete,
Backspace,
DeleteWordBack,
Cut,
Copy,
Paste,
SelectAll,
SelectNone,
ScrollStart,
ScrollEnd,
ScrollPageUp,
ScrollPageDown
}
}