Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't mess with user caret in smart rename #75294

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;

Expand All @@ -23,6 +22,7 @@ internal sealed partial class SmartRenameUserInputComboBox : ComboBox, IRenameUs
private readonly SmartRenameViewModel _smartRenameViewModel;
private readonly RenameFlyoutViewModel _baseViewModel;
private readonly Lazy<TextBox> _innerTextBox;
private bool _userChangedTextSelection;

internal SmartRenameUserInputComboBox(RenameFlyoutViewModel viewModel)
{
Expand All @@ -36,7 +36,9 @@ internal SmartRenameUserInputComboBox(RenameFlyoutViewModel viewModel)
_innerTextBox = new Lazy<TextBox>(() =>
{
ApplyTemplate();
return (TextBox)GetTemplateChild(InnerTextBox)!;
var textBox = (TextBox)GetTemplateChild(InnerTextBox)!;
textBox.SelectionChanged += (sender, e) => _userChangedTextSelection = true;
return textBox;
});

_smartRenameViewModel.SuggestedNames.CollectionChanged += SuggestedNames_CollectionChanged;
Expand Down Expand Up @@ -125,6 +127,12 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs

private void SuggestedNames_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Focus();
// RenameFlyout handles GotFocus event by calling SelectAllText, which selects all text in the input text box.
// If user changed selection (e.g. by moving the caret or selecting text in the input text box we don't want
// to step on it once rename suggestions became available.
if (!_userChangedTextSelection)
{
Focus();
}
}
}
Loading