Skip to content

Commit f439d83

Browse files
committed
fix(textarea): max height should not determine max lines
Fixes #671.
1 parent 730f5a2 commit f439d83

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

textarea/textarea.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const (
2727
defaultCharLimit = 400
2828
defaultMaxHeight = 99
2929
defaultMaxWidth = 500
30+
31+
// XXX: in v2, make max lines dynamic and default max lines configurable.
32+
maxLines = 10000
3033
)
3134

3235
// Internal messages for clipboard operations.
@@ -290,13 +293,13 @@ func New() Model {
290293
style: &blurredStyle,
291294
FocusedStyle: focusedStyle,
292295
BlurredStyle: blurredStyle,
293-
cache: memoization.NewMemoCache[line, [][]rune](defaultMaxHeight),
296+
cache: memoization.NewMemoCache[line, [][]rune](maxLines),
294297
EndOfBufferCharacter: ' ',
295298
ShowLineNumbers: true,
296299
Cursor: cur,
297300
KeyMap: DefaultKeyMap,
298301

299-
value: make([][]rune, minHeight, defaultMaxHeight),
302+
value: make([][]rune, minHeight, maxLines),
300303
focus: false,
301304
col: 0,
302305
row: 0,
@@ -360,9 +363,8 @@ func (m *Model) insertRunesFromUserInput(runes []rune) {
360363
// whatnot.
361364
runes = m.san().Sanitize(runes)
362365

363-
var availSpace int
364366
if m.CharLimit > 0 {
365-
availSpace = m.CharLimit - m.Length()
367+
availSpace := m.CharLimit - m.Length()
366368
// If the char limit's been reached, cancel.
367369
if availSpace <= 0 {
368370
return
@@ -393,9 +395,9 @@ func (m *Model) insertRunesFromUserInput(runes []rune) {
393395
lines = append(lines, runes[lstart:])
394396
}
395397

396-
// Obey the maximum height limit.
397-
if m.MaxHeight > 0 && len(m.value)+len(lines)-1 > m.MaxHeight {
398-
allowedHeight := max(0, m.MaxHeight-len(m.value)+1)
398+
// Obey the maximum line limit.
399+
if maxLines > 0 && len(m.value)+len(lines)-1 > maxLines {
400+
allowedHeight := max(0, maxLines-len(m.value)+1)
399401
lines = lines[:allowedHeight]
400402
}
401403

@@ -590,11 +592,7 @@ func (m *Model) Blur() {
590592

591593
// Reset sets the input to its default state with no input.
592594
func (m *Model) Reset() {
593-
startCap := m.MaxHeight
594-
if startCap <= 0 {
595-
startCap = defaultMaxHeight
596-
}
597-
m.value = make([][]rune, minHeight, startCap)
595+
m.value = make([][]rune, minHeight, maxLines)
598596
m.col = 0
599597
m.row = 0
600598
m.viewport.GotoTop()

0 commit comments

Comments
 (0)