@@ -3,7 +3,6 @@ import * as etch from "etch"
33import { isEqual } from "lodash"
44import { NavigationTree } from "typescript/lib/protocol"
55import { GetClientFunction } from "../../../../client"
6- import { handlePromise } from "../../../../utils"
76import * as atomUtils from "../../utils"
87import { NavigationNodeComponent } from "./navigationNodeComponent"
98import {
@@ -25,7 +24,6 @@ export class NavigationTreeComponent
2524 private editor ?: TextEditor
2625 private editorScrolling ?: Disposable
2726 private editorChanging ?: Disposable
28- private selectedNode ?: NavigationTreeViewModel
2927 private getClient ?: GetClientFunction
3028 private subscriptions = new CompositeDisposable ( )
3129
@@ -48,7 +46,6 @@ export class NavigationTreeComponent
4846 if ( this . editorChanging ) this . editorChanging . dispose ( )
4947 this . editorScrolling = undefined
5048 this . editorChanging = undefined
51- this . selectedNode = undefined
5249 this . subscriptions . dispose ( )
5350 await etch . destroy ( this )
5451 }
@@ -59,7 +56,25 @@ export class NavigationTreeComponent
5956 }
6057
6158 public getSelectedNode ( ) {
62- return this . selectedNode
59+ return this . element . querySelector < HTMLElement > ( ".header.selected" ) ?? undefined
60+ }
61+
62+ public clearSelection ( ) {
63+ const elems = this . element . querySelectorAll < HTMLElement > ( ".header.selected" )
64+ for ( let i = 0 ; i < elems . length ; i += 1 ) {
65+ elems . item ( i ) . classList . remove ( "selected" )
66+ }
67+ }
68+
69+ public markSelection ( node ?: HTMLLIElement ) {
70+ this . clearSelection ( )
71+ if ( ! node ) return
72+ const h = node . querySelector < HTMLElement > ( ".header" )
73+ if ( h ) h . classList . add ( "selected" )
74+ }
75+
76+ public firstNode ( ) {
77+ return this . element . querySelector < HTMLLIElement > ( "li.node" ) ?? undefined
6378 }
6479
6580 public render ( ) {
@@ -106,14 +121,13 @@ export class NavigationTreeComponent
106121 restoreCollapsed ( navTree , this . props . navTree )
107122 this . props . navTree = navTree
108123
109- let selectedNode : NavigationTreeViewModel | undefined
110- if ( navTree ) {
124+ const node = this . firstNode ( )
125+ if ( node ) {
111126 const cursorLine = this . getCursorLine ( )
112127 if ( cursorLine !== undefined ) {
113- selectedNode = findNodeAt ( cursorLine , cursorLine , navTree )
128+ this . markSelection ( findNodeAt ( cursorLine , cursorLine , node ) )
114129 }
115130 }
116- this . selectedNode = selectedNode
117131 }
118132
119133 private loadNavTree = async ( ) => {
@@ -139,15 +153,18 @@ export class NavigationTreeComponent
139153 * current cursor position
140154 */
141155 private selectAtCursorLine = ( { newBufferPosition} : CursorPositionChangedEvent ) => {
142- if ( ! this . props . navTree ) {
156+ const firstNodeElem = this . firstNode ( )
157+ if ( ! firstNodeElem ) {
143158 return
144159 }
145160 const cursorLine = newBufferPosition . row
146161
147- const selectedChild = findNodeAt ( cursorLine , cursorLine , this . props . navTree )
148- if ( selectedChild !== this . selectedNode ) {
149- this . selectedNode = selectedChild
150- handlePromise ( etch . update ( this ) )
162+ const selectedChild =
163+ findNodeAt ( cursorLine , cursorLine , firstNodeElem ) ?. querySelector ( ".header" ) ?? undefined
164+ const currentSelection = this . getSelectedNode ( )
165+ if ( selectedChild !== currentSelection ) {
166+ if ( currentSelection ) currentSelection . classList . remove ( "selected" )
167+ if ( selectedChild ) selectedChild . classList . add ( "selected" )
151168 }
152169 }
153170
0 commit comments