diff --git a/lib/main/atom/views/outline/navigationTreeComponent.tsx b/lib/main/atom/views/outline/navigationTreeComponent.tsx index 0125e0dcc..477741b9c 100644 --- a/lib/main/atom/views/outline/navigationTreeComponent.tsx +++ b/lib/main/atom/views/outline/navigationTreeComponent.tsx @@ -1,4 +1,4 @@ -import {CompositeDisposable, CursorPositionChangedEvent, Disposable, TextEditor} from "atom" +import {CompositeDisposable, Disposable, TextEditor} from "atom" import * as etch from "etch" import {isEqual} from "lodash" import {NavigationTree} from "typescript/lib/protocol" @@ -32,7 +32,10 @@ export class NavigationTreeComponent constructor(public props: Props) { prepareNavTree(props.navTree) etch.initialize(this) - this.subscriptions.add(atom.workspace.observeActiveTextEditor(this.subscribeToEditor)) + this.subscriptions.add( + atom.workspace.observeActiveTextEditor(this.subscribeToEditor), + atom.commands.add("atom-workspace", "typescript:reveal-cursor", this.selectAtCursorLine) + ) } public async update(props: Partial) { @@ -138,11 +141,16 @@ export class NavigationTreeComponent * HELPER select the node's HTML represenation which corresponds to the * current cursor position */ - private selectAtCursorLine = ({newBufferPosition}: CursorPositionChangedEvent) => { + private selectAtCursorLine = () => { + const editor = atom.workspace.getActiveTextEditor() + if (editor === undefined) { + return + } + if (!this.props.navTree) { return } - const cursorLine = newBufferPosition.row + const cursorLine = editor.getCursorBufferPosition().row const selectedChild = findNodeAt(cursorLine, cursorLine, this.props.navTree) if (selectedChild !== this.selectedNode) { @@ -177,7 +185,6 @@ export class NavigationTreeComponent // set navTree await this.loadNavTree() - this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine) this.editorChanging = editor.onDidStopChanging(this.loadNavTree) } }