Tab view stealing focus from ComboBox #4190
Replies: 3 comments
-
Hey, thanks for using Terminal.Gui. Unfortunately ComboBox is quite a buggy view. It was always a frankenstein mix of TextField and ListView. There is work underway in v2 to switch to a common 'popover' implementation for the combo box dropdown (and menus etc). Until then this is unlikely to be fixed. I have in fact removed ComboBox from TerminalGuiDesigner precisely because it is so unreliable - see gui-cs/TerminalGuiDesigner#300. I would suggest either radio group or list view depending on your needs or TextField with popout autocomplete. Let me know if I can help more - this probably should go away when the new popover implementation is done for ComboBox. |
Beta Was this translation helpful? Give feedback.
-
I've had very good results using a public static void SetExpressionSuggestions(this TextField field, Branch? branch)
{
List<string> functions =
[
"Abs (",
"Acos (",
"Asin (",
"Atan (",
//... etc
];
field.Autocomplete.MaxWidth = 50;
((SingleWordSuggestionGenerator)field.Autocomplete.SuggestionGenerator).AllSuggestions = functions;
field.KeyDown += (sender, e) => ShowSuggestionPopover(sender, e, functions);
}
private static void ShowSuggestionPopover(object? sender, Key e, List<string> suggestions)
{
if (sender is not TextField textField) return;
if (e != Key.J.WithCtrl) return;
if (suggestions.Count == 0) return;
List<MenuItemv2> items = [];
foreach (string suggestion in suggestions)
{
MenuItemv2 item = new()
{
Title = suggestion,
Action = () =>
{
// TODO: is this a bug in Terminal.Gui?
// if useOldCursorPos is true (default), InsertText will
// exhibit strange behavior such as inserting text in
// reverse order if the cursor is at the beginning of the
// text field.
textField.InsertText(suggestion, false);
},
};
items.Add(item);
}
PopoverMenu menu = new(items);
menu.MakeVisible(new Point
{
Y = textField.ViewportToScreen().Location.Y + 1,
X = textField.ViewportToScreen().Location.X + textField.CursorPosition
});
Application.Popover?.Register(menu);
e.Handled = true;
} I use |
Beta Was this translation helpful? Give feedback.
-
Thank you for everyone's answers! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an app I'm building and I'm using the TabView as the main driver for the application. I did have some oddities with allowing the TextFields within the View of the tab to be focusable, which was solved by setting the CanFocus attribute on the View that is being used inside my Tab. But whenever I click the triangle to have the dropdown show when using a ComboBox it instantly loses focus and the focus goes to the Tab itself. I've tried various settings and haven't really seen anything in the Docs that describes why I see this behavior. Can someone point me to some docs that would be helpful?
I have pulled the ComboBox out of the Tab just to ensure it's working there and it works fine. It seems to be something within the Tab pulling focus or some handler on the ComboBox
I am using the latest version of the develop branch for V2
Beta Was this translation helpful? Give feedback.
All reactions