Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #553 from atom/wl-tab-scrolling
Browse files Browse the repository at this point in the history
Make tab scrolling settings work
  • Loading branch information
50Wliu committed Jan 11, 2019
2 parents 405006e + 524dd73 commit b39c2b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
23 changes: 9 additions & 14 deletions lib/tab-bar-view.coffee
Expand Up @@ -55,6 +55,7 @@ class TabBarView

@element.addEventListener "mouseenter", @onMouseEnter.bind(this)
@element.addEventListener "mouseleave", @onMouseLeave.bind(this)
@element.addEventListener "mousewheel", @onMouseWheel.bind(this)
@element.addEventListener "dragstart", @onDragStart.bind(this)
@element.addEventListener "dragend", @onDragEnd.bind(this)
@element.addEventListener "dragleave", @onDragLeave.bind(this)
Expand All @@ -79,9 +80,9 @@ class TabBarView
@subscriptions.add @pane.onDidChangeActiveItem (item) =>
@updateActiveTab()

@subscriptions.add atom.config.observe 'tabs.tabScrolling', @updateTabScrolling.bind(this)
@subscriptions.add atom.config.observe 'tabs.tabScrollingThreshold', => @updateTabScrollingThreshold()
@subscriptions.add atom.config.observe 'tabs.alwaysShowTabBar', => @updateTabBarVisibility()
@subscriptions.add atom.config.observe 'tabs.tabScrolling', (value) => @updateTabScrolling(value)
@subscriptions.add atom.config.observe 'tabs.tabScrollingThreshold', (value) => @updateTabScrollingThreshold(value)
@subscriptions.add atom.config.observe 'tabs.alwaysShowTabBar', (value) => @updateTabBarVisibility(value)

@updateActiveTab()

Expand Down Expand Up @@ -147,8 +148,8 @@ class TabBarView
tab.updateTitle() for tab in @getTabs()
@updateTabBarVisibility()

updateTabBarVisibility: ->
if not atom.config.get('tabs.alwaysShowTabBar') and not @shouldAllowDrag()
updateTabBarVisibility: (value) ->
if not value and not @shouldAllowDrag()
@element.classList.add('hidden')
else
@element.classList.remove('hidden')
Expand Down Expand Up @@ -389,7 +390,7 @@ class TabBarView
atom.focus()

onMouseWheel: (event) ->
return if event.shiftKey
return if event.shiftKey or not @tabScrolling

@wheelDelta ?= 0
@wheelDelta += event.wheelDeltaY
Expand Down Expand Up @@ -437,20 +438,14 @@ class TabBarView
atom.commands.dispatch(@element, 'application:new-file')
event.preventDefault()

updateTabScrollingThreshold: ->
@tabScrollingThreshold = atom.config.get('tabs.tabScrollingThreshold')
updateTabScrollingThreshold: (value) ->
@tabScrollingThreshold = value

updateTabScrolling: (value) ->
if value is 'platform'
@tabScrolling = (process.platform is 'linux')
else
@tabScrolling = value
@tabScrollingThreshold = atom.config.get('tabs.tabScrollingThreshold')

if @tabScrolling
@element.addEventListener 'mousewheel', @onMouseWheel.bind(this)
else
@element.removeEventListener 'mousewheel', @onMouseWheel.bind(this)

browserWindowForId: (id) ->
BrowserWindow ?= require('electron').remote.BrowserWindow
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -37,7 +37,7 @@
"description": "Show the tab bar even when only one tab is open."
},
"tabScrolling": {
"type": "any",
"type": ["boolean", "string"],
"enum": [
true,
false,
Expand Down
8 changes: 8 additions & 0 deletions spec/tabs-spec.coffee
Expand Up @@ -1167,6 +1167,14 @@ describe "TabBarView", ->
tabBar.element.dispatchEvent(buildWheelPlusShiftEvent(-120))
expect(pane.getActiveItem()).toBe item2

describe "when the tabScrolling is changed to false", ->
it "does not change the active tab when scrolling", ->
atom.config.set("tabs.tabScrolling", false)

expect(pane.getActiveItem()).toBe item2
tabBar.element.dispatchEvent(buildWheelEvent(120))
expect(pane.getActiveItem()).toBe item2

describe "when tabScrolling is false in package settings", ->
beforeEach ->
atom.config.set("tabs.tabScrolling", false)
Expand Down

0 comments on commit b39c2b2

Please sign in to comment.