HexView: PageUp, PageDown, Home

This commit is contained in:
miguel
2018-05-10 23:22:35 -04:00
parent 11b4e45920
commit b260d12ea1
2 changed files with 42 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
//
// TODO:
// - Support searching and highlighting of the search result
// - Support PageUp/PageDown/Home/End
// - Bug showing the last line
//
using System;
using System.Collections.Generic;
@@ -254,6 +254,32 @@ namespace Terminal.Gui {
RedisplayLine (position);
}
void MoveUp (int bytes)
{
RedisplayLine (position);
position -= bytes;
if (position < 0)
position = 0;
if (position < DisplayStart) {
SetDisplayStart (DisplayStart - bytes);
SetNeedsDisplay ();
} else
RedisplayLine (position);
}
void MoveDown (int bytes)
{
RedisplayLine (position);
if (position + bytes < source.Length)
position += bytes;
if (position >= (DisplayStart + bytesPerLine * Frame.Height)) {
SetDisplayStart (DisplayStart + bytes);
SetNeedsDisplay ();
} else
RedisplayLine (position);
}
public override bool ProcessKey (KeyEvent keyEvent)
{
switch (keyEvent.Key) {
@@ -279,32 +305,28 @@ namespace Terminal.Gui {
CursorRight ();
break;
case Key.CursorDown:
RedisplayLine (position);
if (position + bytesPerLine < source.Length)
position += bytesPerLine;
if (position >= (DisplayStart + bytesPerLine * Frame.Height)) {
SetDisplayStart (DisplayStart + bytesPerLine);
SetNeedsDisplay ();
} else
RedisplayLine (position);
MoveDown (bytesPerLine);
break;
case Key.CursorUp:
RedisplayLine (position);
position -= bytesPerLine;
if (position < 0)
position = 0;
if (position < DisplayStart) {
SetDisplayStart (DisplayStart - bytesPerLine);
SetNeedsDisplay ();
} else
RedisplayLine (position);
MoveUp (bytesPerLine);
break;
case Key.Tab:
leftSide = !leftSide;
RedisplayLine (position);
firstNibble = true;
break;
case ((int)'v' + Key.AltMask):
case Key.PageUp:
MoveUp (bytesPerLine * Frame.Height);
break;
case Key.ControlV:
case Key.PageDown:
MoveDown (bytesPerLine * Frame.Height);
break;
case Key.Home:
DisplayStart = 0;
SetNeedsDisplay ();
break;
default:
if (leftSide) {
int value = -1;

View File

@@ -6,6 +6,7 @@
//
//
// TODO:
// PageUp/PageDown
// Attributed text on spans
// Replace insertion with Insert method
// String accumulation (Control-k, control-k is not preserving the last new line, see StringToRunes