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

Fix scrolling of long query in input field #230

Closed
wants to merge 1 commit into from
Closed

Fix scrolling of long query in input field #230

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 21, 2017

How to reproduce:

echo | pick -q $( seq -s ":" 1 $COLUMNS )

and pressing left arrow key several times: nothing happens ... at some point the input field scrolls, but cursor position is out of sync and entering new characters messes up the query ...

@mptre
Copy link
Owner

mptre commented Aug 22, 2017

Nice catch. Can we do something simpler like the diff below, lightly tested:

diff --git a/pick.c b/pick.c
index 768c075..41ddba0 100644
--- a/pick.c
+++ b/pick.c
@@ -276,8 +276,7 @@ eager_strpbrk(const char *string, const char *separators)
 const struct choice *
 selected_choice(void)
 {
-	size_t	cursor_position, i, j, length;
-	size_t	xscroll = 0;
+	size_t	cursor_position, i, j, length, xscroll;
 	char	buf[6];
 	int	choices_count, word_position;
 	int	selection = 0;
@@ -290,10 +289,10 @@ selected_choice(void)
 	for (;;) {
 		tty_putp(cursor_invisible, 0);
 		tty_putp(carriage_return, 1);	/* move cursor to first column */
-		if (cursor_position >= xscroll + columns)
+		if (cursor_position >= (size_t)columns)
 			xscroll = cursor_position - columns + 1;
-		if (cursor_position < xscroll)
-			xscroll = cursor_position;
+		else
+			xscroll = 0;
 		print_line(&query[xscroll], query_length - xscroll, 0, -1, -1);
 		choices_count = print_choices(yscroll, selection);
 		if ((size_t)choices_count - yscroll < choices.length

@ghost
Copy link
Author

ghost commented Aug 22, 2017

Indeed simpler and works also great ...

mptre added a commit that referenced this pull request Aug 22, 2017
Issue reported by Jenz Guenther in PR #230.
@mptre
Copy link
Owner

mptre commented Aug 22, 2017

Great, merged as 1ef7970.

@mptre mptre closed this Aug 22, 2017
@ghost ghost deleted the xscroll branch August 22, 2017 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant