Browse Source

Fix TextView region highlighting

tablepad
Trevor Slocum 2 years ago
parent
commit
b47c35329c
  1. 3
      demos/presentation/main.go
  2. 4
      table.go
  3. 4
      textview.go

3
demos/presentation/main.go

@ -67,8 +67,7 @@ func main() {
// The bottom row has some info on where we are.
info := cview.NewTextView()
info.
SetDynamicColors(true)
info.SetDynamicColors(true)
info.SetRegions(true)
info.SetWrap(false)
info.SetHighlightedFunc(func(added, removed, remaining []string) {

4
table.go

@ -1401,9 +1401,7 @@ func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primi
}
// If the selection has changed, notify the handler.
if t.selectionChanged != nil &&
(t.rowsSelectable && previouslySelectedRow != t.selectedRow ||
t.columnsSelectable && previouslySelectedColumn != t.selectedColumn) {
if t.selectionChanged != nil && ((t.rowsSelectable && previouslySelectedRow != t.selectedRow) || (t.columnsSelectable && previouslySelectedColumn != t.selectedColumn)) {
t.Unlock()
t.selectionChanged(t.selectedRow, t.selectedColumn)
t.Lock()

4
textview.go

@ -564,7 +564,7 @@ func (t *TextView) Highlight(regionIDs ...string) {
t.index = nil
// Notify.
if t.highlighted != nil && len(added) > 0 || len(removed) > 0 {
if t.highlighted != nil && (len(added) > 0 || len(removed) > 0) {
t.Unlock()
t.highlighted(added, removed, remaining)
} else {
@ -1121,7 +1121,7 @@ func (t *TextView) Draw(screen tcell.Screen) {
colorPos++
} else if regionPos < len(regionIndices) && textPos+tagOffset >= regionIndices[regionPos][0] && textPos+tagOffset < regionIndices[regionPos][1] {
// Get the region.
if len(regionID) > 0 && len(t.regionInfos) > 0 && !bytes.Equal(t.regionInfos[len(t.regionInfos)-1].ID, regionID) {
if len(regionID) > 0 && len(t.regionInfos) > 0 && bytes.Equal(t.regionInfos[len(t.regionInfos)-1].ID, regionID) {
// End last region.
t.regionInfos[len(t.regionInfos)-1].ToX = x + posX
t.regionInfos[len(t.regionInfos)-1].ToY = y + line - t.lineOffset

Loading…
Cancel
Save