-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Full text modal for attribute tree
Showing
8 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package component | ||
|
||
import ( | ||
"github.com/gdamore/tcell/v2" | ||
"github.com/rivo/tview" | ||
) | ||
|
||
type showModalFunc func(tview.Primitive, string) *tview.TextView | ||
|
||
type hideModalFunc func(tview.Primitive) | ||
|
||
func attachModalForTreeAttributes(tree *tview.TreeView, showFn showModalFunc, hideFn hideModalFunc) { | ||
var currentModalNode *tview.TreeNode = nil | ||
tree.SetSelectedFunc(func(node *tview.TreeNode) { | ||
if len(node.GetChildren()) > 0 { | ||
node.SetExpanded(!node.IsExpanded()) | ||
return | ||
} | ||
if currentModalNode == node { | ||
hideFn(tree) | ||
currentModalNode = nil | ||
return | ||
} | ||
textView := showFn(tree, node.GetText()) | ||
textView.SetTitle("Scroll (Ctrl+J, Ctrl+K)") | ||
currentModalNode = node | ||
tree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { | ||
switch event.Key() { | ||
case tcell.KeyCtrlJ: | ||
row, col := textView.GetScrollOffset() | ||
textView.ScrollTo(row+1, col) | ||
return nil | ||
case tcell.KeyCtrlK: | ||
row, col := textView.GetScrollOffset() | ||
textView.ScrollTo(row-1, col) | ||
return nil | ||
} | ||
return event | ||
}) | ||
}) | ||
tree.SetChangedFunc(func(node *tview.TreeNode) { | ||
if currentModalNode != nil { | ||
hideFn(tree) | ||
currentModalNode = nil | ||
} | ||
}) | ||
} |