forked from tslocum/cview
Add TextView.SetReindexBuffer
This commit is contained in:
parent
f35f86924a
commit
a6a473f866
|
@ -1,6 +1,7 @@
|
|||
v1.4.9 (WIP)
|
||||
- Add InputField.GetCursorPosition and InputField.SetCursorPosition
|
||||
- Add Table.Sort, Table.SetSortFunc and Table.SetSortClicked
|
||||
- Add TextView.SetReindexBuffer
|
||||
- Upgrade tcell to v2: includes strikethrough support
|
||||
|
||||
v1.4.8 (2020-08-11)
|
||||
|
|
4
FORK.md
4
FORK.md
|
@ -43,6 +43,10 @@ All clicks are handled as single clicks until an interval is set with [Applicati
|
|||
Call [Box.SetBackgroundTransparent](https://docs.rocketnine.space/gitlab.com/tslocum/cview/#Box.SetBackgroundTransparent)
|
||||
to enable background transparency.
|
||||
|
||||
## Tables are sorted when a fixed row is clicked by default
|
||||
|
||||
Call [Table.SetSortClicked] to disable this behavior.
|
||||
|
||||
## Lists and Forms do not wrap around by default
|
||||
|
||||
Call [List.SetWrapAround](https://docs.rocketnine.space/gitlab.com/tslocum/cview/#List.SetWrapAround) to wrap around when navigating.
|
||||
|
|
29
textview.go
29
textview.go
|
@ -109,6 +109,9 @@ type TextView struct {
|
|||
// to be re-indexed.
|
||||
index []*textViewIndex
|
||||
|
||||
// If set to true, the buffer will be reindexed each time it is modified.
|
||||
reindex bool
|
||||
|
||||
// The text alignment, one of AlignLeft, AlignCenter, or AlignRight.
|
||||
align int
|
||||
|
||||
|
@ -200,6 +203,7 @@ func NewTextView() *TextView {
|
|||
Box: NewBox(),
|
||||
highlights: make(map[string]struct{}),
|
||||
lineOffset: -1,
|
||||
reindex: true,
|
||||
scrollable: true,
|
||||
align: AlignLeft,
|
||||
wrap: true,
|
||||
|
@ -478,7 +482,9 @@ func (t *TextView) Clear() *TextView {
|
|||
func (t *TextView) clear() *TextView {
|
||||
t.buffer = nil
|
||||
t.recentBytes = nil
|
||||
t.index = nil
|
||||
if t.reindex {
|
||||
t.index = nil
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -752,11 +758,30 @@ func (t *TextView) write(p []byte) (n int, err error) {
|
|||
t.clipBuffer()
|
||||
|
||||
// Reset the index.
|
||||
t.index = nil
|
||||
if t.reindex {
|
||||
t.index = nil
|
||||
}
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// SetReindexBuffer set a flag controlling whether the buffer is reindexed when
|
||||
// it is modified. This improves the performance of TextViews whose contents
|
||||
// always have line-breaks in the same location. This must be called after the
|
||||
// buffer has been indexed.
|
||||
func (t *TextView) SetReindexBuffer(reindex bool) *TextView {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
|
||||
t.reindex = reindex
|
||||
|
||||
if reindex {
|
||||
t.index = nil
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
// reindexBuffer re-indexes the buffer such that we can use it to easily draw
|
||||
// the buffer onto the screen. Each line in the index will contain a pointer
|
||||
// into the buffer from which on we will print text. It will also contain the
|
||||
|
|
Loading…
Reference in New Issue