-
-
Save ncreep/a87f127abd962d3cec56 to your computer and use it in GitHub Desktop.
atom.workspace.observeTextEditors (item) -> | |
# Sets up middle button scroll on the given editor component | |
middleMouseScrollSetup = (editorComponent) -> | |
lastClick = {x: 0, y: 0} | |
lastPosition = {x: 0, y: 0} | |
{scrollContainer} = editorComponent.refs | |
onMouseMove = (event) -> | |
[lastPosition.x, lastPosition.y] = [event.x, event.y] | |
doScroll = -> | |
sensitivity = 0.5 | |
dx = sensitivity * (lastClick.x - lastPosition.x) | |
dy = sensitivity * (lastClick.y - lastPosition.y) | |
previousScrollLeft = editorComponent.getScrollLeft() | |
previousScrollTop = editorComponent.getScrollTop() | |
updatedScrollLeft = previousScrollLeft - Math.round(dx) | |
updatedScrollTop = previousScrollTop - Math.round(dy) | |
editorComponent.setScrollLeft(updatedScrollLeft) | |
editorComponent.setScrollTop(updatedScrollTop) | |
editorComponent.updateSync() | |
# We prevent regular scrolling on the scroll-container since it interferes with | |
# the scrolling on the editor-component | |
scrollContainer.addEventListener 'scroll', (event) -> | |
if process.platform is 'win32' | |
scrollContainer.scrollTop = 0 | |
scrollContainer.scrollLeft = 0 | |
scrollContainer.addEventListener 'mousedown', (event) -> | |
# click with middle button | |
if event.button is 1 and process.platform is 'win32' | |
[lastClick.x, lastClick.y] = [event.x, event.y] | |
[lastPosition.x, lastPosition.y] = [event.x, event.y] | |
intervalId = setInterval doScroll, 50 | |
onMouseUp = -> | |
clearInterval(intervalId) | |
window.removeEventListener 'mousemove', onMouseMove | |
window.removeEventListener 'mouseup', onMouseUp | |
window.addEventListener 'mousemove', onMouseMove | |
window.addEventListener 'mouseup', onMouseUp | |
init = () -> | |
editorView = atom.views.getView(item) | |
if editorView && editorView.constructor.name == 'atom-text-editor' | |
editorComponent = editorView.component | |
middleMouseScrollSetup(editorComponent) | |
init() |
.platform-win32 atom-text-editor.editor:not(.mini) { | |
div { | |
div.scroll-view { | |
overflow: auto !important; | |
} | |
} | |
.scroll-view::-webkit-scrollbar { | |
display: none; | |
} | |
} |
@mirkea: Sorry, didn't get a notification about the comment here.
Object.observe
was deprecated, and I'm not enough of an Atom/Javascript expert to find an alternative for it at the moment.
Removing it from the script and the functionality of the script will be somewhat impaired when moving tabs around.
Uncaught TypeError: Cannot read property 'addEventListener' of undefined ???
C:\Users\phamd.atom\init.coffee:33
Hide Stack Trace
TypeError: Cannot read property 'addEventListener' of undefined
at middleMouseScrollSetup (file:///C:/Users/phamd/.atom/init.coffee:33:19)
at init (file:///C:/Users/phamd/.atom/init.coffee:54:7)
at file:///C:/Users/phamd/.atom/init.coffee:57:3
at Function.module.exports.Emitter.simpleDispatch (C:\Users\phamd\AppData\Local\atom\app-1.19.2\resources\app\node_modules\event-kit\lib\emitter.js:25:20)
at Emitter.module.exports.Emitter.emit (C:\Users\phamd\AppData\Local\atom\app-1.19.2\resources\app\node_modules\event-kit\lib\emitter.js:141:34)
at C:\Users\phamd\AppData\Local\atom\app-1.19.2\resources\app\src\workspace.js:551:30
This is all acessing private APIs and it broke after a rewrite of TextEditorComponent
. Other things might break, but you should replace {scrollViewNode} = editorComponent
with {scrollContainer} = editorComponent.refs
.
@nathansobo
click with middle button to scroll still not working :((
Atom 1.19.2
I created a package that does this scroll-editor-on-middle-click
I've fixed the Gist to work with the newer Atom versions. Still hacky, so maybe the package linked above will be a better solution.
Hi. I get this error in init.coffee:
Object.observe is not a function
Any idea what might cause it?