diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2016-04-18 14:20:07 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@xamarin.com> | 2016-04-18 14:38:58 +0300 |
commit | 760623d2dc4bd70afcd6a5deeaec7d3d4521a174 (patch) | |
tree | e130281fdaef05317a12dc8564d1316075fe30e8 | |
parent | ef2bfc35a63b03e6b0cdcb032e431f275c089f9d (diff) |
[TextEditor] Added command for focussing & centering.
Centering the caret is now at 33% no longer at 50%
(cherry picked from commit 93b5af7c4c2b940f0f071eb1641131a8035ba125)
3 files changed, 22 insertions, 2 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs index b13c87e7ef..ef32ab7282 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/TextArea.cs @@ -1543,7 +1543,7 @@ namespace Mono.TextEditor // int yMargin = 1 * this.LineHeight; double caretPosition = editor.TextArea.LineToY (p.Line); - caretPosition -= editor.TextArea.textEditorData.VAdjustment.PageSize / 2; + caretPosition -= editor.TextArea.textEditorData.VAdjustment.PageSize / 3; // Make sure the caret position is inside the bounds. This avoids an unnecessary bump of the scrollview. // The adjustment does this check, but does it after assigning the value, so the value may be out of bounds for a while. diff --git a/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml b/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml index 0652e3002a..26fc8bfdb8 100644 --- a/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml +++ b/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml @@ -668,6 +668,11 @@ _label = "_Cursor Position" shortcut = "Alt|C" _description = "Go to Cursor Position" /> + <Command id = "MonoDevelop.Ide.Commands.ViewCommands.CenterAndFocusCurrentDocument" + defaultHandler = "MonoDevelop.Ide.Commands.CenterAndFocusCurrentDocumentHandler" + _label = "Center and F_ocus Document" + shortcut = "Alt|Shift|C" + _description = "Focus and center current document" /> <Command id = "MonoDevelop.Ide.Commands.ViewCommands.ShowWelcomePage" defaultHandler = "MonoDevelop.Ide.WelcomePage.ShowWelcomePageHandler" _label = "Welcome Page" diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ViewCommands.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ViewCommands.cs index 86c3e97c9e..8644f78a30 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ViewCommands.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ViewCommands.cs @@ -58,6 +58,7 @@ namespace MonoDevelop.Ide.Commands ZoomOut, ZoomReset, FocusCurrentDocument, + CenterAndFocusCurrentDocument, ShowWelcomePage } @@ -409,7 +410,7 @@ namespace MonoDevelop.Ide.Commands window.MoveToPreviousNotebook (); } } - + public class FocusCurrentDocumentHandler : CommandHandler { protected override void Update (CommandInfo info) @@ -424,4 +425,18 @@ namespace MonoDevelop.Ide.Commands } } + + public class CenterAndFocusCurrentDocumentHandler : CommandHandler + { + protected override void Update (CommandInfo info) + { + info.Enabled = IdeApp.Workbench.ActiveDocument != null && IdeApp.Workbench.ActiveDocument.Editor != null; + } + + protected override void Run () + { + IdeApp.Workbench.ActiveDocument.Editor.CenterToCaret (); + IdeApp.Workbench.ActiveDocument.Editor.StartCaretPulseAnimation (); + } + } } |