From 6262dd60a0b68967356da2ad5cab6ac9a84c983d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 30 Jan 2014 18:58:03 +0100 Subject: [PATCH] fix #310: InsertWithCursor should support Home/End/PageDown/PageUp keys --- .../Project/Src/Refactoring/EditorScript.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs index 48f927e385..1dc3731452 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs @@ -329,6 +329,10 @@ namespace CSharpBinding.Refactoring this.layer = layer; AddBinding(EditingCommands.MoveDownByLine, ModifierKeys.None, Key.Down, MoveMarker(false)); AddBinding(EditingCommands.MoveUpByLine, ModifierKeys.None, Key.Up, MoveMarker(true)); + AddBinding(EditingCommands.MoveDownByPage, ModifierKeys.None, Key.PageDown, MoveMarkerPage(false)); + AddBinding(EditingCommands.MoveUpByPage, ModifierKeys.None, Key.PageUp, MoveMarkerPage(true)); + AddBinding(EditingCommands.MoveToLineStart, ModifierKeys.None, Key.Home, MoveMarkerFull(true)); + AddBinding(EditingCommands.MoveToLineEnd, ModifierKeys.None, Key.End, MoveMarkerFull(false)); AddBinding(EditingCommands.EnterParagraphBreak, ModifierKeys.None, Key.Enter, layer.InsertCode); AddBinding(ExitCommand, ModifierKeys.None, Key.Escape, layer.Cancel); } @@ -344,6 +348,49 @@ namespace CSharpBinding.Refactoring layer.ScrollToInsertionPoint(); }; } + + ExecutedRoutedEventHandler MoveMarkerPage(bool up) + { + return (sender, e) => { + TextLocation current = layer.insertionPoints[layer.CurrentInsertionPoint].Location; + double currentVPos = layer.editor.TextView.GetVisualTopByDocumentLine(current.Line); + + int newIndex = layer.CurrentInsertionPoint; + + double newVPos; + do { + if (up) { + newIndex--; + if (newIndex < 0) { + newIndex = 0; + break; + } + } else { + newIndex++; + if (newIndex >= layer.insertionPoints.Length) { + newIndex = layer.insertionPoints.Length - 1; + break; + } + } + newVPos = layer.editor.TextView.GetVisualTopByDocumentLine(layer.insertionPoints[newIndex].Location.Line); + } while (Math.Abs(currentVPos - newVPos) < layer.editor.ActualHeight); + layer.CurrentInsertionPoint = newIndex; + layer.InvalidateVisual(); + layer.ScrollToInsertionPoint(); + }; + } + + ExecutedRoutedEventHandler MoveMarkerFull(bool up) + { + return (sender, e) => { + if (up) + layer.CurrentInsertionPoint = 0; + else + layer.CurrentInsertionPoint = layer.insertionPoints.Length - 1; + layer.InvalidateVisual(); + layer.ScrollToInsertionPoint(); + }; + } } public void Dispose()