]> git.r.bdr.sh - rbdr/dotfiles/blobdiff - atom/packages/vim-mode/spec/scroll-spec.coffee
Update atoms
[rbdr/dotfiles] / atom / packages / vim-mode / spec / scroll-spec.coffee
index 947319394e13bccb44f6718c6cc1c867f4512996..ebe400ae08847349973ae0fbb3677b186b94e95c 100644 (file)
@@ -11,8 +11,8 @@ describe "Scrolling", ->
       editorElement = element
       editor = editorElement.getModel()
       vimState = editorElement.vimState
-      vimState.activateCommandMode()
-      vimState.resetCommandMode()
+      vimState.activateNormalMode()
+      vimState.resetNormalMode()
 
   keydown = (key, options={}) ->
     options.element ?= editorElement
@@ -120,3 +120,111 @@ describe "Scrolling", ->
         keydown('b')
         expect(editor.setScrollTop).toHaveBeenCalledWith(860)
         expect(editor.moveToFirstCharacterOfLine).not.toHaveBeenCalled()
+
+  describe "horizontal scroll cursor keybindings", ->
+    beforeEach ->
+      editor.setWidth(600)
+      editor.setLineHeightInPixels(10)
+      editor.setDefaultCharWidth(10)
+      text = ""
+      for i in [100..199]
+        text += "#{i} "
+      editor.setText(text)
+      editor.setCursorBufferPosition([0, 0])
+
+    describe "the zs keybinding", ->
+      zsPos = (pos) ->
+        editor.setCursorBufferPosition([0, pos])
+        keydown('z')
+        keydown('s')
+        editor.getScrollLeft()
+
+      startPosition = NaN
+
+      beforeEach ->
+        startPosition = editor.getScrollLeft()
+
+      it "does nothing near the start of the line", ->
+        pos1 = zsPos(1)
+        expect(pos1).toEqual(startPosition)
+
+      it "moves the cursor the nearest it can to the left edge of the editor", ->
+        pos10 = zsPos(10)
+        expect(pos10).toBeGreaterThan(startPosition)
+
+        pos11 = zsPos(11)
+        expect(pos11 - pos10).toEqual(10)
+
+      it "does nothing near the end of the line", ->
+        posEnd = zsPos(399)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 399]
+
+        pos390 = zsPos(390)
+        expect(pos390).toEqual(posEnd)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 390]
+
+        pos340 = zsPos(340)
+        expect(pos340).toBeLessThan(posEnd)
+        pos342 = zsPos(342)
+        expect(pos342 - pos340).toEqual(20)
+
+      it "does nothing if all lines are short", ->
+        editor.setText('short')
+        startPosition = editor.getScrollLeft()
+        pos1 = zsPos(1)
+        expect(pos1).toEqual(startPosition)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 1]
+        pos10 = zsPos(10)
+        expect(pos10).toEqual(startPosition)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 4]
+
+
+    describe "the ze keybinding", ->
+      zePos = (pos) ->
+        editor.setCursorBufferPosition([0, pos])
+        keydown('z')
+        keydown('e')
+        editor.getScrollLeft()
+
+      startPosition = NaN
+
+      beforeEach ->
+        startPosition = editor.getScrollLeft()
+
+      it "does nothing near the start of the line", ->
+        pos1 = zePos(1)
+        expect(pos1).toEqual(startPosition)
+
+        pos40 = zePos(40)
+        expect(pos40).toEqual(startPosition)
+
+      it "moves the cursor the nearest it can to the right edge of the editor", ->
+        pos110 = zePos(110)
+        expect(pos110).toBeGreaterThan(startPosition)
+
+        pos109 = zePos(109)
+        expect(pos110 - pos109).toEqual(10)
+
+      it "does nothing when very near the end of the line", ->
+        posEnd = zePos(399)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 399]
+
+        pos397 = zePos(397)
+        expect(pos397).toEqual(posEnd)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 397]
+
+        pos380 = zePos(380)
+        expect(pos380).toBeLessThan(posEnd)
+
+        pos382 = zePos(382)
+        expect(pos382 - pos380).toEqual(20)
+
+      it "does nothing if all lines are short", ->
+        editor.setText('short')
+        startPosition = editor.getScrollLeft()
+        pos1 = zePos(1)
+        expect(pos1).toEqual(startPosition)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 1]
+        pos10 = zePos(10)
+        expect(pos10).toEqual(startPosition)
+        expect(editor.getCursorBufferPosition()).toEqual [0, 4]