Skip to content

Commit

Permalink
Handle asterisk & space output
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukaii committed Apr 11, 2020
1 parent d69370e commit 9bcacef
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions keymap/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
{ keys: 's\'<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\'' } },
{ keys: 's\"<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\"' } },
{ keys: 's\`<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\`' } },
{ keys: 's\*<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\*' } },
{ keys: 's\(<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\(' } },
{ keys: 's\)<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\)' } },
{ keys: 's\{<character>', type: 'action', forceMatch: true, action: 'vimChangeSurround', actionArgs: { search: '\{' } },
Expand Down Expand Up @@ -2833,7 +2834,7 @@
var openCs = ['{', '(', '[']
var mirroredPairs = {'(': ')', ')': '(',
'[': ']', ']': '[',
'\'': true, '"': true, '`': true};
'\'': true, '"': true, '`': true, '*': true};
var multilinePairs = { '{': '}', '}': '{' };

function transformCharacterPair (character) {
Expand Down Expand Up @@ -2866,10 +2867,19 @@

var inner = lineContent.slice(openIndex + 1, closeIndex + cursor.ch)

var addSpace = openCs.includes(replaceCharacter)

var openPos = { ch: openIndex, line: cursor.line }
var closePos = { ch: cursor.ch + closeIndex + 1, line: cursor.line }

cm.replaceRange(replacePair[0] + inner + replacePair[1], openPos, closePos)
var text
if (addSpace) {
text = replacePair[0] + ' ' + inner + ' ' + replacePair[1]
} else {
text = replacePair[0] + inner + replacePair[1]
}

cm.replaceRange(text, openPos, closePos)
}

function replaceMultilineSurround () {
Expand Down

0 comments on commit 9bcacef

Please sign in to comment.