public virtual void KeyPressed(KeyEvent e)
{
int code = e.GetKeyCode();
if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT)
{
if (outputMark == GetCaretPosition())
{
e.Consume();
}
}
else
{
if (code == KeyEvent.VK_HOME)
{
int caretPos = GetCaretPosition();
if (caretPos == outputMark)
{
e.Consume();
}
else
{
if (caretPos > outputMark)
{
if (!e.IsControlDown())
{
if (e.IsShiftDown())
{
MoveCaretPosition(outputMark);
}
else
{
SetCaretPosition(outputMark);
}
e.Consume();
}
}
}
}
else
{
if (code == KeyEvent.VK_ENTER)
{
ReturnPressed();
e.Consume();
}
else
{
if (code == KeyEvent.VK_UP)
{
historyIndex--;
if (historyIndex >= 0)
{
if (historyIndex >= history.Count)
{
historyIndex = history.Count - 1;
}
if (historyIndex >= 0)
{
string str = history[historyIndex];
int len = GetDocument().GetLength();
ReplaceRange(str, outputMark, len);
int caretPos = outputMark + str.Length;
Select(caretPos, caretPos);
}
else
{
historyIndex++;
}
}
else
{
historyIndex++;
}
e.Consume();
}
else
{
if (code == KeyEvent.VK_DOWN)
{
int caretPos = outputMark;
if (history.Count > 0)
{
historyIndex++;
if (historyIndex < 0)
{
historyIndex = 0;
}
int len = GetDocument().GetLength();
if (historyIndex < history.Count)
{
string str = history[historyIndex];
ReplaceRange(str, outputMark, len);
caretPos = outputMark + str.Length;
}
else
{
historyIndex = history.Count;
ReplaceRange(string.Empty, outputMark, len);
}
}
Select(caretPos, caretPos);
e.Consume();
}
}
}
}
}
}