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

Bug when using ScrollTo() method #1876

Closed
luizfernandonb opened this issue Jul 21, 2022 · 13 comments
Closed

Bug when using ScrollTo() method #1876

luizfernandonb opened this issue Jul 21, 2022 · 13 comments
Labels

Comments

@luizfernandonb
Copy link

luizfernandonb commented Jul 21, 2022

Describe the bug
A bit similar to the #1866 I had previously opened.

In this case, when the ScrollTo method runs for a few lines down and you try to type something, an error is thrown.

To Reproduce
Steps to reproduce the behavior:
In the screenshots

Expected behavior
Perhaps in this case, it would be correct for the cursor to go to the line that was defined in the parameter of the ScrollTo() method

Screenshots

  1. Before:
    image

  2. After pressing the Ctrl + CursorDown key, which I put as binding in the code next to the console:
    image

  3. I try to type anything and boom:
    image

@BDisp
Copy link
Collaborator

BDisp commented Jul 21, 2022

You have to test with the current main branch because it's the same bug that was fixed by the #1866 already merged.

@luizfernandonb
Copy link
Author

You have to test with the current main branch because it's the same bug that was fixed by the #1866 already merged.

I was waiting for a library update on NuGet to be able to test, will it take a long time to come out?

@BDisp
Copy link
Collaborator

BDisp commented Jul 21, 2022

I was waiting for a library update on NuGet to be able to test, will it take a long time to come out?

I recommend to you to have two projects, one using the NuGet package and another using the gui.cs repo. Only this way you can really test if the fixes is working. Waiting for a update package sometimes it take to long time.

@luizfernandonb
Copy link
Author

I was waiting for a library update on NuGet to be able to test, will it take a long time to come out?

I recommend to you to have two projects, one using the NuGet package and another using the gui.cs repo. Only this way you can really test if the fixes is working. Waiting for a update package sometimes it take lo long time.

Okay, thanks, I'll do that, if it works, I'll close this issue.

@tig tig added the bug label Jul 21, 2022
@luizfernandonb
Copy link
Author

I was waiting for a library update on NuGet to be able to test, will it take a long time to come out?

I recommend to you to have two projects, one using the NuGet package and another using the gui.cs repo. Only this way you can really test if the fixes is working. Waiting for a update package sometimes it take lo long time.

Okay, thanks, I'll do that, if it works, I'll close this issue.

Yes, it solved, but is there any way to move the cursor to the line I scrolled? I can't do that, the cursor is always on the same line, I've tried using the Move method but I haven't had success.

@BDisp
Copy link
Collaborator

BDisp commented Jul 21, 2022

Set the cursor position to the column and row you want.

@luizfernandonb
Copy link
Author

Set the cursor position to the column and row you want.

I already do that, but it doesn't work, I use the Move() method

@luizfernandonb
Copy link
Author

I forgot to mention, even inverting the operations, which in this case would be, putting the Move() method first and the ScrollTo() right below, in theory the cursor would change its place first and then the scroll is done, but that doesn't happen, the effect is the same as calling ScrollTo() method first and then Move().

@luizfernandonb
Copy link
Author

Any update on this bug? In case what I said was not clear, I can record a gif, or anything else

@BDisp
Copy link
Collaborator

BDisp commented Jul 25, 2022

I haven't see it yet.

@BDisp
Copy link
Collaborator

BDisp commented Jul 26, 2022

This unit test proves that the CursorPosition is working by setting his value. The ScrollTo method only moves the text but without change the cursor position. After scrolling you have to click on the position you want and then typing. This is the normal ScrollTo behavior. If you want more or less a near localization of the text the LeftColumn and the TopRow gives the information about the cols and rows were scrolled and using the TextView width and height there is a approximated indicator where you are in the text.
Note that the column is 100 because the cursor need an extra column in the end of the line.
If you want to set to the scrolled position you can set like this: CursorPosition = new Point(LeftColumn, TopRow)

		[Fact]
		[AutoInitShutdown]
		public void MoveDown_By_Setting_CursorPosition ()
		{
			var tv = new TextView {
				Width = 10,
				Height = 5
			};

			// add 100 lines of wide text to view
			for (int i = 0; i < 100; i++)
				tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);

			Assert.Equal (new Point (0, 0), tv.CursorPosition);
			tv.CursorPosition = new Point (5, 50);
			Assert.Equal (new Point (5, 50), tv.CursorPosition);

			tv.CursorPosition = new Point (200, 200);
			Assert.Equal (new Point (100, 99), tv.CursorPosition);
		}

		[Fact]
		[AutoInitShutdown]
		public void ScrollTo_CursorPosition ()
		{
			var tv = new TextView {
				Width = 10,
				Height = 5
			};

			// add 100 lines of wide text to view
			for (int i = 0; i < 100; i++)
				tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);

			Assert.Equal (new Point (0, 0), tv.CursorPosition);
			tv.ScrollTo (50);
			Assert.Equal (new Point (0, 0), tv.CursorPosition);

			tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
			Assert.Equal (new Point (0, 50), tv.CursorPosition);
		}

@BDisp
Copy link
Collaborator

BDisp commented Jul 26, 2022

Set the cursor position to the column and row you want.

I already do that, but it doesn't work, I use the Move() method

This method is normally used by the Redraw and PositionCursor methods when the view is being rendering and not for set some property.

@luizfernandonb
Copy link
Author

This unit test proves that the CursorPosition is working by setting his value. The ScrollTo method only moves the text but without change the cursor position. After scrolling you have to click on the position you want and then typing. This is the normal ScrollTo behavior. If you want more or less a near localization of the text the LeftColumn and the TopRow gives the information about the cols and rows were scrolled and using the TextView width and height there is a approximated indicator where you are in the text. Note that the column is 100 because the cursor need an extra column in the end of the line. If you want to set to the scrolled position you can set like this: CursorPosition = new Point(LeftColumn, TopRow)

		[Fact]
		[AutoInitShutdown]
		public void MoveDown_By_Setting_CursorPosition ()
		{
			var tv = new TextView {
				Width = 10,
				Height = 5
			};

			// add 100 lines of wide text to view
			for (int i = 0; i < 100; i++)
				tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);

			Assert.Equal (new Point (0, 0), tv.CursorPosition);
			tv.CursorPosition = new Point (5, 50);
			Assert.Equal (new Point (5, 50), tv.CursorPosition);

			tv.CursorPosition = new Point (200, 200);
			Assert.Equal (new Point (100, 99), tv.CursorPosition);
		}

		[Fact]
		[AutoInitShutdown]
		public void ScrollTo_CursorPosition ()
		{
			var tv = new TextView {
				Width = 10,
				Height = 5
			};

			// add 100 lines of wide text to view
			for (int i = 0; i < 100; i++)
				tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine);

			Assert.Equal (new Point (0, 0), tv.CursorPosition);
			tv.ScrollTo (50);
			Assert.Equal (new Point (0, 0), tv.CursorPosition);

			tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow);
			Assert.Equal (new Point (0, 50), tv.CursorPosition);
		}

Now I understand, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants