File tree Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,23 @@ func (s *selector) add(n node) error {
36
36
return nil
37
37
}
38
38
39
+ func (s * selector ) reindex (nodes []node ) {
40
+ if len (s .selections ) == 0 {
41
+ return
42
+ }
43
+ selections := make (map [resource.ID ]struct {}, len (s .selections ))
44
+ for _ , n := range nodes {
45
+ id , ok := n .ID ().(resource.ID )
46
+ if ! ok {
47
+ continue
48
+ }
49
+ if _ , ok := s .selections [id ]; ok {
50
+ selections [id ] = struct {}{}
51
+ }
52
+ }
53
+ s .selections = selections
54
+ }
55
+
39
56
// addAll implements "select all" functionality with a twist: it ensures only
40
57
// nodes of the same type of selected; the cursor node must match any existing
41
58
// selection type, and then the nodes are filtered to only add those
Original file line number Diff line number Diff line change
1
+ package explorer
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/leg100/pug/internal/resource"
7
+ "github.com/stretchr/testify/assert"
8
+ )
9
+
10
+ func TestSelector_isSelected (t * testing.T ) {
11
+ mod1 := moduleNode {id : resource .NewID (resource .Module )}
12
+ mod2 := moduleNode {id : resource .NewID (resource .Module )}
13
+
14
+ s := selector {selections : make (map [resource.ID ]struct {})}
15
+ s .add (mod1 )
16
+
17
+ assert .True (t , s .isSelected (mod1 ))
18
+ assert .False (t , s .isSelected (mod2 ))
19
+ }
20
+
21
+ func TestSelector_reindex (t * testing.T ) {
22
+ mod1 := moduleNode {id : resource .NewID (resource .Module )}
23
+ mod2 := moduleNode {id : resource .NewID (resource .Module )}
24
+
25
+ s := selector {selections : make (map [resource.ID ]struct {})}
26
+ s .add (mod1 )
27
+ s .add (mod2 )
28
+
29
+ assert .True (t , s .isSelected (mod1 ))
30
+ assert .True (t , s .isSelected (mod2 ))
31
+
32
+ s .reindex ([]node {mod1 })
33
+
34
+ assert .True (t , s .isSelected (mod1 ))
35
+ assert .False (t , s .isSelected (mod2 ))
36
+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ func (t *tracker) reindex(tree *tree, height int) {
39
39
t .totalWorkspaces = 0
40
40
t .cursorIndex = - 1
41
41
t .doReindex (tree )
42
+ t .selector .reindex (t .nodes )
42
43
43
44
// When pug first starts up, for the user's convenience we want the cursor
44
45
// to be on the first module. Because modules are added asynchronously, a
@@ -74,12 +75,6 @@ func (t *tracker) doReindex(tree *tree) {
74
75
if t .cursorNode != nil && t .cursorNode .ID () == tree .value .ID () {
75
76
t .cursorIndex = len (t .nodes ) - 1
76
77
}
77
- // Track indices of selected nodes
78
- if dir , ok := tree .value .(dirNode ); ok {
79
- if dir .closed {
80
- return
81
- }
82
- }
83
78
for _ , child := range tree .children {
84
79
t .doReindex (child )
85
80
}
You can’t perform that action at this time.
0 commit comments