diff --git a/projects/kiss-vscode/src/commands/MapLines.kiss b/projects/kiss-vscode/src/commands/MapLines.kiss new file mode 100644 index 00000000..a849c4c2 --- /dev/null +++ b/projects/kiss-vscode/src/commands/MapLines.kiss @@ -0,0 +1,25 @@ +(function _mapLinesSync [selectedText mapFunc] + (let [:String->String safeMapFunc + ->[line] + (ifLet [trimmedLine (StringTools.trim line)] (try (mapFunc trimmedLine) (catch [e] (Std.string e))) "") + mappedText + (.join + (map + (.split selectedText "\n") + safeMapFunc) + "\n")] + (.edit activeTextEditor + (lambda [e] + (let [editor activeTextEditor] + (e.delete editor.selection) + (e.insert editor.selection.active mappedText)))))) + +(function mapLinesSync [&opt selectedText] + (awaitLet [mapFuncStr (inputBox)] + (let [:String->String mapFunc (evalString mapFuncStr)] + (_mapLinesSync selectedText mapFunc)))) + +(function :Void registerMapLinesCommands [&opt leaderKeys] + (unless leaderKeys (set leaderKeys "")) + (let [prefix "Kiss-VSCode:$(if leaderKeys " [${leaderKeys}]" "")"] + (registerCommand "${prefix} [M]ap lines synchronously" mapLinesSync))) \ No newline at end of file