Added more escape characters to surround

This commit is contained in:
Lox 2023-07-07 21:06:04 +02:00 committed by GitHub
parent 9ccf52a590
commit a97be9aa29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

16
main.ts
View file

@ -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));
}
@ -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(/\\(.)/g, function(str, char) { return escapeCodes[char]; }); // Get the beginning surround text
let ending = newArgs[1].replace(/\\(.)/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()};