diff options
Diffstat (limited to 'atom/packages/vim-surround/lib/command')
5 files changed, 0 insertions, 208 deletions
diff --git a/atom/packages/vim-surround/lib/command/base.coffee b/atom/packages/vim-surround/lib/command/base.coffee deleted file mode 100644 index b40e644..0000000 --- a/atom/packages/vim-surround/lib/command/base.coffee +++ /dev/null @@ -1,59 +0,0 @@ -{CompositeDisposable} = require 'atom' - -module.exports = class Base - - constructor: (config) -> - @disposables = new CompositeDisposable - - @curPairs = [] - @registerPairs config.pairs - - registerPairs: (pairs) -> - pairs = (x for x in pairs when x.length > 0 and x.length %2 == 0) - - for pair in pairs - if pair not in @curPairs - @registerPair pair - @curPairs.push(pair) - - registerPair: (pair) -> - [left, right] = @splitPair(pair) - - if left != right - @createPairBindings left, "#{left} ", " #{right}" - @createPairBindings right, left, right - - createPairBindings: (key, left, right) -> - name = "vim-surround:#{@getName key}" - - # First, we add a command to the system to actually perform the surround. - # We attach the disposable to our object's list. - @disposables.add atom.commands.add @context, name, @getRunner left, right - - # Next, we build up keybindings for our command. First, we build a - # space-delineated version of our key that's passed in. This breaks up - # double keys like `{%` into the seperate keystroke form: `{ %` - keys = "" - for i in [0..key.length-1] - if i == 0 - keys = key[i] - else - keys = "#{keys} #{key[i]}" - - # Making a one-command keymap data structure here. Basically: - # "atom-text-editor.vim-mode.visual-mode": - # "s (": - # "vim-surround:surround-(" - - keymapArg = {} - fullCommand = "#{@command} #{keys}" - keymapArg[fullCommand] = name - - contextArg = {} - contextArg[@context] = keymapArg - - # Capture the disposable heretom test! - @disposables.add atom.keymaps.add name, contextArg - - splitPair: (pair) -> - return [pair[..(pair.length/2)-1], pair[pair.length/2..]] diff --git a/atom/packages/vim-surround/lib/command/change.coffee b/atom/packages/vim-surround/lib/command/change.coffee deleted file mode 100644 index 7bdf623..0000000 --- a/atom/packages/vim-surround/lib/command/change.coffee +++ /dev/null @@ -1,74 +0,0 @@ -{CompositeDisposable} = require 'atom' - -Base = require './base' -Selector = require './selector' - -module.exports = class Change - constructor: (config) -> - @command = config.changeSurroundCommand - @context = "atom-text-editor.vim-mode.normal-mode" - @disposables = new CompositeDisposable - @curPairs = [] - @curPairsWithTarget = [] - @registerPairs config.pairs - - getName: (key, targetKey) -> "change-#{key}-to-#{targetKey}" - - registerPairs: (pairs) -> - pairs = (x for x in pairs when x.length > 0 and x.length %2 == 0) - - for pair in pairs - for target in pairs - if "#{pair}#{target}" not in @curPairs - @registerPair pair, target - @curPairs.push("#{pair}#{target}") - - registerPair: (pair, target) -> - [left, right] = @splitPair(pair) - [target_left, target_right] = @splitPair(target) - - for key in [left, right] - for targetKey in [target_left, target_right] - if "#{key}#{targetKey}" not in @curPairsWithTarget - name = "vim-surround:#{@getName(key, targetKey)}" - - unless pair == target - @disposables.add atom.commands.add @context, name, @getRunner pair, target - - keymapArg = {} - fullCommand = "#{@command} #{key} #{targetKey}" - keymapArg[fullCommand] = name - - contextArg = {} - contextArg[@context] = keymapArg - - # Capture the disposable heretom test! - unless pair == target - @disposables.add atom.keymaps.add name, contextArg - @curPairsWithTarget.push("#{key}#{targetKey}") - - splitPair: (pair) -> - return [pair[..(pair.length/2)-1], pair[pair.length/2..]] - - getRunner: (from, to) -> -> - [left, right] = [from[0], from[1]] - [target_left, target_right] = [to[0], to[1]] - editor = atom.workspace.getActiveTextEditor() - selector = new Selector(editor, left, right) - - editor.transact -> - cursorPos = editor.getCursorBufferPosition() - - selector.inside().select() - editor.selections.forEach (selection) -> - text = selection.getText() - - # restore cursore and select text with surrounding keys - editor.setCursorBufferPosition(cursorPos) - selector.outside().select() - - editor.selections.forEach (selection) -> - selection.insertText "#{target_left}#{text}#{target_right}" - - # restore cursore - editor.setCursorBufferPosition(cursorPos) diff --git a/atom/packages/vim-surround/lib/command/delete.coffee b/atom/packages/vim-surround/lib/command/delete.coffee deleted file mode 100644 index 744b3a1..0000000 --- a/atom/packages/vim-surround/lib/command/delete.coffee +++ /dev/null @@ -1,33 +0,0 @@ -{compositedisposable} = require 'atom' - -Base = require './base' -Selector = require './selector' - -module.exports = class Delete extends Base - constructor: (config) -> - @command = config.deleteSurroundCommand - @context = "atom-text-editor.vim-mode.normal-mode" - super config - - getName: (key) -> "delete-#{key}" - - getRunner: (left, right) -> -> - editor = atom.workspace.getActiveTextEditor() - selector = new Selector(editor, left, right) - - editor.transact -> - cursorPos = editor.getCursorBufferPosition() - - selector.inside().select() - editor.selections.forEach (selection) -> - text = selection.getText() - - # restore cursore and select text with surrounding keys - editor.setCursorBufferPosition(cursorPos) - selector.outside().select() - - editor.selections.forEach (selection) -> - selection.insertText text - - # restore cursore - editor.setCursorBufferPosition(cursorPos) diff --git a/atom/packages/vim-surround/lib/command/selector.coffee b/atom/packages/vim-surround/lib/command/selector.coffee deleted file mode 100644 index bcb3c15..0000000 --- a/atom/packages/vim-surround/lib/command/selector.coffee +++ /dev/null @@ -1,24 +0,0 @@ -vimModePath = atom.packages.resolvePackagePath('vim-mode') or - atom.packages.resolvePackagePath('vim-mode-next') - -{SelectInsideQuotes, SelectInsideBrackets} = require "#{vimModePath}/lib/text-objects" - -module.exports = class Selector - constructor: (@editor, left, right) -> - @left = left.trim() - @right = right.trim() - - inside: -> - if @isBraket() - new SelectInsideBrackets(@editor, @left, @right, false) - else - new SelectInsideQuotes(@editor, @left, false) - - outside: -> - if @isBraket() - new SelectInsideBrackets(@editor, @left, @right, true) - else - new SelectInsideQuotes(@editor, @left, true) - - isBraket: -> - ['[', ']', '{', '}', '<', '>', '(', ')'].indexOf?(@left.trim()) >= 0 diff --git a/atom/packages/vim-surround/lib/command/surround.coffee b/atom/packages/vim-surround/lib/command/surround.coffee deleted file mode 100644 index e939f78..0000000 --- a/atom/packages/vim-surround/lib/command/surround.coffee +++ /dev/null @@ -1,18 +0,0 @@ -{CompositeDisposable} = require 'atom' - -Base = require './base' - -module.exports = class Surround extends Base - constructor: (config) -> - @command = config.surroundCommand - @context = "atom-text-editor.vim-mode.visual-mode" - super config - - getName: (key) -> "surround-#{key}" - - getRunner: (left, right) -> -> - editor = atom.workspace.getActiveTextEditor() - editor.transact -> - editor.selections.forEach (selection) -> - text = selection.getText() - selection.insertText "#{left}#{text}#{right}" |