sQu1rr / nerd-treeview

Vim-like NERD Tree behaviour for Atom.io Tree View
https://atom.io/packages/nerd-treeview
MIT License
19 stars 5 forks source link

Uncaught TypeError: $tree.offset is not a function #15

Closed jordwalke closed 7 years ago

jordwalke commented 7 years ago

Open the tree view. Use j/k.

Atom: 1.16.0-beta0 x64 Electron: 1.3.13 OS: Mac OS X 10.12.2 Thrown From: nerd-treeview package 0.4.3

Stack Trace

Uncaught TypeError: $tree.offset is not a function

At /Users/jwalke/.atom/packages/nerd-treeview/lib/nerd-treeview.coffee:7

TypeError: $tree.offset is not a function
  at visible (/packages/nerd-treeview/lib/nerd-treeview.coffee:7:21)
  at scrollIfInvisible (/packages/nerd-treeview/lib/nerd-treeview.coffee:12:8)
  at Object.jump (/packages/nerd-treeview/lib/nerd-treeview.coffee:254:13)
  at Object.jumpDown (/packages/nerd-treeview/lib/nerd-treeview.coffee:290:10)
  at /packages/nerd-treeview/lib/nerd-treeview.coffee:60:44)
  at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/app.asar/src/command-registry.js:259:29)
  at /app.asar/src/command-registry.js:3:59
  at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:599:16)
  at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:390:22)
  at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/app.asar/src/window-event-handler.js:106:36)
  at /app.asar/src/window-event-handler.js:3:59)

Commands

  2x -0:23.9.0 tree-view:toggle (input.hidden-input)
  6x -0:23.3.0 nerd-treeview:jump-down (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  7x -0:22.6.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
 19x -0:21.9.0 nerd-treeview:jump-down (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:20.9.0 nerd-treeview:jump-line (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  7x -0:20.5.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:19.7.0 nerd-treeview:jump-line (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:19.2.0 nerd-treeview:jump-top (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:18.8.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  5x -0:18.8.0 nerd-treeview:jump-down (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  5x -0:18.3.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  2x -0:17.9.0 nerd-treeview:open (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  7x -0:16.8.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
  2x -0:16.3.0 nerd-treeview:open (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:15.2.0 nerd-treeview:jump-up (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)
     -0:15.1.0 nerd-treeview:open (ol.tree-view.full-menu.list-tree.has-collapsable-children.focusable-panel)

Non-Core Packages

.bin undefined 
atom-reason 0.0.5 
atom-reason-loader 0.5.0 
base16-ocean-dark-syntax-theme 0.1.10 
browser-plus 0.0.87 
busy-signal 1.3.0 
docblockr 0.9.4 
focus-pane-or-panel 0.2.0 
git-time-machine 1.5.3 
gruvbox 1.0.5 
intentions 1.1.2 
language-ocaml 1.1.2 
language-reason 0.0.11 
lazy-motion 0.4.0 
linter 2.1.2 
linter-ui-default 1.2.2 
markdown-preview-enhanced 0.10.11 
markdown-preview-opener 0.1.1 
minimap 4.25.0 
nerd-treeview 0.4.3 
node_modules undefined 
nuclide 0.214.0 
oceanic-next 1.0.0 
project-find-navigation 0.3.0 
spacegray-dark-neue-ui 1.6.0 
Stylus 3.0.0 
toggle-gutter 0.2.2 
tool-bar 1.0.1 
vim-mode-plus 0.86.1 
vim-mode-plus-ex-mode 0.9.0 
vim-mode-plus-project-find-from-search 0.2.0 
yet-another-base16-ocean-light-theme 3.3.0 
markovicdenis commented 7 years ago

Here is a quickfix for this error which works for me.. Add $tree = $($tree) to 12th line of ".atom/packages/nerd-treeview/lib/nerd-treeview.coffee"

$ = jQuery = require 'jquery'

# influenced by https://github.com/customd/jquery-visible
visible = ($e, $tree) ->
    top = $e.offset().top
    bottom = top + $e.height()
    treeTop = $tree.offset().top
    treeBottom = treeTop + $tree.height()
    return top >= treeTop and bottom <= treeBottom

scrollIfInvisible = ($e, $tree) ->
    $tree = $($tree)
    if not visible($e, $tree)
        $e[0]?.scrollIntoView($e.offset().top < $tree.offset().top)

...
dcalhoun commented 7 years ago

@markovicdenis would you be willing to open a PR with your fix, please?

markovicdenis commented 7 years ago

@dcalhoun This what I'm doing seems like a hack, but it seems to fix the error. In the latest version you actually have to add $tree = $($tree.element)..

Anyways, submitted a PR with some checks to make sure that $tree is not already an jQuery object in "scrollIfInvisible" function

jordwalke commented 7 years ago

Glad to see a fix. Atom is getting Faster, and VMP is as well so this plugin is of renewed interest.