mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-08-16 18:20:50 +03:00
Custom impl. of scrollTo & scrollToHighlight for #196
https://github.com/makeworld-the-better-one/amfora/issues/197#issuecomment-869200677
This commit is contained in:
parent
4ef4d247d1
commit
6ec7ed1668
@ -94,7 +94,7 @@ func makeNewTab() *tab {
|
||||
tabs[tab].page.Mode = structs.ModeLinkSelect
|
||||
|
||||
tabs[tab].view.Highlight("0")
|
||||
tabs[tab].view.ScrollToHighlight()
|
||||
tabs[tab].scrollToHighlight()
|
||||
// Display link URL in bottomBar
|
||||
bottomBar.SetLabel("[::b]Link: [::-]")
|
||||
bottomBar.SetText(tabs[tab].page.Links[0])
|
||||
@ -115,7 +115,7 @@ func makeNewTab() *tab {
|
||||
return
|
||||
}
|
||||
tabs[tab].view.Highlight(strconv.Itoa(index))
|
||||
tabs[tab].view.ScrollToHighlight()
|
||||
tabs[tab].scrollToHighlight()
|
||||
// Display link URL in bottomBar
|
||||
bottomBar.SetLabel("[::b]Link: [::-]")
|
||||
bottomBar.SetText(tabs[tab].page.Links[index])
|
||||
@ -184,7 +184,7 @@ func makeNewTab() *tab {
|
||||
return nil
|
||||
case config.CmdCopyTargetURL:
|
||||
currentURL := t.page.URL
|
||||
selectedURL := t.HighlightedURL()
|
||||
selectedURL := t.highlightedURL()
|
||||
if selectedURL == "" {
|
||||
return nil
|
||||
}
|
||||
@ -215,6 +215,7 @@ func makeNewTab() *tab {
|
||||
}
|
||||
|
||||
// Scrolling stuff
|
||||
// Copied in scrollTo
|
||||
|
||||
key := event.Key()
|
||||
mod := event.Modifiers()
|
||||
@ -377,6 +378,49 @@ func (t *tab) applyScroll() {
|
||||
t.applyHorizontalScroll()
|
||||
}
|
||||
|
||||
// scrollTo scrolls the current tab to specified position. Like
|
||||
// cview.TextView.ScrollTo but using the custom scrolling logic required by #196.
|
||||
func (t *tab) scrollTo(row, col int) {
|
||||
// Logic copied from scrolling stuff around line 217.
|
||||
|
||||
height, width := t.view.GetBufferSize()
|
||||
_, _, boxW, boxH := t.view.GetInnerRect()
|
||||
|
||||
// Make boxW accurate by subtracting one if a scrollbar is covering the last
|
||||
// column of text
|
||||
if config.ScrollBar == cview.ScrollBarAlways ||
|
||||
(config.ScrollBar == cview.ScrollBarAuto && height > boxH) {
|
||||
boxW--
|
||||
}
|
||||
|
||||
// Keep row and col within limits
|
||||
|
||||
if row < 0 {
|
||||
row = 0
|
||||
} else if row > height {
|
||||
row = height
|
||||
}
|
||||
if col < 0 {
|
||||
col = 0
|
||||
} else if col > width {
|
||||
col = width
|
||||
}
|
||||
|
||||
t.page.Row = row
|
||||
t.page.Column = col
|
||||
t.applyScroll()
|
||||
App.Draw()
|
||||
}
|
||||
|
||||
// scrollToHighlight scrolls the current tab to specified position. Like
|
||||
// cview.TextView.ScrollToHighlight but using the custom scrolling logic
|
||||
// required by #196.
|
||||
func (t *tab) scrollToHighlight() {
|
||||
t.view.ScrollToHighlight()
|
||||
App.Draw()
|
||||
t.scrollTo(t.view.GetScrollOffset())
|
||||
}
|
||||
|
||||
// saveBottomBar saves the current bottomBar values in the tab.
|
||||
func (t *tab) saveBottomBar() {
|
||||
t.barLabel = bottomBar.GetLabel()
|
||||
@ -431,8 +475,8 @@ func (t *tab) applyAll() {
|
||||
}
|
||||
}
|
||||
|
||||
// HighlightedURL returns the currently selected URL
|
||||
func (t *tab) HighlightedURL() string {
|
||||
// highlightedURL returns the currently selected URL
|
||||
func (t *tab) highlightedURL() string {
|
||||
currentSelection := tabs[curTab].view.GetHighlights()
|
||||
|
||||
if len(currentSelection) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user