Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.
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
Diff view
2 changes: 2 additions & 0 deletions keymaps/vim-mode.cson
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
'i (': 'vim-mode:select-inside-parentheses'
'i )': 'vim-mode:select-inside-parentheses'
'i b': 'vim-mode:select-inside-parentheses'
'i p': 'vim-mode:select-inside-paragraph'
'a w': 'vim-mode:select-a-word'
'a "': 'vim-mode:select-around-double-quotes'
'a \'': 'vim-mode:select-around-single-quotes'
Expand All @@ -253,6 +254,7 @@
'a (': 'vim-mode:select-around-parentheses'
'a )': 'vim-mode:select-around-parentheses'
'a b': 'vim-mode:select-around-parentheses'
'a p': 'vim-mode:select-around-paragraph'
'x': 'vim-mode:reset-command-mode'

'atom-text-editor.vim-mode.visual-mode':
Expand Down
11 changes: 10 additions & 1 deletion lib/text-objects.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ class SelectAWord extends TextObject
selection.selectRight()
true

module.exports = {TextObject, SelectInsideWord, SelectInsideQuotes, SelectInsideBrackets, SelectAWord}
class SelectInsideParagraph extends TextObject
constructor: (@editor, @inclusive) ->
select: ->
for selection in @editor.getSelections()
range = selection.cursor.getCurrentParagraphBufferRange()
if range?
selection.setBufferRange(range)
true

module.exports = {TextObject, SelectInsideWord, SelectInsideQuotes, SelectInsideBrackets, SelectAWord, SelectInsideParagraph}
2 changes: 2 additions & 0 deletions lib/vim-state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class VimState
'select-inside-tags': => new TextObjects.SelectInsideBrackets(@editor, '>', '<', false)
'select-inside-square-brackets': => new TextObjects.SelectInsideBrackets(@editor, '[', ']', false)
'select-inside-parentheses': => new TextObjects.SelectInsideBrackets(@editor, '(', ')', false)
'select-inside-paragraph': => new TextObjects.SelectInsideParagraph(@editor, false)
'select-a-word': => new TextObjects.SelectAWord(@editor)
'select-around-double-quotes': => new TextObjects.SelectInsideQuotes(@editor, '"', true)
'select-around-single-quotes': => new TextObjects.SelectInsideQuotes(@editor, '\'', true)
Expand All @@ -148,6 +149,7 @@ class VimState
'select-around-angle-brackets': => new TextObjects.SelectInsideBrackets(@editor, '<', '>', true)
'select-around-square-brackets': => new TextObjects.SelectInsideBrackets(@editor, '[', ']', true)
'select-around-parentheses': => new TextObjects.SelectInsideBrackets(@editor, '(', ')', true)
'select-around-paragraph': => new TextObjects.SelectInsideParagraph(@editor, true)
'register-prefix': (e) => @registerPrefix(e)
'repeat': (e) => new Operators.Repeat(@editor, @)
'repeat-search': (e) => new Motions.RepeatSearch(@editor, @)
Expand Down
25 changes: 25 additions & 0 deletions spec/text-objects-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,31 @@ describe "TextObjects", ->
expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
expect(editorElement.classList.contains('command-mode')).toBe(true)

describe "the 'ip' text object", ->
beforeEach ->
editor.setText("\nParagraph-1\nParagraph-1\nParagraph-1\n\n")
editor.setCursorScreenPosition([2, 2])

it "applies operators inside the current paragraph in operator-pending mode", ->

keydown('y')
keydown('i')
keydown('p')

expect(editor.getText()).toBe "\nParagraph-1\nParagraph-1\nParagraph-1\n\n"
expect(editor.getCursorScreenPosition()).toEqual [1, 0]
expect(vimState.getRegister('"').text).toBe "Paragraph-1\nParagraph-1\nParagraph-1"
expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
expect(editorElement.classList.contains('command-mode')).toBe(true)

it "selects inside the current paragraph in visual mode", ->
keydown('v')
keydown('i')
keydown('p')

expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [3, 11]]


describe "the 'i[' text object", ->
beforeEach ->
editor.setText("[ something in here and in [here] ]")
Expand Down