From 88a2781d857d98c7ee56eace3bc258c4e6976322 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Thu, 21 May 2015 15:53:06 -0700 Subject: [PATCH] Rename dashboard navigation tweaks * Dashboard is no longer focused when starting inline rename * F2 outside a rename field commits the current session and starts a new one * F2 within a rename field focuses the dashboard --- .../RenameCommandHandler_RenameHandler.cs | 28 +++++++++++++------ .../InlineRename/Dashboard/Dashboard.xaml.cs | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/InlineRename/CommandHandlers/RenameCommandHandler_RenameHandler.cs b/src/EditorFeatures/Core/Implementation/InlineRename/CommandHandlers/RenameCommandHandler_RenameHandler.cs index 2042a8879a267..d61f63ec772c0 100644 --- a/src/EditorFeatures/Core/Implementation/InlineRename/CommandHandlers/RenameCommandHandler_RenameHandler.cs +++ b/src/EditorFeatures/Core/Implementation/InlineRename/CommandHandlers/RenameCommandHandler_RenameHandler.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.SuggestionSupport; using Microsoft.CodeAnalysis.Notification; using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename @@ -58,14 +59,6 @@ public void ExecuteCommand(RenameCommandArgs args, Action nextHandler) private void ExecuteRenameWorker(RenameCommandArgs args, CancellationToken cancellationToken) { - // If there is already an active session, focus its dashboard; - if (_renameService.ActiveSession != null) - { - var dashboard = GetDashboard(args.TextView); - dashboard.Focus(); - return; - } - var snapshot = args.SubjectBuffer.CurrentSnapshot; Workspace workspace; if (!Workspace.TryGetWorkspace(snapshot.AsText().Container, out workspace)) @@ -80,6 +73,25 @@ private void ExecuteRenameWorker(RenameCommandArgs args, CancellationToken cance return; } + // If there is already an active session, commit it first + if (_renameService.ActiveSession != null) + { + // Is the caret within any of the rename fields in this buffer? + // If so, focus the dashboard + SnapshotSpan editableSpan; + if (_renameService.ActiveSession.TryGetContainingEditableSpan(caretPoint.Value, out editableSpan)) + { + var dashboard = GetDashboard(args.TextView); + dashboard.Focus(); + return; + } + else + { + // Otherwise, commit the existing session and start a new one. + _renameService.ActiveSession.Commit(); + } + } + var position = caretPoint.Value; var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) diff --git a/src/EditorFeatures/Core/Implementation/InlineRename/Dashboard/Dashboard.xaml.cs b/src/EditorFeatures/Core/Implementation/InlineRename/Dashboard/Dashboard.xaml.cs index 3f8fc1d6f82c6..d6e952a86fc10 100644 --- a/src/EditorFeatures/Core/Implementation/InlineRename/Dashboard/Dashboard.xaml.cs +++ b/src/EditorFeatures/Core/Implementation/InlineRename/Dashboard/Dashboard.xaml.cs @@ -70,7 +70,7 @@ public Dashboard( this.Focus(); textView.Caret.IsHidden = false; - ShouldReceiveKeyboardNavigation = true; + ShouldReceiveKeyboardNavigation = false; } private void ShowCaret()