mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
chore(textarea): rename Model.SetCursor to Model.SetCursorColumn
Set.CursorColumn sets the cursor column position. This change was made for clarity.
This commit is contained in:
+24
-24
@@ -546,7 +546,7 @@ func (m *Model) insertRunesFromUserInput(runes []rune) {
|
||||
// Finally add the tail at the end of the last line inserted.
|
||||
m.value[m.row] = append(m.value[m.row], tail...)
|
||||
|
||||
m.SetCursor(m.col)
|
||||
m.SetCursorColumn(m.col)
|
||||
}
|
||||
|
||||
// Value returns the value of the text input.
|
||||
@@ -654,9 +654,9 @@ func (m *Model) CursorUp() {
|
||||
}
|
||||
}
|
||||
|
||||
// SetCursor moves the cursor to the given position. If the position is
|
||||
// SetCursorColumn moves the cursor to the given position. If the position is
|
||||
// out of bounds the cursor will be moved to the start or end accordingly.
|
||||
func (m *Model) SetCursor(col int) {
|
||||
func (m *Model) SetCursorColumn(col int) {
|
||||
m.col = clamp(col, 0, len(m.value[m.row]))
|
||||
// Any time that we move the cursor horizontally we need to reset the last
|
||||
// offset so that the horizontal position when navigating is adjusted.
|
||||
@@ -665,12 +665,12 @@ func (m *Model) SetCursor(col int) {
|
||||
|
||||
// CursorStart moves the cursor to the start of the input field.
|
||||
func (m *Model) CursorStart() {
|
||||
m.SetCursor(0)
|
||||
m.SetCursorColumn(0)
|
||||
}
|
||||
|
||||
// CursorEnd moves the cursor to the end of the input field.
|
||||
func (m *Model) CursorEnd() {
|
||||
m.SetCursor(len(m.value[m.row]))
|
||||
m.SetCursorColumn(len(m.value[m.row]))
|
||||
}
|
||||
|
||||
// Focused returns the focus state on the model.
|
||||
@@ -700,7 +700,7 @@ func (m *Model) Reset() {
|
||||
m.col = 0
|
||||
m.row = 0
|
||||
m.viewport.GotoTop()
|
||||
m.SetCursor(0)
|
||||
m.SetCursorColumn(0)
|
||||
}
|
||||
|
||||
// san initializes or retrieves the rune sanitizer.
|
||||
@@ -717,7 +717,7 @@ func (m *Model) san() runeutil.Sanitizer {
|
||||
// not the cursor blink should be reset.
|
||||
func (m *Model) deleteBeforeCursor() {
|
||||
m.value[m.row] = m.value[m.row][m.col:]
|
||||
m.SetCursor(0)
|
||||
m.SetCursorColumn(0)
|
||||
}
|
||||
|
||||
// deleteAfterCursor deletes all text after the cursor. Returns whether or not
|
||||
@@ -725,7 +725,7 @@ func (m *Model) deleteBeforeCursor() {
|
||||
// the cursor so as not to reveal word breaks in the masked input.
|
||||
func (m *Model) deleteAfterCursor() {
|
||||
m.value[m.row] = m.value[m.row][:m.col]
|
||||
m.SetCursor(len(m.value[m.row]))
|
||||
m.SetCursorColumn(len(m.value[m.row]))
|
||||
}
|
||||
|
||||
// transposeLeft exchanges the runes at the cursor and immediately
|
||||
@@ -737,11 +737,11 @@ func (m *Model) transposeLeft() {
|
||||
return
|
||||
}
|
||||
if m.col >= len(m.value[m.row]) {
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
}
|
||||
m.value[m.row][m.col-1], m.value[m.row][m.col] = m.value[m.row][m.col], m.value[m.row][m.col-1]
|
||||
if m.col < len(m.value[m.row]) {
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,22 +757,22 @@ func (m *Model) deleteWordLeft() {
|
||||
// call into the corresponding if clause does not apply here.
|
||||
oldCol := m.col //nolint:ifshort
|
||||
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
for unicode.IsSpace(m.value[m.row][m.col]) {
|
||||
if m.col <= 0 {
|
||||
break
|
||||
}
|
||||
// ignore series of whitespace before cursor
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
}
|
||||
|
||||
for m.col > 0 {
|
||||
if !unicode.IsSpace(m.value[m.row][m.col]) {
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
} else {
|
||||
if m.col > 0 {
|
||||
// keep the previous space
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -795,12 +795,12 @@ func (m *Model) deleteWordRight() {
|
||||
|
||||
for m.col < len(m.value[m.row]) && unicode.IsSpace(m.value[m.row][m.col]) {
|
||||
// ignore series of whitespace after cursor
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
}
|
||||
|
||||
for m.col < len(m.value[m.row]) {
|
||||
if !unicode.IsSpace(m.value[m.row][m.col]) {
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
@@ -812,13 +812,13 @@ func (m *Model) deleteWordRight() {
|
||||
m.value[m.row] = append(m.value[m.row][:oldCol], m.value[m.row][m.col:]...)
|
||||
}
|
||||
|
||||
m.SetCursor(oldCol)
|
||||
m.SetCursorColumn(oldCol)
|
||||
}
|
||||
|
||||
// characterRight moves the cursor one character to the right.
|
||||
func (m *Model) characterRight() {
|
||||
if m.col < len(m.value[m.row]) {
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
} else {
|
||||
if m.row < len(m.value)-1 {
|
||||
m.row++
|
||||
@@ -839,7 +839,7 @@ func (m *Model) characterLeft(insideLine bool) {
|
||||
}
|
||||
}
|
||||
if m.col > 0 {
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,7 +858,7 @@ func (m *Model) wordLeft() {
|
||||
if unicode.IsSpace(m.value[m.row][m.col-1]) {
|
||||
break
|
||||
}
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,7 +885,7 @@ func (m *Model) doWordRight(fn func(charIdx int, pos int)) {
|
||||
break
|
||||
}
|
||||
fn(charIdx, m.col)
|
||||
m.SetCursor(m.col + 1)
|
||||
m.SetCursorColumn(m.col + 1)
|
||||
charIdx++
|
||||
}
|
||||
}
|
||||
@@ -975,13 +975,13 @@ func (m Model) Width() int {
|
||||
// moveToBegin moves the cursor to the beginning of the input.
|
||||
func (m *Model) moveToBegin() {
|
||||
m.row = 0
|
||||
m.SetCursor(0)
|
||||
m.SetCursorColumn(0)
|
||||
}
|
||||
|
||||
// moveToEnd moves the cursor to the end of the input.
|
||||
func (m *Model) moveToEnd() {
|
||||
m.row = len(m.value) - 1
|
||||
m.SetCursor(len(m.value[m.row]))
|
||||
m.SetCursorColumn(len(m.value[m.row]))
|
||||
}
|
||||
|
||||
// SetWidth sets the width of the textarea to fit exactly within the given width.
|
||||
@@ -1104,7 +1104,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
if len(m.value[m.row]) > 0 {
|
||||
m.value[m.row] = append(m.value[m.row][:max(0, m.col-1)], m.value[m.row][m.col:]...)
|
||||
if m.col > 0 {
|
||||
m.SetCursor(m.col - 1)
|
||||
m.SetCursorColumn(m.col - 1)
|
||||
}
|
||||
}
|
||||
case key.Matches(msg, m.KeyMap.DeleteCharacterForward):
|
||||
|
||||
Reference in New Issue
Block a user