aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/vim-surround/lib/command/delete.coffee
blob: 744b3a1e45898e02dd01eb4c216655ba8b993716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{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)