diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/CommandHandlers/RenameCommandHandler.cs b/src/EditorFeatures/Core.Wpf/InlineRename/CommandHandlers/RenameCommandHandler.cs
index 57f249768fa80..9283a50c0bf08 100644
--- a/src/EditorFeatures/Core.Wpf/InlineRename/CommandHandlers/RenameCommandHandler.cs
+++ b/src/EditorFeatures/Core.Wpf/InlineRename/CommandHandlers/RenameCommandHandler.cs
@@ -94,11 +94,11 @@ protected override void SetAdornmentFocusToPreviousElement(ITextView textView)
}
}
- protected override void Commit(InlineRenameSession activeSession, ITextView textView)
+ protected override void CommitAndSetFocus(InlineRenameSession activeSession, ITextView textView, IUIThreadOperationContext operationContext)
{
try
{
- base.Commit(activeSession, textView);
+ base.CommitAndSetFocus(activeSession, textView, operationContext);
}
catch (NotSupportedException ex)
{
diff --git a/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs b/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs
index ef1fb91477479..4c5351e60b5c7 100644
--- a/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs
+++ b/src/EditorFeatures/Core/ExtractMethod/ExtractMethodCommandHandler.cs
@@ -88,7 +88,7 @@ public bool ExecuteCommand(ExtractMethodCommandArgs args, CommandExecutionContex
// wait indicator for Extract Method
if (_renameService.ActiveSession != null)
{
- _threadingContext.JoinableTaskFactory.Run(() => _renameService.ActiveSession.CommitAsync(previewChanges: false));
+ _threadingContext.JoinableTaskFactory.Run(() => _renameService.ActiveSession.CommitAsync(previewChanges: false, context.OperationContext));
}
if (!args.SubjectBuffer.SupportsRefactorings())
diff --git a/src/EditorFeatures/Core/IInlineRenameSession.cs b/src/EditorFeatures/Core/IInlineRenameSession.cs
index 431a1f6491f0d..36bc73cebd506 100644
--- a/src/EditorFeatures/Core/IInlineRenameSession.cs
+++ b/src/EditorFeatures/Core/IInlineRenameSession.cs
@@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor;
@@ -50,5 +51,5 @@ internal interface IInlineRenameSession
///
/// Dismisses the rename session, completing the rename operation across all files.
///
- Task CommitAsync(bool previewChanges);
+ Task CommitAsync(bool previewChanges, IUIThreadOperationContext editorOperationContext = null);
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler.cs
index 3a54313a64f99..327254149e670 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler.cs
@@ -11,6 +11,8 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Utilities;
+using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;
@@ -55,7 +57,7 @@ private CommandState GetCommandState(Func nextHandler)
private CommandState GetCommandState()
=> _renameService.ActiveSession != null ? CommandState.Available : CommandState.Unspecified;
- private void HandlePossibleTypingCommand(TArgs args, Action nextHandler, Action actionIfInsideActiveSpan)
+ private void HandlePossibleTypingCommand(TArgs args, Action nextHandler, IUIThreadOperationContext operationContext, Action actionIfInsideActiveSpan)
where TArgs : EditorCommandArgs
{
if (_renameService.ActiveSession == null)
@@ -78,14 +80,14 @@ private void HandlePossibleTypingCommand(TArgs args, Action nextHandler,
if (_renameService.ActiveSession.TryGetContainingEditableSpan(singleSpan.Start, out var containingSpan) &&
containingSpan.Contains(singleSpan))
{
- actionIfInsideActiveSpan(_renameService.ActiveSession, containingSpan);
+ actionIfInsideActiveSpan(_renameService.ActiveSession, operationContext, containingSpan);
}
else if (_renameService.ActiveSession.IsInOpenTextBuffer(singleSpan.Start))
{
// It's in a read-only area that is open, so let's commit the rename
// and then let the character go through
- CommitIfActiveAndCallNextHandler(args, nextHandler);
+ CommitIfActiveAndCallNextHandler(args, nextHandler, operationContext);
}
else
{
@@ -94,13 +96,13 @@ private void HandlePossibleTypingCommand(TArgs args, Action nextHandler,
}
}
- private void CommitIfActive(EditorCommandArgs args)
+ private void CommitIfActive(EditorCommandArgs args, IUIThreadOperationContext operationContext)
{
if (_renameService.ActiveSession != null)
{
var selection = args.TextView.Selection.VirtualSelectedSpans.First();
- _renameService.ActiveSession.Commit();
+ Commit(operationContext);
var translatedSelection = selection.TranslateTo(args.TextView.TextBuffer.CurrentSnapshot);
args.TextView.Selection.Select(translatedSelection.Start, translatedSelection.End);
@@ -108,9 +110,15 @@ private void CommitIfActive(EditorCommandArgs args)
}
}
- private void CommitIfActiveAndCallNextHandler(EditorCommandArgs args, Action nextHandler)
+ private void CommitIfActiveAndCallNextHandler(EditorCommandArgs args, Action nextHandler, IUIThreadOperationContext operationContext)
{
- CommitIfActive(args);
+ CommitIfActive(args, operationContext);
nextHandler();
}
+
+ private void Commit(IUIThreadOperationContext operationContext)
+ {
+ RoslynDebug.AssertNotNull(_renameService.ActiveSession);
+ _renameService.ActiveSession.Commit(previewChanges: false, operationContext);
+ }
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_BackspaceDeleteHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_BackspaceDeleteHandler.cs
index 21c6c04c1dea9..d068c352e5600 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_BackspaceDeleteHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_BackspaceDeleteHandler.cs
@@ -21,7 +21,7 @@ public CommandState GetCommandState(DeleteKeyCommandArgs args, Func
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
var caretPoint = args.TextView.GetCaretPoint(args.SubjectBuffer);
if (!args.TextView.Selection.IsEmpty || caretPoint.Value != span.Start)
@@ -33,7 +33,7 @@ public void ExecuteCommand(BackspaceKeyCommandArgs args, Action nextHandler, Com
public void ExecuteCommand(DeleteKeyCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
- HandlePossibleTypingCommand(args, nextHandler, (activeSession, span) =>
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
var caretPoint = args.TextView.GetCaretPoint(args.SubjectBuffer);
if (!args.TextView.Selection.IsEmpty || caretPoint.Value != span.End)
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_CutPasteHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_CutPasteHandler.cs
index 3448d2eda764c..89affbfabdeb9 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_CutPasteHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_CutPasteHandler.cs
@@ -16,7 +16,7 @@ public CommandState GetCommandState(CutCommandArgs args, Func next
public void ExecuteCommand(CutCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
- HandlePossibleTypingCommand(args, nextHandler, (activeSession, span) =>
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
nextHandler();
});
@@ -27,7 +27,7 @@ public CommandState GetCommandState(PasteCommandArgs args, Func ne
public void ExecuteCommand(PasteCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
- HandlePossibleTypingCommand(args, nextHandler, (activeSession, span) =>
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
nextHandler();
});
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_MoveSelectedLinesHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_MoveSelectedLinesHandler.cs
index ffee45ee36f18..e9a140815a143 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_MoveSelectedLinesHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_MoveSelectedLinesHandler.cs
@@ -15,7 +15,7 @@ public CommandState GetCommandState(MoveSelectedLinesUpCommandArgs args)
public bool ExecuteCommand(MoveSelectedLinesUpCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
@@ -24,7 +24,7 @@ public CommandState GetCommandState(MoveSelectedLinesDownCommandArgs args)
public bool ExecuteCommand(MoveSelectedLinesDownCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineAboveHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineAboveHandler.cs
index 6670627524316..830552a35e14c 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineAboveHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineAboveHandler.cs
@@ -15,9 +15,9 @@ public CommandState GetCommandState(OpenLineAboveCommandArgs args, Func
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, operationContext, span) =>
{
- activeSession.Commit();
+ Commit(operationContext);
nextHandler();
});
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineBelowHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineBelowHandler.cs
index e8649fbf5577c..5bb99425cdae2 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineBelowHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_OpenLineBelowHandler.cs
@@ -15,9 +15,9 @@ public CommandState GetCommandState(OpenLineBelowCommandArgs args, Func
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, operationContext, span) =>
{
- activeSession.Commit();
+ Commit(operationContext);
nextHandler();
});
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RefactoringWithCommandHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RefactoringWithCommandHandler.cs
index 8c403e0d14712..a3413138c2e74 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RefactoringWithCommandHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RefactoringWithCommandHandler.cs
@@ -18,7 +18,7 @@ public CommandState GetCommandState(ReorderParametersCommandArgs args)
public bool ExecuteCommand(ReorderParametersCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
@@ -27,7 +27,7 @@ public CommandState GetCommandState(RemoveParametersCommandArgs args)
public bool ExecuteCommand(RemoveParametersCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
@@ -36,7 +36,7 @@ public CommandState GetCommandState(ExtractInterfaceCommandArgs args)
public bool ExecuteCommand(ExtractInterfaceCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
@@ -45,7 +45,7 @@ public CommandState GetCommandState(EncapsulateFieldCommandArgs args)
public bool ExecuteCommand(EncapsulateFieldCommandArgs args, CommandExecutionContext context)
{
- CommitIfActive(args);
+ CommitIfActive(args, context.OperationContext);
return false;
}
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RenameHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RenameHandler.cs
index 25d0fb76612a0..8fce77aa75c2b 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RenameHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_RenameHandler.cs
@@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
+using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;
@@ -43,11 +44,11 @@ public bool ExecuteCommand(RenameCommandArgs args, CommandExecutionContext conte
}
var token = _listener.BeginAsyncOperation(nameof(ExecuteCommand));
- _ = ExecuteCommandAsync(args).CompletesAsyncOperation(token);
+ _ = ExecuteCommandAsync(args, context.OperationContext).CompletesAsyncOperation(token);
return true;
}
- private async Task ExecuteCommandAsync(RenameCommandArgs args)
+ private async Task ExecuteCommandAsync(RenameCommandArgs args, IUIThreadOperationContext editorOperationContext)
{
_threadingContext.ThrowIfNotOnUIThread();
@@ -63,12 +64,6 @@ private async Task ExecuteCommandAsync(RenameCommandArgs args)
return;
}
- var backgroundWorkIndicatorFactory = workspace.Services.GetRequiredService();
- using var context = backgroundWorkIndicatorFactory.Create(
- args.TextView,
- args.TextView.GetTextElementSpan(caretPoint.Value),
- EditorFeaturesResources.Finding_token_to_rename);
-
// If there is already an active session, commit it first
if (_renameService.ActiveSession != null)
{
@@ -82,10 +77,16 @@ private async Task ExecuteCommandAsync(RenameCommandArgs args)
else
{
// Otherwise, commit the existing session and start a new one.
- _renameService.ActiveSession.Commit();
+ Commit(editorOperationContext);
}
}
+ var backgroundWorkIndicatorFactory = workspace.Services.GetRequiredService();
+ using var context = backgroundWorkIndicatorFactory.Create(
+ args.TextView,
+ args.TextView.GetTextElementSpan(caretPoint.Value),
+ EditorFeaturesResources.Finding_token_to_rename);
+
var cancellationToken = context.UserCancellationToken;
var document = await args
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_ReturnHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_ReturnHandler.cs
index 5cb04c3f18579..db18065f46759 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_ReturnHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_ReturnHandler.cs
@@ -5,6 +5,7 @@
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
+using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;
@@ -17,20 +18,16 @@ public bool ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext co
{
if (_renameService.ActiveSession != null)
{
- // Prevent Editor's typing responsiveness auto canceling the rename operation.
- // InlineRenameSession will call IUIThreadOperationExecutor to sets up our own IUIThreadOperationContext
- context.OperationContext.TakeOwnership();
-
- Commit(_renameService.ActiveSession, args.TextView);
+ CommitAndSetFocus(_renameService.ActiveSession, args.TextView, context.OperationContext);
return true;
}
return false;
}
- protected virtual void Commit(InlineRenameSession activeSession, ITextView textView)
+ protected virtual void CommitAndSetFocus(InlineRenameSession activeSession, ITextView textView, IUIThreadOperationContext operationContext)
{
- activeSession.Commit();
+ Commit(operationContext);
SetFocusToTextView(textView);
}
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_SaveHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_SaveHandler.cs
index 4a9bb0c50b1e1..132c8d0f42a5d 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_SaveHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_SaveHandler.cs
@@ -16,7 +16,7 @@ public bool ExecuteCommand(SaveCommandArgs args, CommandExecutionContext context
{
if (_renameService.ActiveSession != null)
{
- _renameService.ActiveSession.Commit();
+ Commit(context.OperationContext);
SetFocusToTextView(args.TextView);
}
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TabHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TabHandler.cs
index b7cff5b4ed1c7..9846afad5f315 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TabHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TabHandler.cs
@@ -26,7 +26,7 @@ public void ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandEx
return;
}
- HandlePossibleTypingCommand(args, nextHandler, (activeSession, span) =>
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
var spans = new NormalizedSnapshotSpanCollection(
activeSession.GetBufferManager(args.SubjectBuffer)
diff --git a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TypeCharHandler.cs b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TypeCharHandler.cs
index 6b1da07bed52b..d154e4f9fc438 100644
--- a/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TypeCharHandler.cs
+++ b/src/EditorFeatures/Core/InlineRename/CommandHandlers/AbstractRenameCommandHandler_TypeCharHandler.cs
@@ -19,7 +19,7 @@ public CommandState GetCommandState(TypeCharCommandArgs args, Func
public void ExecuteCommand(TypeCharCommandArgs args, Action nextHandler, CommandExecutionContext context)
{
- HandlePossibleTypingCommand(args, nextHandler, (activeSession, span) =>
+ HandlePossibleTypingCommand(args, nextHandler, context.OperationContext, (activeSession, _, span) =>
{
var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
diff --git a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs
index 458d62ac88cf2..bc22473d91a88 100644
--- a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs
+++ b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs
@@ -723,36 +723,42 @@ void DismissUIAndRollbackEdits()
}
}
- public void Commit(bool previewChanges = false)
- => CommitSynchronously(previewChanges);
+ ///
+ /// Caller should pass in the IUIThreadOperationContext if it is called from editor so rename commit operation could set up the its own context correctly.
+ ///
+ public void Commit(bool previewChanges = false, IUIThreadOperationContext editorOperationContext = null)
+ => CommitSynchronously(previewChanges, editorOperationContext);
/// if the rename operation was committed, otherwise
- private bool CommitSynchronously(bool previewChanges)
+ private bool CommitSynchronously(bool previewChanges, IUIThreadOperationContext operationContext = null)
{
// We're going to synchronously block the UI thread here. So we can't use the background work indicator (as
// it needs the UI thread to update itself. This will force us to go through the Threaded-Wait-Dialog path
// which at least will allow the user to cancel the rename if they want.
//
// In the future we should remove this entrypoint and have all callers use CommitAsync instead.
- return _threadingContext.JoinableTaskFactory.Run(() => CommitWorkerAsync(previewChanges, canUseBackgroundWorkIndicator: false));
+ return _threadingContext.JoinableTaskFactory.Run(() => CommitWorkerAsync(previewChanges, canUseBackgroundWorkIndicator: false, operationContext));
}
- public async Task CommitAsync(bool previewChanges)
+ ///
+ /// Caller should pass in the IUIThreadOperationContext if it is called from editor so rename commit operation could set up the its own context correctly.
+ ///
+ public async Task CommitAsync(bool previewChanges, IUIThreadOperationContext editorOperationContext = null)
{
if (this.RenameService.GlobalOptions.GetOption(InlineRenameSessionOptionsStorage.RenameAsynchronously))
{
- await CommitWorkerAsync(previewChanges, canUseBackgroundWorkIndicator: true).ConfigureAwait(false);
+ await CommitWorkerAsync(previewChanges, canUseBackgroundWorkIndicator: true, editorOperationContext).ConfigureAwait(false);
}
else
{
- CommitSynchronously(previewChanges);
+ CommitSynchronously(previewChanges, editorOperationContext);
}
}
/// if the rename operation was committed, otherwise
- private async Task CommitWorkerAsync(bool previewChanges, bool canUseBackgroundWorkIndicator)
+ private async Task CommitWorkerAsync(bool previewChanges, bool canUseBackgroundWorkIndicator, IUIThreadOperationContext editorUIOperationContext)
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();
VerifyNotDismissed();
@@ -775,6 +781,13 @@ private async Task CommitWorkerAsync(bool previewChanges, bool canUseBackg
previewChanges = previewChanges || PreviewChanges;
+ if (editorUIOperationContext is not null)
+ {
+ // Prevent Editor's typing responsiveness auto canceling the rename operation.
+ // InlineRenameSession will call IUIThreadOperationExecutor to sets up our own IUIThreadOperationContext
+ editorUIOperationContext.TakeOwnership();
+ }
+
try
{
if (canUseBackgroundWorkIndicator)
diff --git a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb
index a97faa06717eb..a59c2e7eeffb4 100644
--- a/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb
+++ b/src/EditorFeatures/VisualBasicTest/LineCommit/CommitTestData.vb
@@ -16,6 +16,7 @@ Imports Microsoft.CodeAnalysis.Text.Shared.Extensions
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Editor
Imports Microsoft.VisualStudio.Text.Operations
+Imports Microsoft.VisualStudio.Utilities
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit
Friend Class CommitTestData
@@ -111,7 +112,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit
Throw New NotImplementedException()
End Sub
- Public Function CommitAsync(previewChanges As Boolean) As Task Implements IInlineRenameSession.CommitAsync
+ Public Function CommitAsync(previewChanges As Boolean, Optional editorOperationContext As IUIThreadOperationContext = Nothing) As Task Implements IInlineRenameSession.CommitAsync
Throw New NotImplementedException()
End Function
End Class