Skip to content
Open
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
16 changes: 14 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ const mappingCommands: String[] = [
"vunmap",
]


const escapeCodes: { [key: string]: string } = {
'\\': '\\',
'r': '\r',
'n': '\n',
't': '\t',
's': ' ',
'b': '\b',
'&': '\&',
' ': ' '
};

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down Expand Up @@ -443,8 +455,8 @@ export default class VimrcPlugin extends Plugin {
throw new Error("surround requires exactly 2 parameters: prefix and postfix text.");
}

let beginning = newArgs[0].replace("\\\\", "\\").replace("\\ ", " "); // Get the beginning surround text
let ending = newArgs[1].replace("\\\\", "\\").replace("\\ ", " "); // Get the ending surround text
let beginning = newArgs[0].replace(/\\([\\rntsb &])/g, function(str, char) { return escapeCodes[char]; }); // Get the beginning surround text
let ending = newArgs[1].replace(/\\([\\rntsb &])/g, function(str, char) { return escapeCodes[char]; }); // Get the ending surround text

let currentSelections = this.currentSelection;
var chosenSelection = currentSelections?.[0] ? currentSelections[0] : {anchor: editor.getCursor(), head: editor.getCursor()};
Expand Down