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()