Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ov-less.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
# DisableMouse: false # Disable mouse support.
# DisableColumnCycle: false # Disable cycling when moving columns.
# DisableStickyFollow: false # Disable sticky follow mode.
#
# ViewMode: markdown # Default view mode.
#
Expand Down
1 change: 1 addition & 0 deletions ov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# DisableMouse: false # Disable mouse support.
# DisableColumnCycle: false # Disable cycling when moving columns.
# DisableStickyFollow: false # Disable sticky follow mode.
#
# ViewMode: markdown # Default view mode.
#
Expand Down
21 changes: 20 additions & 1 deletion oviewer/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ func (root *Root) toggleRainbow(context.Context) {
// toggleFollowMode toggles follow mode.
func (root *Root) toggleFollowMode(context.Context) {
root.Doc.FollowMode = !root.Doc.FollowMode
root.Doc.pauseFollow = false
}

// toggleFollowAll toggles follow all mode.
func (root *Root) toggleFollowAll(context.Context) {
root.FollowAll = !root.FollowAll
root.Doc.pauseFollow = false
root.mu.Lock()
for _, doc := range root.DocList {
doc.latestNum = doc.BufEndNum()
Expand All @@ -99,6 +101,7 @@ func (root *Root) toggleFollowAll(context.Context) {

// toggleFollowSection toggles follow section mode.
func (root *Root) toggleFollowSection(context.Context) {
root.Doc.pauseFollow = false
root.Doc.FollowSection = !root.Doc.FollowSection
}

Expand Down Expand Up @@ -210,6 +213,7 @@ func (root *Root) watchControl() {
// searchGo will go to the line with the matching term after searching.
// Jump by section if JumpTargetSection is true.
func (root *Root) searchGo(ctx context.Context, lN int, searcher Searcher) {
root.setPauseFollow()
root.resetSelect()
root.Doc.lastSearchLN = lN
start, end := root.searchXPos(lN, searcher)
Expand Down Expand Up @@ -758,13 +762,18 @@ func calculatePosition(str string, length int) (float64, error) {

// TailSync move to tail and sync.
func (root *Root) TailSync(ctx context.Context) {
root.Doc.moveBottom()
if !root.Doc.pauseFollow {
root.Doc.moveBottom()
}
root.ViewSync(ctx)
}

// tailSection moves to the last section
// and adjusts to its original position.
func (root *Root) tailSection(ctx context.Context) {
if root.Doc.pauseFollow {
return
}
moved := root.Doc.topLN - root.Doc.lastSectionPosNum
root.Doc.moveLastSection(ctx)
if moved > 0 && (root.Doc.topLN+moved) < root.Doc.BufEndNum() {
Expand Down Expand Up @@ -960,3 +969,13 @@ func (m *Document) isValidColumn(cursor int) error {
}
return nil
}

// setPauseFollow sets pauseFollow to true if sticky follow is not disabled.
func (root *Root) setPauseFollow() {
if root.Config.DisableStickyFollow {
return
}
if root.FollowAll || root.Doc.FollowMode || root.Doc.FollowSection {
root.Doc.pauseFollow = true
}
}
2 changes: 2 additions & 0 deletions oviewer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type Config struct {
ShrinkChar string
// DisableColumnCycle indicates whether to disable column cycling.
DisableColumnCycle bool
// DisableStickYFollow indicates whether to disable sticky follow mode.
DisableStickyFollow bool
// Debug indicates whether to enable debug output.
Debug bool
// deprecatedStyleConfig is the old style setting.
Expand Down
2 changes: 2 additions & 0 deletions oviewer/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ type Document struct {
reopenable bool
// nonMatch indicates if non-matching lines are searched.
nonMatch bool
// pauseFollow indicates if follow mode is paused.
pauseFollow bool
// General is the General settings.
General General
}
Expand Down
20 changes: 17 additions & 3 deletions oviewer/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const bottomMargin = 2

// Go to the top line.
func (root *Root) moveTop(context.Context) {
root.setPauseFollow()
root.resetSelect()
defer root.releaseEventBuffer()

Expand All @@ -24,10 +25,12 @@ func (root *Root) moveBottom(context.Context) {
defer root.releaseEventBuffer()

root.Doc.moveBottom()
root.Doc.pauseFollow = false
}

// Move up one screen.
func (root *Root) movePgUp(context.Context) {
root.setPauseFollow()
root.resetSelect()
defer root.releaseEventBuffer()

Expand All @@ -39,11 +42,14 @@ func (root *Root) movePgDn(context.Context) {
root.resetSelect()
defer root.releaseEventBuffer()

root.Doc.movePgDn()
if root.Doc.movePgDn() {
root.Doc.pauseFollow = false
}
}

// Moves up half a screen.
func (root *Root) moveHfUp(context.Context) {
root.setPauseFollow()
root.resetSelect()
defer root.releaseEventBuffer()

Expand All @@ -55,11 +61,14 @@ func (root *Root) moveHfDn(context.Context) {
root.resetSelect()
defer root.releaseEventBuffer()

root.Doc.moveHfDn()
if root.Doc.moveHfDn() {
root.Doc.pauseFollow = false
}
}

// Move up one line.
func (root *Root) moveUpOne(context.Context) {
root.setPauseFollow()
root.moveUp(1)
}

Expand All @@ -70,6 +79,7 @@ func (root *Root) moveDownOne(context.Context) {

// Move up by n amount.
func (root *Root) moveUp(n int) {
root.setPauseFollow()
root.resetSelect()
defer root.releaseEventBuffer()

Expand All @@ -81,7 +91,9 @@ func (root *Root) moveDown(n int) {
root.resetSelect()
defer root.releaseEventBuffer()

root.Doc.moveYDown(n)
if root.Doc.moveYDown(n) {
root.Doc.pauseFollow = false
}
}

// nextSection moves down to the next section's delimiter.
Expand All @@ -90,6 +102,7 @@ func (root *Root) nextSection(ctx context.Context) {
defer root.releaseEventBuffer()

if err := root.Doc.moveNextSection(ctx); err != nil {
root.Doc.pauseFollow = false
// Move by page if there is no section.
root.Doc.movePgDn()
// Last section or no section.
Expand All @@ -107,6 +120,7 @@ func (root *Root) nextSection(ctx context.Context) {

// prevSection moves up to the delimiter of the previous section.
func (root *Root) prevSection(ctx context.Context) {
root.setPauseFollow()
root.resetSelect()
defer root.releaseEventBuffer()

Expand Down
38 changes: 20 additions & 18 deletions oviewer/move_updown.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,44 +68,46 @@ func (m *Document) moveLineNth(lN int, nTh int) (int, int) {
}

// movePgUp moves up one screen.
func (m *Document) movePgUp() {
m.moveLimitYUp(m.height)
func (m *Document) movePgUp() bool {
return m.moveLimitYUp(m.height)
}

// movePgDn moves down one screen.
func (m *Document) movePgDn() {
m.moveYDown(m.height)
func (m *Document) movePgDn() bool {
return m.moveYDown(m.height)
}

// moveHfUp moves up half a screen.
func (m *Document) moveHfUp() {
m.moveLimitYUp(m.height / 2)
func (m *Document) moveHfUp() bool {
return m.moveLimitYUp(m.height / 2)
}

// moveHfDn moves down half a screen.
func (m *Document) moveHfDn() {
m.moveYDown(m.height / 2)
func (m *Document) moveHfDn() bool {
return m.moveYDown(m.height / 2)
}

// limitMoveDown limits the movement of the cursor when moving down.
func (m *Document) limitMoveDown(lX int, lN int) {
// Returns true if reached the bottom line.
func (m *Document) limitMoveDown(lX int, lN int) bool {
if lN+m.height < m.BufEndNum()-m.SkipLines {
m.topLX = lX
m.topLN = lN
return
return false
}

tX, tN := m.bottomLineNum(m.BufEndNum(), m.height-lastLineMargin)
if lN < tN || (lN == tN && lX < tX) {
m.topLX = lX
m.topLN = lN
return
return false
}
// move to bottom
if m.topLN < tN || (m.topLN == tN && m.topLX < tX) {
m.topLX = tX
m.topLN = tN
}
return true
}

// numOfWrap returns the number of wrap from lX and lN.
Expand Down Expand Up @@ -170,16 +172,14 @@ func (m *Document) numUp(lX int, lN int, upY int) (int, int) {
}

// moveYDown moves down by the specified number of y.
func (m *Document) moveYDown(moveY int) {
func (m *Document) moveYDown(moveY int) bool {
if !m.WrapMode {
m.limitMoveDown(0, m.topLN+moveY)
return
return m.limitMoveDown(0, m.topLN+moveY)
}

// WrapMode
if m.topLN < 0 {
m.limitMoveDown(m.topLX, m.topLN+1)
return
return m.limitMoveDown(m.topLX, m.topLN+1)
}
lN := m.topLN + m.firstLine()
lX := m.topLX
Expand All @@ -200,16 +200,18 @@ func (m *Document) moveYDown(moveY int) {
}
n++
}
m.limitMoveDown(lX, lN-m.firstLine())
return m.limitMoveDown(lX, lN-m.firstLine())
}

// moveLimitYUp moves up by the specified number of y.
// The movement is limited to the top of the document.
func (m *Document) moveLimitYUp(moveY int) {
func (m *Document) moveLimitYUp(moveY int) bool {
m.moveYUp(moveY)
if m.topLN < m.BufStartNum() {
m.moveTop()
return true
}
return false
}

// moveYUp moves up by the specified number of y.
Expand Down
9 changes: 9 additions & 0 deletions oviewer/status_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (root *Root) normalLeftStatus() (contents, int) {

// statusDisplay returns the status mode of the document.
func (root *Root) statusDisplay() string {
stMode := root.statusMode()
if !root.Doc.pauseFollow {
return stMode
}
return fmt.Sprintf("||%s", stMode)
}

// statusMode returns the status mode of the document.
func (root *Root) statusMode() string {
if root.Doc.WatchMode {
// Watch mode doubles as FollowSection mode.
return "(Watch)"
Expand Down
Loading