@@ -10,9 +10,7 @@ import (
1010 "github.com/charmbracelet/x/ansi"
1111)
1212
13- const (
14- defaultHorizontalStep = 6
15- )
13+ const defaultHorizontalStep = 6
1614
1715// New returns a new model with the given width and height as well as default
1816// key mappings.
@@ -168,7 +166,7 @@ func (m Model) visibleLines() (lines []string) {
168166
169167// scrollArea returns the scrollable boundaries for high performance rendering.
170168//
171- // XXX : high performance rendering is deprecated in Bubble Tea.
169+ // Deprecated : high performance rendering is deprecated in Bubble Tea.
172170func (m Model ) scrollArea () (top , bottom int ) {
173171 top = max (0 , m .YPosition )
174172 bottom = max (top , top + m .Height )
@@ -183,45 +181,81 @@ func (m *Model) SetYOffset(n int) {
183181 m .YOffset = clamp (n , 0 , m .maxYOffset ())
184182}
185183
186- // ViewDown moves the view down by the number of lines in the viewport.
184+ // PageDown moves the view down by the number of lines in the viewport.
187185// Basically, "page down".
186+ //
187+ // Deprecated: use [Model.PageDown] instead.
188188func (m * Model ) ViewDown () []string {
189+ return m .PageDown ()
190+ }
191+
192+ // PageDown moves the view down by the number of lines in the viewport.
193+ func (m * Model ) PageDown () []string {
189194 if m .AtBottom () {
190195 return nil
191196 }
192197
193- return m .LineDown (m .Height )
198+ return m .ScrollDown (m .Height )
194199}
195200
196- // ViewUp moves the view up by one height of the viewport. Basically, "page up".
201+ // ViewUp moves the view up by one height of the viewport.
202+ // Basically, "page up".
203+ //
204+ // Deprecated: use [Model.PageUp] instead.
197205func (m * Model ) ViewUp () []string {
206+ return m .PageUp ()
207+ }
208+
209+ // PageUp moves the view up by one height of the viewport.
210+ func (m * Model ) PageUp () []string {
198211 if m .AtTop () {
199212 return nil
200213 }
201214
202- return m .LineUp (m .Height )
215+ return m .ScrollUp (m .Height )
203216}
204217
205218// HalfViewDown moves the view down by half the height of the viewport.
219+ //
220+ // Deprecated: use [Model.HalfPageDown] instead.
206221func (m * Model ) HalfViewDown () (lines []string ) {
222+ return m .HalfPageDown ()
223+ }
224+
225+ // HalfPageDown moves the view down by half the height of the viewport.
226+ func (m * Model ) HalfPageDown () (lines []string ) {
207227 if m .AtBottom () {
208228 return nil
209229 }
210230
211- return m .LineDown (m .Height / 2 ) //nolint:mnd
231+ return m .ScrollDown (m .Height / 2 ) //nolint:mnd
212232}
213233
214234// HalfViewUp moves the view up by half the height of the viewport.
235+ //
236+ // Deprecated: use [Model.HalfPageUp] instead.
215237func (m * Model ) HalfViewUp () (lines []string ) {
238+ return m .HalfPageUp ()
239+ }
240+
241+ // HalfPageUp moves the view up by half the height of the viewport.
242+ func (m * Model ) HalfPageUp () (lines []string ) {
216243 if m .AtTop () {
217244 return nil
218245 }
219246
220- return m .LineUp (m .Height / 2 ) //nolint:mnd
247+ return m .ScrollUp (m .Height / 2 ) //nolint:mnd
221248}
222249
223250// LineDown moves the view down by the given number of lines.
251+ //
252+ // Deprecated: use [Model.ScrollDown] instead.
224253func (m * Model ) LineDown (n int ) (lines []string ) {
254+ return m .ScrollDown (n )
255+ }
256+
257+ // ScrollDown moves the view down by the given number of lines.
258+ func (m * Model ) ScrollDown (n int ) (lines []string ) {
225259 if m .AtBottom () || n == 0 || len (m .lines ) == 0 {
226260 return nil
227261 }
@@ -241,7 +275,15 @@ func (m *Model) LineDown(n int) (lines []string) {
241275
242276// LineUp moves the view down by the given number of lines. Returns the new
243277// lines to show.
278+ //
279+ // Deprecated: use [Model.ScrollUp] instead.
244280func (m * Model ) LineUp (n int ) (lines []string ) {
281+ return m .ScrollUp (n )
282+ }
283+
284+ // ScrollUp moves the view down by the given number of lines. Returns the new
285+ // lines to show.
286+ func (m * Model ) ScrollUp (n int ) (lines []string ) {
245287 if m .AtTop () || n == 0 || len (m .lines ) == 0 {
246288 return nil
247289 }
@@ -258,6 +300,32 @@ func (m *Model) LineUp(n int) (lines []string) {
258300 return m .lines [top :bottom ]
259301}
260302
303+ // SetHorizontalStep sets the default amount of columns to scroll left or right
304+ // with the default viewport key map.
305+ // If set to 0 or less, horizontal scrolling is disabled.
306+ func (m * Model ) SetHorizontalStep (n int ) {
307+ if n < 0 {
308+ n = 0
309+ }
310+
311+ m .horizontalStep = n
312+ }
313+
314+ // SetXOffset sets the X offset.
315+ func (m * Model ) SetXOffset (n int ) {
316+ m .xOffset = clamp (n , 0 , m .longestLineWidth - m .Width )
317+ }
318+
319+ // ScrollLeft moves the viewport to the left by the given number of columns.
320+ func (m * Model ) ScrollLeft (n int ) {
321+ m .SetXOffset (m .xOffset - n )
322+ }
323+
324+ // ScrollRight moves viewport to the right by the given number of columns.
325+ func (m * Model ) ScrollRight (n int ) {
326+ m .SetXOffset (m .xOffset + n )
327+ }
328+
261329// TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.
262330func (m Model ) TotalLineCount () int {
263331 return len (m .lines )
@@ -305,6 +373,8 @@ func Sync(m Model) tea.Cmd {
305373//
306374// lines := model.ViewDown(1)
307375// cmd := ViewDown(m, lines)
376+ //
377+ // Deprecated: high performance rendering is deprecated in Bubble Tea.
308378func ViewDown (m Model , lines []string ) tea.Cmd {
309379 if len (lines ) == 0 {
310380 return nil
@@ -319,6 +389,8 @@ func ViewDown(m Model, lines []string) tea.Cmd {
319389// ViewUp is a high performance command the moves the viewport down by a given
320390// number of lines height. Use Model.ViewUp to get the lines that should be
321391// rendered.
392+ //
393+ // Deprecated: high performance rendering is deprecated in Bubble Tea.
322394func ViewUp (m Model , lines []string ) tea.Cmd {
323395 if len (lines ) == 0 {
324396 return nil
@@ -330,39 +402,6 @@ func ViewUp(m Model, lines []string) tea.Cmd {
330402 return tea .ScrollUp (lines , top , bottom ) //nolint:staticcheck
331403}
332404
333- // SetHorizontalStep sets the amount of cells that the viewport moves in the
334- // default viewport keymapping. If set to 0 or less, horizontal scrolling is
335- // disabled.
336- func (m * Model ) SetHorizontalStep (n int ) {
337- if n < 0 {
338- n = 0
339- }
340-
341- m .horizontalStep = n
342- }
343-
344- // MoveLeft moves the viewport to the left by the given number of columns.
345- func (m * Model ) MoveLeft (cols int ) {
346- m .xOffset -= cols
347- if m .xOffset < 0 {
348- m .xOffset = 0
349- }
350- }
351-
352- // MoveRight moves viewport to the right by the given number of columns.
353- func (m * Model ) MoveRight (cols int ) {
354- // prevents over scrolling to the right
355- if m .xOffset >= m .longestLineWidth - m .Width {
356- return
357- }
358- m .xOffset += cols
359- }
360-
361- // Resets lines indent to zero.
362- func (m * Model ) ResetIndent () {
363- m .xOffset = 0
364- }
365-
366405// Update handles standard message-based viewport updates.
367406func (m Model ) Update (msg tea.Msg ) (Model , tea.Cmd ) {
368407 var cmd tea.Cmd
@@ -383,46 +422,46 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
383422 case tea.KeyMsg :
384423 switch {
385424 case key .Matches (msg , m .KeyMap .PageDown ):
386- lines := m .ViewDown ()
425+ lines := m .PageDown ()
387426 if m .HighPerformanceRendering {
388427 cmd = ViewDown (m , lines )
389428 }
390429
391430 case key .Matches (msg , m .KeyMap .PageUp ):
392- lines := m .ViewUp ()
431+ lines := m .PageUp ()
393432 if m .HighPerformanceRendering {
394433 cmd = ViewUp (m , lines )
395434 }
396435
397436 case key .Matches (msg , m .KeyMap .HalfPageDown ):
398- lines := m .HalfViewDown ()
437+ lines := m .HalfPageDown ()
399438 if m .HighPerformanceRendering {
400439 cmd = ViewDown (m , lines )
401440 }
402441
403442 case key .Matches (msg , m .KeyMap .HalfPageUp ):
404- lines := m .HalfViewUp ()
443+ lines := m .HalfPageUp ()
405444 if m .HighPerformanceRendering {
406445 cmd = ViewUp (m , lines )
407446 }
408447
409448 case key .Matches (msg , m .KeyMap .Down ):
410- lines := m .LineDown (1 )
449+ lines := m .ScrollDown (1 )
411450 if m .HighPerformanceRendering {
412451 cmd = ViewDown (m , lines )
413452 }
414453
415454 case key .Matches (msg , m .KeyMap .Up ):
416- lines := m .LineUp (1 )
455+ lines := m .ScrollUp (1 )
417456 if m .HighPerformanceRendering {
418457 cmd = ViewUp (m , lines )
419458 }
420459
421460 case key .Matches (msg , m .KeyMap .Left ):
422- m .MoveLeft (m .horizontalStep )
461+ m .ScrollLeft (m .horizontalStep )
423462
424463 case key .Matches (msg , m .KeyMap .Right ):
425- m .MoveRight (m .horizontalStep )
464+ m .ScrollRight (m .horizontalStep )
426465 }
427466
428467 case tea.MouseMsg :
@@ -431,13 +470,13 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
431470 }
432471 switch msg .Button { //nolint:exhaustive
433472 case tea .MouseButtonWheelUp :
434- lines := m .LineUp (m .MouseWheelDelta )
473+ lines := m .ScrollUp (m .MouseWheelDelta )
435474 if m .HighPerformanceRendering {
436475 cmd = ViewUp (m , lines )
437476 }
438477
439478 case tea .MouseButtonWheelDown :
440- lines := m .LineDown (m .MouseWheelDelta )
479+ lines := m .ScrollDown (m .MouseWheelDelta )
441480 if m .HighPerformanceRendering {
442481 cmd = ViewDown (m , lines )
443482 }
0 commit comments