Don't use config for scrollSensitivity in TextEditorComponent

Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
Max Brunsfeld
2016-07-27 15:35:56 -07:00
committed by Nathan Sobo
parent 4c03cb39de
commit 63a730253b
3 changed files with 9 additions and 32 deletions

View File

@@ -3553,7 +3553,7 @@ describe('TextEditorComponent', function () {
describe('mousewheel events', function () {
beforeEach(function () {
atom.config.set('editor.scrollSensitivity', 100)
editor.setScrollSensitivity(100)
})
describe('updating scrollTop and scrollLeft', function () {
@@ -3586,7 +3586,7 @@ describe('TextEditorComponent', function () {
})
it('updates the scrollLeft or scrollTop according to the scroll sensitivity', async function () {
atom.config.set('editor.scrollSensitivity', 50)
editor.setScrollSensitivity(50)
componentNode.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaX: -5,
wheelDeltaY: -10
@@ -3603,26 +3603,6 @@ describe('TextEditorComponent', function () {
expect(verticalScrollbarNode.scrollTop).toBe(5)
expect(horizontalScrollbarNode.scrollLeft).toBe(7)
})
it('uses the previous scrollSensitivity when the value is not an int', async function () {
atom.config.set('editor.scrollSensitivity', 'nope')
componentNode.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaX: 0,
wheelDeltaY: -10
}))
await nextAnimationFramePromise()
expect(verticalScrollbarNode.scrollTop).toBe(10)
})
it('parses negative scrollSensitivity values at the minimum', async function () {
atom.config.set('editor.scrollSensitivity', -50)
componentNode.dispatchEvent(new WheelEvent('mousewheel', {
wheelDeltaX: 0,
wheelDeltaY: -10
}))
await nextAnimationFramePromise()
expect(verticalScrollbarNode.scrollTop).toBe(1)
})
})
describe('when the mousewheel event\'s target is a line', function () {

View File

@@ -18,7 +18,6 @@ LineTopIndex = require 'line-top-index'
module.exports =
class TextEditorComponent
scrollSensitivity: 0.4
cursorBlinkPeriod: 800
cursorBlinkResumeDelay: 100
tileSize: 12
@@ -47,8 +46,6 @@ class TextEditorComponent
@tileSize = tileSize if tileSize?
@disposables = new CompositeDisposable
@setScrollSensitivity(@config.get('editor.scrollSensitivity'))
lineTopIndex = new LineTopIndex({
defaultLineHeight: @editor.getLineHeightInPixels()
})
@@ -340,7 +337,6 @@ class TextEditorComponent
@disposables.add(@scopedConfigDisposables)
scope = @editor.getRootScopeDescriptor()
@scopedConfigDisposables.add @config.observe 'editor.scrollSensitivity', {scope}, @setScrollSensitivity
focused: ->
if @mounted
@@ -408,7 +404,7 @@ class TextEditorComponent
if Math.abs(wheelDeltaX) > Math.abs(wheelDeltaY)
# Scrolling horizontally
previousScrollLeft = @presenter.getScrollLeft()
updatedScrollLeft = previousScrollLeft - Math.round(wheelDeltaX * @scrollSensitivity)
updatedScrollLeft = previousScrollLeft - Math.round(wheelDeltaX * @editor.getScrollSensitivity() / 100)
event.preventDefault() if @presenter.canScrollLeftTo(updatedScrollLeft)
@presenter.setScrollLeft(updatedScrollLeft)
@@ -416,7 +412,7 @@ class TextEditorComponent
# Scrolling vertically
@presenter.setMouseWheelScreenRow(@screenRowForNode(event.target))
previousScrollTop = @presenter.getScrollTop()
updatedScrollTop = previousScrollTop - Math.round(wheelDeltaY * @scrollSensitivity)
updatedScrollTop = previousScrollTop - Math.round(wheelDeltaY * @editor.getScrollSensitivity() / 100)
event.preventDefault() if @presenter.canScrollTopTo(updatedScrollTop)
@presenter.setScrollTop(updatedScrollTop)
@@ -926,10 +922,6 @@ class TextEditorComponent
@linesYardstick.invalidateCache()
@presenter.measurementsChanged()
setScrollSensitivity: (scrollSensitivity) =>
if scrollSensitivity = parseInt(scrollSensitivity)
@scrollSensitivity = Math.abs(scrollSensitivity) / 100
screenPositionForMouseEvent: (event, linesClientRect) ->
pixelPosition = @pixelPositionForMouseEvent(event, linesClientRect)
@screenPositionForPixelPosition(pixelPosition)

View File

@@ -80,6 +80,7 @@ class TextEditor extends Model
atomicSoftTabs: true
invisibles: null
showLineNumbers: true
scrollSensitivity: 40
Object.defineProperty @prototype, "element",
get: -> @getElement()
@@ -3359,6 +3360,10 @@ class TextEditor extends Model
getScrollPastEnd: -> @scrollPastEnd
setScrollSensitivity: (@scrollSensitivity) ->
getScrollSensitivity: -> @scrollSensitivity
setShowLineNumbers: (showLineNumbers) ->
if showLineNumbers isnt @showLineNumbers
@showLineNumbers = showLineNumbers