TextEdit: only hide cursor when unfocused
This commit is contained in:
parent
8142bb2de5
commit
5df772e568
@ -268,6 +268,20 @@ func (t *TextEdit) GetLineCol() (int, int) {
|
|||||||
return t.cury, t.curx
|
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.
|
// 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 `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.
|
// If `col` is out of bounds, `col` will be clamped to the closest column available for the line.
|
||||||
@ -300,9 +314,8 @@ func (t *TextEdit) SetLineCol(line, col int) {
|
|||||||
|
|
||||||
t.cury, t.curx = line, col
|
t.cury, t.curx = line, col
|
||||||
if t.focused && !t.selectMode {
|
if t.focused && !t.selectMode {
|
||||||
(*t.screen).ShowCursor(t.x+columnWidth+col+tabOffset-t.scrollx, t.y+line-t.scrolly)
|
// Update terminal cursor position
|
||||||
} else {
|
t.updateTerminalCursorNoHelper(columnWidth, tabOffset)
|
||||||
(*t.screen).HideCursor()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +557,7 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
func (t *TextEdit) SetFocused(v bool) {
|
func (t *TextEdit) SetFocused(v bool) {
|
||||||
t.focused = v
|
t.focused = v
|
||||||
if v {
|
if v {
|
||||||
t.SetLineCol(t.cury, t.curx)
|
t.updateTerminalCursor()
|
||||||
} else {
|
} else {
|
||||||
(*t.screen).HideCursor()
|
(*t.screen).HideCursor()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user