8000 Indent operations preceded by a number should indent multiple times in visual mode. by mwleeds · Pull Request #798 · atom/vim-mode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Indent operations preceded by a number should indent multiple times in visual mode. #798

Merged
merged 3 commits into from
Aug 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
< 8000 div data-view-component="true" class="js-unified-diff-view-box border rounded-1 pt-3 pb-1 color-border-accent-emphasis">
Diff view
4 changes: 4 additions & 0 deletions docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
* Indent/Outdent/Auto-indent
* `vw>` - works in visual mode
* `>>` - indent current line one level
* `>2>` - repeated linewise
* `v2>` - repeat indent operation in visual mode
* `<<` - outdent current line one level
* `<2<` - repeated linewise
* `v2<` - repeat outdent operation in visual mode
* `==` - auto-indents current line
* [Put](http://vimhelp.appspot.com/change.txt.html#p)
* `p` - default register
Expand Down
7 changes: 6 additions & 1 deletion lib/operators/indent-operators.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_ = require 'underscore-plus'
{Operator} = require './general-operators'

class AdjustIndentation extends Operator
Expand All @@ -6,7 +7,11 @@ class AdjustIndentation extends Operator
@motion.select(count)
{start} = @editor.getSelectedBufferRange()

@indent()
if mode is 'visual'
@editor.transact =>
_.times(count, => @indent())
else
@indent()

@editor.setCursorBufferPosition([start.row, 0])
@editor.moveToFirstCharacterOfLine()
Expand Down
78 changes: 55 additions & 23 deletions spec/operators-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1327,60 +1327,92 @@ describe "Operators", ->
it "outdents all three lines", ->
expect(editor.getText()).toBe "12345\nabcde\nABCDE"

describe "in visual mode", ->
describe "in visual mode linewise", ->
beforeEach ->
editor.setCursorScreenPosition([0, 0])
keydown('v', shift: true)
keydown('>')
keydown('j')

it "indents the current line and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe " 12345\nabcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 2], [0, 2]] ]
describe "single indent multiple lines", ->
beforeEach ->
keydown('>')

it "indents both lines once and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 2], [0, 2]] ]

it "allows repeating the operation", ->
keydown(".")
expect(editor.getText()).toBe " 12345\nabcde\nABCDE"
it "allows repeating the operation", ->
keydown('.')
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"

describe "multiple indent multiple lines", ->
beforeEach ->
keydown('2')
keydown('>')

it "indents both lines twice and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 4], [0, 4]] ]

describe "the < keybinding", ->
beforeEach ->
editor.setText(" 12345\n abcde\nABCDE")
editor.setText(" 12345\n abcde\nABCDE")
editor.setCursorScreenPosition([0, 0])

describe "when followed by a <", ->
beforeEach ->
keydown('<')
keydown('<')

it "indents the current line", ->
expect(editor.getText()).toBe "12345\n abcde\nABCDE"
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
it "outdents the current line", ->
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getCursorScreenPosition()).toEqual [0, 2]

describe "when followed by a repeating <", ->
beforeEach ->
keydown('2')
keydown('<')
keydown('<')

it "indents multiple lines at once", ->
expect(editor.getText()).toBe "12345\nabcde\nABCDE"
expect(editor.getCursorScreenPosition()).toEqual [0, 0]
it "outdents multiple lines at once", ->
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getCursorScreenPosition()).toEqual [0, 2]

describe "undo behavior", ->
beforeEach -> keydown('u')

it "indents both lines", ->
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"

describe "in visual mode", ->
describe "in visual mode linewise", ->
beforeEach ->
keydown('v', shift: true)
keydown('<')
keydown('j')

it "indents the current line and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe "12345\n abcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 0], [0, 0]] ]
describe "single outdent multiple lines", ->
beforeEach ->
keydown('<')

it "outdents the current line and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe " 12345\n abcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 2], [0, 2]] ]

it "allows repeating the operation", ->
keydown('.')
expect(editor.getText()).toBe "12345\nabcde\nABCDE"

describe "multiple outdent multiple lines", ->
beforeEach ->
keydown('2')
keydown('<')

it "outdents both lines twice and exits visual mode", ->
expect(editorElement.classList.contains('normal-mode')).toBe(true)
expect(editor.getText()).toBe "12345\nabcde\nABCDE"
expect(editor.getSelectedBufferRanges()).toEqual [ [[0, 0], [0, 0]] ]

describe "the = keybinding", ->
oldGrammar = []
Expand Down
0