From cfc528d31169ca9d199e0ff1ee33846e8dc54cc6 Mon Sep 17 00:00:00 2001 From: makeworld Date: Sun, 19 Jul 2020 11:27:39 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Number=20keys=20for=20links=20-=20f?= =?UTF-8?q?ixes=20#47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + display/display.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e3f121..169d1d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Tab now also enters link selecting mode, like Enter (#48) +- Number keys can be pressed to navigate to links 1 through 10 (#47) ### Fixed - You can't change link selection while the page is loading diff --git a/display/display.go b/display/display.go index db5c1d5..3af09c4 100644 --- a/display/display.go +++ b/display/display.go @@ -317,6 +317,19 @@ func Init() { tabs[curTab].pageDown() return nil } + + // Number key: 1-9, 0 + i, err := strconv.Atoi(string(event.Rune())) + if err == nil { + if i == 0 { + i = 10 // 0 key is for link 10 + } + if i <= len(tabs[curTab].page.Links) && i > 0 { + // It's a valid link number + followLink(tabs[curTab], tabs[curTab].page.Url, tabs[curTab].page.Links[i-1]) + return nil + } + } } } // All the keys and operations that can work while a tab IS loading