Tidy up ReviewPanelController

This commit is contained in:
James Allen 2016-10-13 10:09:59 +01:00
parent fc782581ea
commit 8d968f6865

View file

@ -9,33 +9,38 @@ define [
scroller = $element.find(".review-panel-scroller") scroller = $element.find(".review-panel-scroller")
list = $element.find(".review-entry-list") list = $element.find(".review-entry-list")
# Use these to avoid unnecessary updates. Scrolling one
# panel causes us to scroll the other panel, but there's no
# need to trigger the event back to the original panel.
ignoreNextPanelEvent = false ignoreNextPanelEvent = false
ignoreNextAceEvent = false ignoreNextAceEvent = false
$scope.onScroll = (scrollTop, height) -> $scope.scrollEvents = new EventEmitter()
scrollPanel = (scrollTop, height) ->
if ignoreNextAceEvent if ignoreNextAceEvent
# console.log "Ignoring ace event"
ignoreNextAceEvent = false ignoreNextAceEvent = false
else else
ignoreNextPanelEvent = true ignoreNextPanelEvent = true
list.height(height) list.height(height)
scroller.scrollTop(scrollTop) scroller.scrollTop(scrollTop)
$scope.scrollEvents = new EventEmitter()
scrollAce = (e) -> scrollAce = (e) ->
now = new Date()
if ignoreNextPanelEvent if ignoreNextPanelEvent
# console.log "Ignoring review panel event"
ignoreNextPanelEvent = false ignoreNextPanelEvent = false
else else
# console.log "review panel scrolled", e
ignoreNextAceEvent = true ignoreNextAceEvent = true
$scope.scrollEvents.emit "scroll", e.target.scrollTop $scope.scrollEvents.emit "scroll", e.target.scrollTop
lastScroll = now
previousScroll = new Date()
scroller.on "scroll", scrollAce scroller.on "scroll", scrollAce
$scope.onScroll = scrollPanel # Passed into the editor directive for it to call
# If we listen for scroll events in the review panel natively, then with a Mac trackpad
# the scroll is very smooth (natively done I'd guess), but we don't get polled regularly
# enough to keep Ace in step, and it noticeably lags. If instead, we borrow the manual
# mousewheel/trackpad scrolling behaviour from Ace, and turn mousewheel events into
# scroll events ourselves, then it makes the review panel slightly less smooth (barely)
# noticeable, but keeps it perfectly in step with Ace.
ace.require("ace/lib/event").addMouseWheelListener scroller[0], (e) -> ace.require("ace/lib/event").addMouseWheelListener scroller[0], (e) ->
deltaY = e.wheelY deltaY = e.wheelY
# console.log "mousewheel", deltaY # console.log "mousewheel", deltaY