mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
chore: merge branch 'v2-exp' into v2-real-textarea
This commit is contained in:
+20
-22
@@ -24,9 +24,12 @@ const (
|
||||
minHeight = 1
|
||||
defaultHeight = 6
|
||||
defaultWidth = 40
|
||||
defaultCharLimit = 400
|
||||
defaultCharLimit = 0 // no limit
|
||||
defaultMaxHeight = 99
|
||||
defaultMaxWidth = 500
|
||||
|
||||
// XXX: in v2, make max lines dynamic and default max lines configurable.
|
||||
maxLines = 10000
|
||||
)
|
||||
|
||||
// Internal messages for clipboard operations.
|
||||
@@ -305,13 +308,13 @@ func New() Model {
|
||||
Prompt: lipgloss.ThickBorder().Left + " ",
|
||||
Styles: styles,
|
||||
activeStyle: &styles.Blurred,
|
||||
cache: memoization.NewMemoCache[line, [][]rune](defaultMaxHeight),
|
||||
cache: memoization.NewMemoCache[line, [][]rune](maxLines),
|
||||
EndOfBufferCharacter: ' ',
|
||||
ShowLineNumbers: true,
|
||||
Cursor: cur,
|
||||
KeyMap: DefaultKeyMap(),
|
||||
|
||||
value: make([][]rune, minHeight, defaultMaxHeight),
|
||||
value: make([][]rune, minHeight, maxLines),
|
||||
focus: false,
|
||||
col: 0,
|
||||
row: 0,
|
||||
@@ -333,23 +336,23 @@ func DefaultStyles(isDark bool) Styles {
|
||||
var s Styles
|
||||
s.Focused = StyleState{
|
||||
Base: lipgloss.NewStyle(),
|
||||
CursorLine: lipgloss.NewStyle().Background(lightDark("255", "0")),
|
||||
CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark("240", "240")),
|
||||
EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark("254", "0")),
|
||||
LineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")),
|
||||
CursorLine: lipgloss.NewStyle().Background(lightDark(lipgloss.Color("255"), lipgloss.Color("0"))),
|
||||
CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("240"), lipgloss.Color("240"))),
|
||||
EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("254"), lipgloss.Color("0"))),
|
||||
LineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))),
|
||||
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
|
||||
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
|
||||
Text: lipgloss.NewStyle(),
|
||||
}
|
||||
s.Blurred = StyleState{
|
||||
Base: lipgloss.NewStyle(),
|
||||
CursorLine: lipgloss.NewStyle().Foreground(lightDark("245", "7")),
|
||||
CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")),
|
||||
EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark("254", "0")),
|
||||
LineNumber: lipgloss.NewStyle().Foreground(lightDark("249", "7")),
|
||||
CursorLine: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("245"), lipgloss.Color("7"))),
|
||||
CursorLineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))),
|
||||
EndOfBuffer: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("254"), lipgloss.Color("0"))),
|
||||
LineNumber: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("249"), lipgloss.Color("7"))),
|
||||
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
|
||||
Prompt: lipgloss.NewStyle().Foreground(lipgloss.Color("7")),
|
||||
Text: lipgloss.NewStyle().Foreground(lightDark("245", "7")),
|
||||
Text: lipgloss.NewStyle().Foreground(lightDark(lipgloss.Color("245"), lipgloss.Color("7"))),
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -392,9 +395,8 @@ func (m *Model) insertRunesFromUserInput(runes []rune) {
|
||||
// whatnot.
|
||||
runes = m.san().Sanitize(runes)
|
||||
|
||||
var availSpace int
|
||||
if m.CharLimit > 0 {
|
||||
availSpace = m.CharLimit - m.Length()
|
||||
availSpace := m.CharLimit - m.Length()
|
||||
// If the char limit's been reached, cancel.
|
||||
if availSpace <= 0 {
|
||||
return
|
||||
@@ -425,9 +427,9 @@ func (m *Model) insertRunesFromUserInput(runes []rune) {
|
||||
lines = append(lines, runes[lstart:])
|
||||
}
|
||||
|
||||
// Obey the maximum height limit.
|
||||
if m.MaxHeight > 0 && len(m.value)+len(lines)-1 > m.MaxHeight {
|
||||
allowedHeight := max(0, m.MaxHeight-len(m.value)+1)
|
||||
// Obey the maximum line limit.
|
||||
if maxLines > 0 && len(m.value)+len(lines)-1 > maxLines {
|
||||
allowedHeight := max(0, maxLines-len(m.value)+1)
|
||||
lines = lines[:allowedHeight]
|
||||
}
|
||||
|
||||
@@ -622,11 +624,7 @@ func (m *Model) Blur() {
|
||||
|
||||
// Reset sets the input to its default state with no input.
|
||||
func (m *Model) Reset() {
|
||||
startCap := m.MaxHeight
|
||||
if startCap <= 0 {
|
||||
startCap = defaultMaxHeight
|
||||
}
|
||||
m.value = make([][]rune, minHeight, startCap)
|
||||
m.value = make([][]rune, minHeight, maxLines)
|
||||
m.col = 0
|
||||
m.row = 0
|
||||
m.realCol = 0
|
||||
|
||||
Reference in New Issue
Block a user