AvaloniaUI / AvaloniaEdit

Avalonia-based text editor (port of AvalonEdit)
MIT License
746 stars 148 forks source link

Cannot close search panel when opened manually #375

Closed vmiwouter closed 1 month ago

vmiwouter commented 11 months ago

When i open the searchpanel via a button the side buttons cannot be clicked. So cannot click previous,next or close and there is no focus on the text area. Similiar as #336.

But if i launch it first via CTRL + F the focus and buttons work normal.

        private readonly TextEditor? _textEditor;
        private readonly SearchPanel? searchPanel;
        public RelatieLogboekView()
        {
            InitializeComponent();
            _textEditor = this.FindControl<TextEditor>("textCode");
            searchPanel = SearchPanel.Install(_textEditor);
            LogboekGrid.SelectionChanged += LogboekGrid_SelectionChanged;
            hightlightBtn.Click += Button_Click;
        }

        private void LogboekGrid_SelectionChanged(object? sender, RoutedEventArgs e)
        {
            if (LogboekGrid.SelectedItem != null)
            {
                var selectedTemp = LogboekGrid.SelectedItem;
                LogboekGrid.ScrollIntoView(selectedTemp, null);
            }
        }

        private void Button_Click(object? sender, RoutedEventArgs e)
        {
            if (searchPanel != null)
            {
                if (searchPanel.IsOpened)
                {
                    searchPanel.Close();
                }
                else
                {
                    searchPanel.SearchPattern = zoekFilter.Text;
                    searchPanel.Open();
                    searchPanel.Reactivate();
                }
            }
        }

Using Avalonia 11.0.5 with FluentAvalonia with the normal fluent theme for AvaloniaEdit

<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />

vmiwouter commented 1 month ago

Solution:

_textEditor.Focus();
_textEditor.SearchPanel.Open();
Dispatcher.UIThread.Post(_textEditor.SearchPanel.Reactivate, DispatcherPriority.Input);