dmitri.shuralyov.com/app/changes/...

Add p/n keyboard shortcuts to go to previous/next commit.
dmitshur committed 6 years ago commit 8cb7a5a1f7cc9898d5c2521dcb8fc9d5e4682242
Collapse all
common/common.go
@@ -7,10 +7,13 @@ import (

type State struct {
	BaseURI          string
	ReqPath          string
	RepoSpec         string
	ChangeID         uint64 `json:",omitempty"` // ChangeID is the current change ID, or 0 if not applicable (e.g., current page is /changes).
	CurrentUser      users.User
	DisableReactions bool
	DisableUsers     bool

	ChangeID uint64 `json:",omitempty"` // ChangeID is the current change ID, or 0 if not applicable (e.g., current page is /changes).
	PrevSHA  string `json:",omitempty"` // PrevSHA is the previous commit SHA, or empty if not applicable (e.g., current page is not /{changeID}/files/{commitID}).
	NextSHA  string `json:",omitempty"` // NextSHA is the next commit SHA, or empty if not applicable (e.g., current page is not /{changeID}/files/{commitID}).
}
frontend/scroll.go
@@ -53,10 +53,25 @@ func setupScroll() {
			setFragment("")

			processHashSet()

			ke.PreventDefault()

		// 'p' keyboard shortcut to go to previous commit.
		case ke.KeyCode == 'P' && !ke.Repeat && !ke.CtrlKey && !ke.AltKey && !ke.MetaKey && !ke.ShiftKey:
			if state.PrevSHA == "" {
				return
			}
			dom.GetWindow().Location().Href = state.PrevSHA
			ke.PreventDefault()
		// 'n' keyboard shortcut to go to next commit.
		case ke.KeyCode == 'N' && !ke.Repeat && !ke.CtrlKey && !ke.AltKey && !ke.MetaKey && !ke.ShiftKey:
			if state.NextSHA == "" {
				return
			}
			dom.GetWindow().Location().Href = state.NextSHA
			ke.PreventDefault()
		}
	})
}

// AnchorScroll scrolls window to target that is pointed by fragment of href of given anchor element.
main.go
@@ -452,10 +452,11 @@ func (h *handler) ChangeFilesHandler(w http.ResponseWriter, req *http.Request, c
			commit.PrevSHA = cs[prev].SHA
		}
		if next := i + 1; next < len(cs) {
			commit.NextSHA = cs[next].SHA
		}
		state.PrevSHA, state.NextSHA = commit.PrevSHA, commit.NextSHA
	}
	var opt *change.GetDiffOptions
	if commitID != "" {
		opt = &change.GetDiffOptions{Commit: commitID}
	}