Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(viewport): gutter column, soft wrap, search highlight #697

Open
wants to merge 40 commits into
base: feature/i236-viewport-horizontal-scroll
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2f4a36a
feat(viewport): column sign
caarlos0 Jan 7, 2025
ea26eb7
feat: gutter, soft wrap
caarlos0 Jan 8, 2025
6c10dc2
wip: search
caarlos0 Jan 8, 2025
4eebb08
wip: search
caarlos0 Jan 8, 2025
eb50edc
wip: search
caarlos0 Jan 8, 2025
7784024
fix: perf
caarlos0 Jan 8, 2025
303ded7
fix: rename
caarlos0 Jan 8, 2025
619bac5
wip
caarlos0 Jan 8, 2025
d1ff1ab
wip
caarlos0 Jan 9, 2025
fbf76e8
refactor: viewport highlight ranges
caarlos0 Jan 9, 2025
5880b3a
fix: ligloss update
caarlos0 Jan 9, 2025
8e14bd2
doc: godoc
caarlos0 Jan 9, 2025
7f6d0eb
feat: fill height optional
caarlos0 Jan 9, 2025
8ddb856
fix: handle no content
caarlos0 Jan 9, 2025
0c86665
fix: empty lines
caarlos0 Jan 9, 2025
2d53a61
feat(viewport): horizontal scroll (#240)
tty2 Jan 10, 2025
e1944c4
Merge remote-tracking branch 'origin/master' into columnsign
caarlos0 Jan 10, 2025
b5f1251
wip
caarlos0 Jan 10, 2025
933f181
wip
caarlos0 Jan 10, 2025
0e3e31b
Revert "wip"
caarlos0 Jan 10, 2025
a7dc5f8
Reapply "wip"
caarlos0 Jan 10, 2025
d1928be
fix: wide
caarlos0 Jan 10, 2025
28cd0ad
fix: wide, find
caarlos0 Jan 10, 2025
067e70a
still not quite there
caarlos0 Jan 10, 2025
2a3bb65
fix: grapheme width
caarlos0 Jan 10, 2025
7b96ddd
fix: cleanups
caarlos0 Jan 10, 2025
912d216
fix: refactors, improves highlight visibility
caarlos0 Jan 11, 2025
7d13ae0
docs: godoc
caarlos0 Jan 11, 2025
87a4e45
docs: additional bubbles (#583)
caarlos0 Jan 17, 2025
e3ce11a
docs: update charm & friends blurb (#703)
bashbunni Jan 17, 2025
7ab08fb
fix(viewport): scroll to last line when borders (#706)
caarlos0 Jan 21, 2025
1bdd4c6
fix: stopwatch.Start() (#707)
bevicted Jan 22, 2025
0632e23
Merge remote-tracking branch 'origin/master' into columnsign
caarlos0 Jan 23, 2025
06eda29
chore: lipgloss update
caarlos0 Jan 23, 2025
b66bc64
chore: x/ansi update
caarlos0 Jan 23, 2025
74c65d3
fix: typos, godocs
caarlos0 Jan 23, 2025
4ac5ac9
fix: rename
caarlos0 Jan 23, 2025
3d06ce4
fix: typo
caarlos0 Jan 23, 2025
01cca44
fix: scroll when soft-wrapping
caarlos0 Jan 23, 2025
afe305c
fix: soft wrap adjustments
caarlos0 Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ type Model struct {
// Deprecated: high performance rendering is now deprecated in Bubble Tea.
HighPerformanceRendering bool

// ColumnSignFn allows to define a function that adds a column into the
// left of the viewpart, which is kept when horizontal scrolling.
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
// Thing line numbers, selection indicators, and etc.
// Argument [i] is the 0-indexed line, [total] is the total amount of lines.
ColumnSignFn func(i, total int) string
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved

initialized bool
lines []string
longestLineWidth int
Expand All @@ -77,6 +83,7 @@ func (m *Model) setInitialValues() {
m.MouseWheelDelta = 3
m.initialized = true
m.horizontalStep = defaultHorizontalStep
m.ColumnSignFn = func(int, int) string { return "" }
}

// Init exists to satisfy the tea.Model interface for composability purposes.
Expand Down Expand Up @@ -147,23 +154,37 @@ func (m Model) maxYOffset() int {
// viewport.
func (m Model) visibleLines() (lines []string) {
h := m.Height - m.Style.GetVerticalFrameSize()
w := m.Width - m.Style.GetHorizontalFrameSize()
w := m.Width -
m.Style.GetHorizontalFrameSize() -
lipgloss.Width(m.ColumnSignFn(0, 0))

if len(m.lines) > 0 {
top := max(0, m.YOffset)
bottom := clamp(m.YOffset+h, top, len(m.lines))
lines = m.lines[top:bottom]
}

for len(lines) < h {
lines = append(lines, "")
}

if (m.xOffset == 0 && m.longestLineWidth <= w) || w == 0 {
return lines
return m.prependColumn(lines)
}

cutLines := make([]string, len(lines))
for i := range lines {
cutLines[i] = ansi.Cut(lines[i], m.xOffset, m.xOffset+w)
}
return cutLines
return m.prependColumn(cutLines)
}

func (m Model) prependColumn(lines []string) []string {
result := make([]string, len(lines))
for i, line := range lines {
result[i] = m.ColumnSignFn(i+m.YOffset, m.TotalLineCount()) + line
}
return result
}

// scrollArea returns the scrollable boundaries for high performance rendering.
Expand Down Expand Up @@ -352,7 +373,10 @@ func (m *Model) MoveLeft(cols int) {
// MoveRight moves viewport to the right by the given number of columns.
func (m *Model) MoveRight(cols int) {
// prevents over scrolling to the right
if m.xOffset >= m.longestLineWidth-m.Width {
w := m.Width -
m.Style.GetHorizontalFrameSize() -
lipgloss.Width(m.ColumnSignFn(0, 0))
if m.xOffset > m.longestLineWidth-w {
return
}
m.xOffset += cols
Expand Down
Loading