Support PgUp/PgDn
This commit is contained in:
parent
a7207aaab1
commit
57486aac9c
@ -134,8 +134,8 @@ namespace MApplication
|
||||
_ when CursorRelativeLine == Height - 1 =>
|
||||
With(
|
||||
out changed1,
|
||||
startingLine: Math.Min(CursorAbsoluteLine + 1, Text.Lines.Count) - Height + 1,
|
||||
cursorAbsoluteLine: Math.Min(CursorAbsoluteLine + 1, Text.Lines.Count)),
|
||||
startingLine: Math.Min(CursorAbsoluteLine + 1, Text.Lines.Count - 1) - Height + 1,
|
||||
cursorAbsoluteLine: Math.Min(CursorAbsoluteLine + 1, Text.Lines.Count - 1)),
|
||||
_ => With(
|
||||
out changed1,
|
||||
cursorAbsoluteLine: CursorAbsoluteLine + 1),
|
||||
@ -145,6 +145,28 @@ namespace MApplication
|
||||
return result;
|
||||
}
|
||||
|
||||
internal DisplayTextViewPort PageDown(out bool needsRedraw)
|
||||
{
|
||||
var result1 = With(
|
||||
out var changed1,
|
||||
startingLine: Math.Min(StartingLine + Height, Text.Lines.Count - 1),
|
||||
cursorAbsoluteLine: Math.Min(CursorAbsoluteLine + Height, Text.Lines.Count - 1));
|
||||
var result = result1.SnapToLine(out var changed2);
|
||||
needsRedraw = changed1 || changed2;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal DisplayTextViewPort PageUp(out bool needsRedraw)
|
||||
{
|
||||
var result1 = With(
|
||||
out var changed1,
|
||||
startingLine: Math.Max(StartingLine - Height, 0),
|
||||
cursorAbsoluteLine: Math.Max(CursorAbsoluteLine - Height, 0));
|
||||
var result = result1.SnapToLine(out var changed2);
|
||||
needsRedraw = changed1 || changed2;
|
||||
return result;
|
||||
}
|
||||
|
||||
public DisplayTextViewPort CursorHome(out bool needsRedraw)
|
||||
{
|
||||
return With(
|
||||
|
@ -47,35 +47,24 @@ namespace MApplication
|
||||
_outputView.MoveCursorTo(viewPort.CursorRelativeColumn, viewPort.CursorRelativeLine);
|
||||
|
||||
var key = Console.ReadKey(intercept: true);
|
||||
switch (key.Key)
|
||||
viewPort = key.Key switch
|
||||
{
|
||||
case ConsoleKey.LeftArrow:
|
||||
viewPort = viewPort.CursorLeft(out needsRedraw);
|
||||
break;
|
||||
|
||||
case ConsoleKey.RightArrow:
|
||||
viewPort = viewPort.CursorRight(out needsRedraw);
|
||||
break;
|
||||
|
||||
case ConsoleKey.UpArrow:
|
||||
viewPort = viewPort.CursorUp(out needsRedraw);
|
||||
break;
|
||||
|
||||
case ConsoleKey.DownArrow:
|
||||
viewPort = viewPort.CursorDown(out needsRedraw);
|
||||
break;
|
||||
|
||||
case ConsoleKey.Home:
|
||||
viewPort = viewPort.CursorHome(out needsRedraw);
|
||||
break;
|
||||
|
||||
case ConsoleKey.End:
|
||||
viewPort = viewPort.CursorEnd(out needsRedraw);
|
||||
break;
|
||||
ConsoleKey.LeftArrow => viewPort.CursorLeft(out needsRedraw),
|
||||
ConsoleKey.RightArrow => viewPort.CursorRight(out needsRedraw),
|
||||
ConsoleKey.UpArrow => viewPort.CursorUp(out needsRedraw),
|
||||
ConsoleKey.DownArrow => viewPort.CursorDown(out needsRedraw),
|
||||
ConsoleKey.Home => viewPort.CursorHome(out needsRedraw),
|
||||
ConsoleKey.End => viewPort.CursorEnd(out needsRedraw),
|
||||
ConsoleKey.PageUp => viewPort.PageUp(out needsRedraw),
|
||||
ConsoleKey.PageDown => viewPort.PageDown(out needsRedraw),
|
||||
_ => viewPort,
|
||||
};
|
||||
if (key.Key == ConsoleKey.Q)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Program
|
||||
|
Loading…
x
Reference in New Issue
Block a user