diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-18 17:45:37 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-18 17:45:37 +0200 |
| commit | 6b13e0184d296273eb6c473e5e065824e6370746 (patch) | |
| tree | 7200f9b4bbd8a527c378f86e4bae089bc44a266a /internal/client | |
| parent | 86c1b7aa58d9b8b9fe9c8579d4089157b3e62688 (diff) | |
Fixed a bug where blank lines in visual or visual line mode won't be
highlighted
Diffstat (limited to 'internal/client')
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index 2bd9c4d..ec391b7 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -110,14 +110,7 @@ func (m Model) Init() tea.Cmd { } func (m Model) View() string { - var lines [][]rune - if len(m.lines) == 1 && len(m.lines[0]) == 0 { - // placeholder := m.PlaceholderStyle.Render(m.Placeholder) - // lines = append(lines, []rune(placeholder)) - lines = m.lines - } else { - lines = m.lines - } + lines := m.lines var builder strings.Builder switch m.mode { @@ -132,7 +125,12 @@ func (m Model) View() string { if m.cursorLine != i { builder.WriteString(string(line)) - } else if m.cursorColumn == len(m.lines[m.cursorLine]) { + } else if len(m.lines) == 1 && len(line) == 0 && m.Placeholder != "" { + cursorChar := m.PlaceholderStyle.Render(m.Placeholder[0:1]) + rest := m.PlaceholderStyle.Render(m.Placeholder[1:]) + builder.WriteString(CursorStyle.Render(cursorChar)) + builder.WriteString(rest) + } else if m.cursorColumn == len(line) { builder.WriteString(string(line)) builder.WriteString(CursorStyle.Render(" ")) } else { @@ -154,12 +152,15 @@ func (m Model) View() string { lineDecoration := m.LineDecoration(i, m) builder.WriteString(lineDecoration) - if isAnchorBefore && m.vline < i && i < m.cursorLine { - // Entire line highlighted - builder.WriteString(VisualStyle.Render(string(line))) - } else if !isAnchorBefore && m.cursorLine < i && i < m.vline { + before := isAnchorBefore && m.vline < i && i < m.cursorLine + after := !isAnchorBefore && m.cursorLine < i && i < m.vline + isInBetween := before || after + if isInBetween { // Entire line highlighted builder.WriteString(VisualStyle.Render(string(line))) + if len(line) == 0 { + builder.WriteString(VisualStyle.Render(" ")) + } } else if m.cursorLine != i && m.vline != i { // Normal line builder.WriteString(string(line)) @@ -167,8 +168,13 @@ func (m Model) View() string { // Both anchor and cursor are on the same line if m.cursorColumn == m.vcol { builder.WriteString(string(line[:m.cursorColumn])) - builder.WriteString(CursorStyle.Render(string(line[m.cursorColumn]))) - builder.WriteString(string(line[m.cursorColumn+1:])) + if len(line) != 0 { + cursorChar := string(line[m.cursorColumn]) + builder.WriteString(CursorStyle.Render(cursorChar)) + builder.WriteString(string(line[m.cursorColumn+1:])) + } else { + builder.WriteString(CursorStyle.Render(" ")) + } builder.WriteByte('\n') continue } @@ -246,10 +252,14 @@ func (m Model) View() string { lineDecoration := m.LineDecoration(i, m) builder.WriteString(lineDecoration) - if isAnchorBefore && m.vline <= i && i < m.cursorLine { - builder.WriteString(VisualStyle.Render(string(line))) - } else if !isAnchorBefore && m.cursorLine < i && i <= m.vline { + before := isAnchorBefore && m.vline <= i && i < m.cursorLine + after := !isAnchorBefore && m.cursorLine < i && i <= m.vline + isInBetween := before || after + if isInBetween { builder.WriteString(VisualStyle.Render(string(line))) + if len(line) == 0 { + builder.WriteString(VisualStyle.Render(" ")) + } } else if m.cursorLine != i { builder.WriteString(string(line)) } else if m.cursorColumn == len(m.lines[m.cursorLine]) { |
