Patchwork [v5] crecord: add an event that scrolls the selected line to the top of the screen

login
register
mail settings
Submitter Nathan Goldbaum
Date Sept. 20, 2016, 3:04 p.m.
Message ID <da914962b6c3f55c3f14.1474383855@rous2.ncsa.illinois.edu>
Download mbox | patch
Permalink /patch/16683/
State Accepted
Headers show

Comments

Nathan Goldbaum - Sept. 20, 2016, 3:04 p.m.
# HG changeset patch
# User Nathan Goldbaum <ngoldbau@illinois.edu>
# Date 1474383830 18000
#      Tue Sep 20 10:03:50 2016 -0500
# Node ID da914962b6c3f55c3f14cd7b82a4c0204c2d6a0d
# Parent  769aee32fae0f7eb8768ea2e90780af4e9a92761
crecord: add an event that scrolls the selected line to the top of the screen

Using ctrl-l for this purpose seems to be a fairly widely used practice,
presumably following emacs. This doesn't scroll the selected line all
the way to the top of the window, instead it leaves a 3 line buffer for
context. Use curses.unctrl() to resolve keypressed to '^L' to avoid
hard-coding hexadecimal key codes.
Pierre-Yves David - Sept. 20, 2016, 3:26 p.m.
On 09/20/2016 05:04 PM, Nathan Goldbaum wrote:
> # HG changeset patch
> # User Nathan Goldbaum <ngoldbau@illinois.edu>
> # Date 1474383830 18000
> #      Tue Sep 20 10:03:50 2016 -0500
> # Node ID da914962b6c3f55c3f14cd7b82a4c0204c2d6a0d
> # Parent  769aee32fae0f7eb8768ea2e90780af4e9a92761
> crecord: add an event that scrolls the selected line to the top of the screen
>
> Using ctrl-l for this purpose seems to be a fairly widely used practice,
> presumably following emacs. This doesn't scroll the selected line all
> the way to the top of the window, instead it leaves a 3 line buffer for
> context. Use curses.unctrl() to resolve keypressed to '^L' to avoid
> hard-coding hexadecimal key codes.


Pushed, thanks.

I've dropped the first hunk with the new empty line.

> diff -r 769aee32fae0 -r da914962b6c3 mercurial/crecord.py
> --- a/mercurial/crecord.py	Mon Sep 19 09:14:35 2016 -0700
> +++ b/mercurial/crecord.py	Tue Sep 20 10:03:50 2016 -0500
> @@ -715,6 +715,7 @@ class curseschunkselector(object):
>
>          self.currentselecteditem = currentitem
>
> +
>      def updatescroll(self):
>          "scroll the screen to fully show the currently-selected"
>          selstart = self.selecteditemstartline
> @@ -1338,6 +1339,7 @@ the following are valid keystrokes:
>   shift-left-arrow   [H] : go to parent header / fold selected header
>                        f : fold / unfold item, hiding/revealing its children
>                        F : fold / unfold parent item and all of its ancestors
> +                 ctrl-l : scroll the selected line to the top of the screen
>                        m : edit / resume editing the commit message
>                        e : edit the currently selected hunk
>                        a : toggle amend mode, only with commit -i
> @@ -1582,6 +1584,9 @@ are you sure you want to review/edit and
>              self.helpwindow()
>              self.stdscr.clear()
>              self.stdscr.refresh()
> +        elif curses.unctrl(keypressed) in ["^L"]:
> +            # scroll the current line to the top of the screen
> +            self.scrolllines(self.selecteditemstartline)
>
>      def main(self, stdscr):
>          """
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff -r 769aee32fae0 -r da914962b6c3 mercurial/crecord.py
--- a/mercurial/crecord.py	Mon Sep 19 09:14:35 2016 -0700
+++ b/mercurial/crecord.py	Tue Sep 20 10:03:50 2016 -0500
@@ -715,6 +715,7 @@  class curseschunkselector(object):
 
         self.currentselecteditem = currentitem
 
+
     def updatescroll(self):
         "scroll the screen to fully show the currently-selected"
         selstart = self.selecteditemstartline
@@ -1338,6 +1339,7 @@  the following are valid keystrokes:
  shift-left-arrow   [H] : go to parent header / fold selected header
                       f : fold / unfold item, hiding/revealing its children
                       F : fold / unfold parent item and all of its ancestors
+                 ctrl-l : scroll the selected line to the top of the screen
                       m : edit / resume editing the commit message
                       e : edit the currently selected hunk
                       a : toggle amend mode, only with commit -i
@@ -1582,6 +1584,9 @@  are you sure you want to review/edit and
             self.helpwindow()
             self.stdscr.clear()
             self.stdscr.refresh()
+        elif curses.unctrl(keypressed) in ["^L"]:
+            # scroll the current line to the top of the screen
+            self.scrolllines(self.selecteditemstartline)
 
     def main(self, stdscr):
         """