Last active
August 19, 2019 06:54
-
-
Save ncreep/a87f127abd962d3cec56 to your computer and use it in GitHub Desktop.
Atom middle mouse scrolling hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.platform-win32 atom-text-editor.editor:not(.mini) { | |
div { | |
div.scroll-view { | |
overflow: auto !important; | |
} | |
} | |
.scroll-view::-webkit-scrollbar { | |
display: none; | |
} | |
} |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nathansobo

click with middle button to scroll still not working :((
Atom 1.19.2