GNOME Bugzilla – Bug 706467
gtksourcecompletioncontainer should never show horizontal scrollbar
Last modified: 2013-08-29 19:34:23 UTC
The horizontal scrollbar on gtksourcecompletioncontainer is really a distraction since it shows up so often. I think the window should instead grow until it has reached the edge of the screen and then ellipsize the cellrenderer markup.
If you try to complete C functions for a GNOME software, I can easily imagine the horizontal scrollbar to appear, indeed. So I agree with your idea.
For the implementation, the CompletionContainer doesn't know the screen edge. What is possible is to set a maximum width for the container. When the completion window moves, we update this maximum width.
So here is something to think about. Consider a window with 2 gtktextview's side-by-side. You are completing on the left-side, and reading from the right-side for example code. Should the completion window extend past the width of the parent textview potentially covering valuable text on the second textview? Or should it be contained to the size of the parent textview. Also, what if you are completing near the end of the line. Is it better to stay contained to your textview or to align the text with the textview. I think I lean towards just covering the second textview. Or in otherwords, staying captive to the current screen, not the parent window.
(In reply to comment #3) > I think I lean towards just covering the second textview. Or in otherwords, > staying captive to the current screen, not the parent window. I tend to agree when thinking about it in abstract terms (implementation and actual testing can change my mind though ;)
Created attachment 252977 [details] [review] calculate maximun container size based on position and screen width This is a fairly minimal patch to implement this feature. It looks at the current position of the window and the width of the screen to calculate the maximum amount of size. I think the reason this works okay is because of the idle callback always readjusting the completion window. Not a big fan of that, but probably fine.
the patch looks ok to me, though Sébastien is more familiar with this code so I'd like him to review the patch as well.
When testing the patch with test-completion, I've found a bug regarding the compact completion window (with or without the patch). Run test-completion, place the main window on the right of the screen, and type a lot of spaces. When reaching the end of the line, the completion window doesn't have a lot of space, so instead of being aligned with the GtkTextIter (the last space on the line), it is moved on the left. With test-completion it is not a big problem, since the natural width of the GtkTreeView doesn't change often. To better see the bug, maybe the random provider should have different proposal lengths. So we can enable only the random provider, and the width would always change. Since the window can be moved on the left to have more space, what is the limit? If there is no limit, the maximum width is the screen width, and we move the completion window a bit on the left if needed. But there should be a limit where this situation occurs. I think a good limit is 350, the MAX_WIDTH of the container (without the patch). To summarize: - First, place the completion window on the GtkTextIter, compute the maximum width based on the screen edge. If the GtkTreeView has enough space, we are done. - If the GtkTreeView doesn't have enough space, there are two situations. (1) The maximum width is above 350. In this case we add a scrollbar and we take the maximum width. (2) The maximum width is below 350. In this case, we set the maximum width as 350, we compute the size of the container (it can be below 350), and we move the completion window on the left, such as the right edge of the completion window touches the right edge of the screen.
Now the random provider has different proposal lengths. But it seems that the bug occurs only with the patch (on the master branch it works).
Review of attachment 252977 [details] [review]: ::: gtksourceview/gtksourcecompletioncontainer.c @@ +61,3 @@ + gdk_window_get_origin (window, &xorigin, NULL); + screen = gdk_window_get_screen (window); + return gdk_screen_get_width (screen) - xorigin; Maybe simply return MAX (350, return_value) here.
Created attachment 253461 [details] [review] completioncontainer: determine max width based on screen size. return MAX (max_width, UNREALIZED_MAX_WIDTH)
Review of attachment 253461 [details] [review]: Minor nitpicks. ::: gtksourceview/gtksourcecompletioncontainer.c @@ +48,3 @@ +static gint +get_max_width (GtkSourceCompletionContainer *self) do not use self but container as in the other parts of the code @@ +50,3 @@ +get_max_width (GtkSourceCompletionContainer *self) +{ + GtkWidget *toplevel; You can move some of this variables inside the block
Review of attachment 253461 [details] [review]: Fix up Nacho's comments and push. Thanks!
The problem explained in comment #7 is not completely fixed. The completion window can not touch the right edge of the screen, due to the xoffset for the text alignment.
Created attachment 253545 [details] [review] completioncontainer: calculate maximum size based on window position. * Fixes nits. * Fixes alignment of window near right window border.
Fixed in da6c9d7e3c7583ed5efdd74f55e418875a3a7a19.