Skip to content

Commit

Permalink
TextEdit: only hide cursor when unfocused
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewilson2002 committed Apr 8, 2021
1 parent 8142bb2 commit 5df772e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ui/textedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ func (t *TextEdit) GetLineCol() (int, int) {
return t.cury, t.curx
}

// The same as updateTerminalCursor but the caller can provide the tabOffset to
// save the original function a calculation.
func (t *TextEdit) updateTerminalCursorNoHelper(columnWidth, tabOffset int) {
(*t.screen).ShowCursor(t.x+columnWidth+t.curx+tabOffset-t.scrollx, t.y+t.cury-t.scrolly)
}

// updateTerminalCursor sets the position of the cursor with the cursor position
// properties of the TextEdit. Always sends a signal to *show* the cursor.
func (t *TextEdit) updateTerminalCursor() {
columnWidth := t.getColumnWidth()
tabOffset := t.getTabCountInLineAtCol(t.cury, t.curx) * (t.TabSize - 1)
t.updateTerminalCursorNoHelper(columnWidth, tabOffset)
}

// SetLineCol sets the cursor line and column position. Zero is origin for both.
// If `line` is out of bounds, `line` will be clamped to the closest available line.
// If `col` is out of bounds, `col` will be clamped to the closest column available for the line.
Expand Down Expand Up @@ -300,9 +314,8 @@ func (t *TextEdit) SetLineCol(line, col int) {

t.cury, t.curx = line, col
if t.focused && !t.selectMode {
(*t.screen).ShowCursor(t.x+columnWidth+col+tabOffset-t.scrollx, t.y+line-t.scrolly)
} else {
(*t.screen).HideCursor()
// Update terminal cursor position
t.updateTerminalCursorNoHelper(columnWidth, tabOffset)
}
}

Expand Down Expand Up @@ -544,7 +557,7 @@ func (t *TextEdit) Draw(s tcell.Screen) {
func (t *TextEdit) SetFocused(v bool) {
t.focused = v
if v {
t.SetLineCol(t.cury, t.curx)
t.updateTerminalCursor()
} else {
(*t.screen).HideCursor()
}
Expand Down

0 comments on commit 5df772e

Please sign in to comment.