question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when changing focused textbox inside of a dialog on Linux

See original GitHub issue

Hi. 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
henrikxcommented, Dec 14, 2021

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

0reactions
henrikxcommented, Dec 14, 2021

I’m not having the same issue as you have on Debian. I tested in WSL Ubuntu and the cursor only goes to (0,0) if the focused view go outside the console window.

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:

image

I also tested this now with only this code (fairly basic), which rules out any issue there:

Program.cs

static void Main(string[] args) {
  try {
    Application.Init();
    var top = Application.Top;

    var win = new Window("Test") {
      X = 0,
      Y = 1, // Leave one row for the toplevel menu

        // By using Dim.Fill(), it will automatically resize without manual intervention
        Width = Dim.Fill(),
        Height = Dim.Fill()
    };
    var test = new Test("test");
    win.Add(test);
    Application.Run(win);
  } finally {
    Application.Shutdown();
  }
}

Test.cs:

public class Test : Window
{
    public Test(string title) : base(title)
    {
        var quit = new Button("Quit")
        {
            X = Pos.Center(),
            Y = Pos.Bottom(this) - 4
        };
        var textBox = new TextField("")
        {
            X = 2,
            Y = 2,
            Width = Dim.Fill(1),
            Text = "Hello World"
        };
        var textBox2 = new TextField("")
        {
            X = 2,
            Y = Pos.Bottom(textBox),
            Width = Dim.Fill(1),
            Text = "fasfas"
        };
        var textBox3 = new TextField("")
        {
            X = 2,
            Y = Pos.Bottom(textBox2),
            Width = Dim.Fill(1),
            Text = "fasfas"
        };
            
        Add(textBox);
        Add(textBox2);
        Add(textBox3);
        quit.Clicked += () => { Application.RequestStop(); };
        Add(quit);
    }
}

What else can I do to debug this? I seem to have ruled out everything on my end.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found