Skip to content

Commit 50038eb

Browse files
authored
fix(textarea): ensure cursor is always in view (#840)
Signed-off-by: Liam Stanley <liam@liam.sh>
1 parent c690ea5 commit 50038eb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

textarea/textarea.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ func (m *Model) CursorDown() {
630630
m.col = nli.StartColumn
631631

632632
if nli.Width <= 0 {
633+
m.repositionView()
633634
return
634635
}
635636

@@ -641,6 +642,8 @@ func (m *Model) CursorDown() {
641642
offset += rw.RuneWidth(m.value[m.row][m.col])
642643
m.col++
643644
}
645+
646+
m.repositionView()
644647
}
645648

646649
// CursorUp moves the cursor up by one line.
@@ -665,6 +668,7 @@ func (m *Model) CursorUp() {
665668
m.col = nli.StartColumn
666669

667670
if nli.Width <= 0 {
671+
m.repositionView()
668672
return
669673
}
670674

@@ -676,6 +680,8 @@ func (m *Model) CursorUp() {
676680
offset += rw.RuneWidth(m.value[m.row][m.col])
677681
m.col++
678682
}
683+
684+
m.repositionView()
679685
}
680686

681687
// SetCursorColumn moves the cursor to the given position. If the position is
@@ -1041,12 +1047,14 @@ func (m Model) Width() int {
10411047
func (m *Model) MoveToBegin() {
10421048
m.row = 0
10431049
m.SetCursorColumn(0)
1050+
m.repositionView()
10441051
}
10451052

10461053
// MoveToEnd moves the cursor to the end of the input.
10471054
func (m *Model) MoveToEnd() {
10481055
m.row = len(m.value) - 1
10491056
m.SetCursorColumn(len(m.value[m.row]))
1057+
m.repositionView()
10501058
}
10511059

10521060
// SetWidth sets the width of the textarea to fit exactly within the given width.
@@ -1125,6 +1133,8 @@ func (m *Model) SetHeight(h int) {
11251133
m.height = max(h, minHeight)
11261134
m.viewport.SetHeight(max(h, minHeight))
11271135
}
1136+
1137+
m.repositionView()
11281138
}
11291139

11301140
// Update is the Bubble Tea update loop.

0 commit comments

Comments
 (0)