Issue when changing focused textbox inside of a dialog on Linux
See original GitHub issueHi. I am running into a strange issue where if the user switches to the next textbox inside of a ScrollView, the cursor is placed at X 0 instead of at the beginning of the textbox. Also it doesn’t happen with the two first textboxes in the View. This issue only occurs with the Linux build (I’m testing on Debian, both WSL and real), while the Windows build works absolutely fine. This was a a bit hard to explain, so I have attached a gif of the issue. gif
Here is the code used for this dialogbox:
Dialog dialog = new Dialog("Edit Rule")
{
X = Pos.Center(),
Y = Pos.Center(),
Height = Dim.Fill(3),
Width = Dim.Fill(5)
};
ScrollView scrollview = new ScrollView()
{
X = 2,
Y = 2,
Width = Dim.Fill(1),
Height = Dim.Fill(1),
ShowVerticalScrollIndicator = true,
ContentSize = new Size(60, 30),
AutoHideScrollBars = false
};
dialog.ColorScheme = new ColorScheme()
{
Normal = new Terminal.Gui.Attribute(Color.White, Color.Black),
Focus = new Terminal.Gui.Attribute(Color.Black, Color.White),
HotFocus = new Terminal.Gui.Attribute(Color.White, Color.Black),
HotNormal = new Terminal.Gui.Attribute(Color.White, Color.Black)
};
int selectedRuleIndex = rulesListview.SelectedItem;
iptablesInterface.Rule selectedRule = ipt.getiptablesRules()[selectedRuleIndex];
dialog.Add(new Label($"Rule: {(selectedRule.fulllineFromValues).ToString()}")
{
X = 0,
Y = 0
});
var exitDialog = new Button("Exit")
{
X = Pos.Center() - 13,
Y = Pos.Bottom(dialog) - 4
};
exitDialog.Clicked += () =>
{
//dialog.Running = false;
Application.RequestStop();
};
var saveAndExitDialog = new Button("Save and Exit")
{
X = Pos.Center() + 3,
Y = Pos.Bottom(dialog) - 4
};
if (selectedRule.ruleType == iptablesInterface.Rule.RuleType.PORTRULE || selectedRule.fulllineFromValues == "")
{
var chain = new Label("Chain:")
{
X = 0,
Y = 1
};
var chainTextbox = new TextField(selectedRule.chain)
{
X = 18,
Y = 1,
Width = Dim.Fill(1),
};
var sourceLabel = new Label("Source:")
{
X = 0,
Y = Pos.Bottom(chain) + 1
};
var sourceTextbox = new TextField(selectedRule.source)
{
X = 18,
Y = Pos.Bottom(chain) + 1,
Width = Dim.Fill(1),
};
//sourceTextbox.CursorPosition = 0; //workaround textbox scroll bug.
var destinationLabel = new Label("Destination:")
{
X = 0,
Y = Pos.Bottom(sourceLabel) + 1
};
var destinationTextbox = new TextField(selectedRule.destination)
{
X = 18,
Y = Pos.Bottom(sourceLabel) + 1,
Width = Dim.Fill(1)
};
//destinationTextbox.CursorPosition = 0;
var destinationPortLabel = new Label("Destination Port:")
{
X = 0,
Y = Pos.Bottom(destinationTextbox) + 1
};
var destinationPortTextbox = new TextField("")
{
X = 18,
Y = Pos.Bottom(destinationTextbox) + 1,
Width = Dim.Fill(1),
Text = selectedRule.destinationPort
};
var sourcePortLabel = new Label("Source Port:")
{
X = 0,
Y = Pos.Bottom(destinationPortTextbox) + 1
};
var sourcePortTextbox = new TextField(Text = selectedRule.sourcePort)
{
X = 18,
Y = Pos.Bottom(destinationPortTextbox) + 1,
Width = Dim.Fill(1)
};
var inInterface = new Label("In Interface:")
{
X = 0,
Y = Pos.Bottom(sourcePortTextbox) + 1
};
var inInterfaceTextbox = new TextField(selectedRule.inInterface)
{
X = 18,
Y = Pos.Bottom(sourcePortTextbox) + 1,
Width = Dim.Fill(1)
};
var outInterface = new Label("Out Interface:")
{
X = 0,
Y = Pos.Bottom(inInterfaceTextbox) + 1
};
var outInterfaceTextbox = new TextField(selectedRule.outInterface)
{
X = 18,
Y = Pos.Bottom(inInterfaceTextbox) + 1,
Width = Dim.Fill(1)
};
var protocolLabel = new Label("Protocol:")
{
X = 0,
Y = Pos.Bottom(outInterfaceTextbox) + 1
};
var protocolSelect = new ComboBox(selectedRule.protocol)
{
X = 18,
Y = Pos.Bottom(outInterfaceTextbox) + 1,
Width = Dim.Fill(1),
Height = 5
};
protocolSelect.SetSource(new string[] { "tcp", "udp", "icmp", "all" });
var targetLabel = new Label("Target:")
{
X = 0,
Y = Pos.Bottom(protocolSelect) + 1
};
var targetSelect = new ComboBox(selectedRule.target)
{
X = 18,
Y = Pos.Bottom(protocolSelect) + 1,
Width = Dim.Fill(1),
Height = 5
};
targetSelect.SetSource(new string[] { "ACCEPT", "DROP", "REJECT", "LOG", "MASQUERADE", "RETURN" });
saveAndExitDialog.Clicked += () =>
{
ipt.getiptablesRules()[rulesListview.SelectedItem] = new iptablesInterface.Rule(chainTextbox.Text.ToString(), protocolSelect.Text.ToString(), sourceTextbox.Text.ToString(), destinationTextbox.Text.ToString(), targetSelect.Text.ToString(), outInterfaceTextbox.Text.ToString(), inInterfaceTextbox.Text.ToString(), destinationPortTextbox.Text.ToString(), sourcePortTextbox.Text.ToString());
//dialog.Running = false;
rulesListview.SetSource(ipt.getiptablesRules().Select(x => x.fulllineFromValues).ToList());
rulesListview.SelectedItem = selectedRuleIndex;
Application.RequestStop();
};
scrollview.Add(chain);
scrollview.Add(chainTextbox);
scrollview.Add(sourceLabel);
scrollview.Add(sourceTextbox);
scrollview.Add(destinationLabel);
scrollview.Add(destinationTextbox);
scrollview.Add(destinationPortLabel);
scrollview.Add(destinationPortTextbox);
scrollview.Add(sourcePortLabel);
scrollview.Add(sourcePortTextbox);
scrollview.Add(inInterface);
scrollview.Add(inInterfaceTextbox);
scrollview.Add(outInterface);
scrollview.Add(outInterfaceTextbox);
scrollview.Add(protocolLabel);
scrollview.Add(protocolSelect);
scrollview.Add(targetLabel);
scrollview.Add(targetSelect);
dialog.Add(scrollview);
dialog.Add(exitDialog);
dialog.Add(saveAndExitDialog);
Application.Run(dialog);
}
else
{
//dialog.Running = false;
editmanualRuleDialog();
}
Thanks for reading. Any help would be greatly appreciated 😃
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
jQuery UI Dialog and Textarea Focus Issue
When opening the dialog, try focusing the textbox during on the "open" function. $('#modal').dialog({ open: function ...
Read more >How to resolve the textbox focus issue of find and replace ...
Solution: While placing RichTextEditor inside jQuery mobile Popup and jQuery mobile Dialog, find and replace textbox cannot be focused because the element is ......
Read more >Can not type in text box (like password) after switching ...
A small dialog should appear. Click Start In Safe Mode (not Refresh). Is the problem still there?
Read more >the input-box lose focus after call window.alert('...') #19977
When called the alert('xxx') and close the message box, the input-box on the page has lost focus and can't enter any text into...
Read more >dialog(1): dialog boxes from shell scripts - Linux man page
Typing any printable characters switches focus to the text-entry window, entering that character as well as scrolling the directory window to the closest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured out the issue. This issue is basically a duplicate of https://github.com/migueldeicaza/gui.cs/issues/1501.
Once I removed the process-start at the beginning of my program the issue was solved. Hope you can get a fixed version up on NuGet soon.
Thanks for all the help
But all of my views are inside of the console window? The cursor also sets itself as 0 only on the X coordinate. The Y coordinate is set correctly.
Also see this error which happens every time the user has tried focusing such a bugged textbox and then resizes the console while it’s focused:
I also tested this now with only this code (fairly basic), which rules out any issue there:
Program.cs
Test.cs:
What else can I do to debug this? I seem to have ruled out everything on my end.