Skip to content

Commit

Permalink
Replace continuous cursor following with a command
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 28, 2021
1 parent f9153cd commit e8bbb25
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/main/atom/views/outline/navigationTreeComponent.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<Props>) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -177,7 +185,6 @@ export class NavigationTreeComponent
// set navTree
await this.loadNavTree()

this.editorScrolling = editor.onDidChangeCursorPosition(this.selectAtCursorLine)
this.editorChanging = editor.onDidStopChanging(this.loadNavTree)
}
}

0 comments on commit e8bbb25

Please sign in to comment.