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 24bd96f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
18 changes: 17 additions & 1 deletion dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

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 24bd96f

Please sign in to comment.