mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
wip(textarea): using viewport's left gutter func
This commit is contained in:
+39
-41
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
@@ -1306,13 +1305,14 @@ func (m Model) View() string {
|
|||||||
|
|
||||||
var ln string
|
var ln string
|
||||||
if m.ShowLineNumbers { //nolint:nestif
|
if m.ShowLineNumbers { //nolint:nestif
|
||||||
if wl == 0 { // normal line
|
m.lineNumberView()
|
||||||
isCursorLine := m.row == l
|
// if wl == 0 { // normal line
|
||||||
s.WriteString(m.lineNumberView(l+1, isCursorLine))
|
// isCursorLine := m.row == l
|
||||||
} else { // soft wrapped line
|
// // s.WriteString(m.lineNumberView(l+1, isCursorLine))
|
||||||
isCursorLine := m.row == l
|
// } else { // soft wrapped line
|
||||||
s.WriteString(m.lineNumberView(-1, isCursorLine))
|
// isCursorLine := m.row == l
|
||||||
}
|
// // s.WriteString(m.lineNumberView(-1, isCursorLine))
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note the widest line number for padding purposes later.
|
// Note the widest line number for padding purposes later.
|
||||||
@@ -1425,30 +1425,25 @@ func (m Model) promptView(displayLine int) (prompt string) {
|
|||||||
//
|
//
|
||||||
// The second argument indicates whether this line number is for a 'cursorline'
|
// The second argument indicates whether this line number is for a 'cursorline'
|
||||||
// line number.
|
// line number.
|
||||||
func (m Model) lineNumberView(n int, isCursorLine bool) (str string) {
|
func (m Model) lineNumberView() {
|
||||||
if !m.ShowLineNumbers {
|
if !m.ShowLineNumbers {
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if n <= 0 {
|
m.viewport.LeftGutterFunc = func(info viewport.GutterContext) string {
|
||||||
str = " "
|
style := m.activeStyle().LineNumber
|
||||||
} else {
|
if info.Soft {
|
||||||
str = strconv.Itoa(n)
|
return style.Render(" │ ")
|
||||||
}
|
}
|
||||||
|
if info.Index >= info.TotalLines {
|
||||||
// XXX: is textStyle really necessary here?
|
return style.Render(" ~ │ ")
|
||||||
textStyle := m.activeStyle().computedText()
|
}
|
||||||
lineNumberStyle := m.activeStyle().computedLineNumber()
|
if m.row == info.Index {
|
||||||
if isCursorLine {
|
return m.activeStyle().CursorLineNumber.Render(fmt.Sprintf("%4d", info.Index+1)) +
|
||||||
textStyle = m.activeStyle().computedCursorLine()
|
style.Render(" │ ")
|
||||||
lineNumberStyle = m.activeStyle().computedCursorLineNumber()
|
}
|
||||||
|
return style.Render(fmt.Sprintf("%4d │ ", info.Index+1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format line number dynamically based on the maximum number of lines.
|
|
||||||
digits := len(strconv.Itoa(m.MaxHeight))
|
|
||||||
str = fmt.Sprintf(" %*v ", digits, str)
|
|
||||||
|
|
||||||
return textStyle.Render(lineNumberStyle.Render(str))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// placeholderView returns the prompt and placeholder, if any.
|
// placeholderView returns the prompt and placeholder, if any.
|
||||||
@@ -1466,7 +1461,7 @@ func (m Model) placeholderView() string {
|
|||||||
plines := strings.Split(strings.TrimSpace(pwrap), "\n")
|
plines := strings.Split(strings.TrimSpace(pwrap), "\n")
|
||||||
|
|
||||||
for i := 0; i < m.height; i++ {
|
for i := 0; i < m.height; i++ {
|
||||||
isLineNumber := len(plines) > i
|
// isLineNumber := len(plines) > i
|
||||||
|
|
||||||
lineStyle := styles.computedPlaceholder()
|
lineStyle := styles.computedPlaceholder()
|
||||||
if len(plines) > i {
|
if len(plines) > i {
|
||||||
@@ -1482,18 +1477,18 @@ func (m Model) placeholderView() string {
|
|||||||
// - render line number for only the cursor line
|
// - render line number for only the cursor line
|
||||||
// - indent other placeholder lines
|
// - indent other placeholder lines
|
||||||
// this is consistent with vim with line numbers enabled
|
// this is consistent with vim with line numbers enabled
|
||||||
if m.ShowLineNumbers {
|
// if m.ShowLineNumbers {
|
||||||
var ln int
|
// var ln int
|
||||||
|
//
|
||||||
switch {
|
// switch {
|
||||||
case i == 0:
|
// case i == 0:
|
||||||
ln = i + 1
|
// ln = i + 1
|
||||||
fallthrough
|
// fallthrough
|
||||||
case len(plines) > i:
|
// case len(plines) > i:
|
||||||
s.WriteString(m.lineNumberView(ln, isLineNumber))
|
// s.WriteString(m.lineNumberView(ln, isLineNumber))
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// first line
|
// first line
|
||||||
@@ -1558,11 +1553,14 @@ func (m Model) Cursor() *tea.Cursor {
|
|||||||
|
|
||||||
xOffset := lineInfo.CharOffset +
|
xOffset := lineInfo.CharOffset +
|
||||||
w(m.promptView(0)) +
|
w(m.promptView(0)) +
|
||||||
w(m.lineNumberView(0, false)) +
|
|
||||||
baseStyle.GetMarginLeft() +
|
baseStyle.GetMarginLeft() +
|
||||||
baseStyle.GetPaddingLeft() +
|
baseStyle.GetPaddingLeft() +
|
||||||
baseStyle.GetBorderLeftSize()
|
baseStyle.GetBorderLeftSize()
|
||||||
|
|
||||||
|
if m.ShowLineNumbers {
|
||||||
|
xOffset += lipgloss.Width(m.viewport.LeftGutterFunc(viewport.GutterContext{}))
|
||||||
|
}
|
||||||
|
|
||||||
yOffset := m.cursorLineNumber() +
|
yOffset := m.cursorLineNumber() +
|
||||||
m.viewport.YOffset +
|
m.viewport.YOffset +
|
||||||
baseStyle.GetMarginTop() +
|
baseStyle.GetMarginTop() +
|
||||||
|
|||||||
Reference in New Issue
Block a user