From c6669add052fd4c7db2dd1203e241b4d1f5fc776 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 19 Jan 2022 15:07:00 -0700 Subject: [PATCH] sort lines kvscode command --- projects/kiss-vscode/config/KissConfig.kiss | 2 +- .../kiss-vscode/src/commands/MapLines.kiss | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/projects/kiss-vscode/config/KissConfig.kiss b/projects/kiss-vscode/config/KissConfig.kiss index b6b579b2..0e993d88 100644 --- a/projects/kiss-vscode/config/KissConfig.kiss +++ b/projects/kiss-vscode/config/KissConfig.kiss @@ -225,7 +225,7 @@ (registerCommand "${prefix} [r]eload Config.kiss" tryLoadConfig) // In this file: (registerCommand "${prefix} [q]uickPick and run a command" runCommand) - (registerCommand "${prefix} Re-run [l]ast command" runLastCommand) + (registerCommand "${prefix} Re-run last command" runLastCommand) (registerCommand "${prefix} Run a keyboard [s]hortcut command" runKeyboardShortcut) // KissTools.kiss: (registerCommand "${prefix} [e]valuate and print an expression" evalAndPrint) diff --git a/projects/kiss-vscode/src/commands/MapLines.kiss b/projects/kiss-vscode/src/commands/MapLines.kiss index a849c4c2..63624322 100644 --- a/projects/kiss-vscode/src/commands/MapLines.kiss +++ b/projects/kiss-vscode/src/commands/MapLines.kiss @@ -1,3 +1,4 @@ +// Perform a synchronous transformation on each selected line of text (function _mapLinesSync [selectedText mapFunc] (let [:String->String safeMapFunc ->[line] @@ -18,8 +19,24 @@ (awaitLet [mapFuncStr (inputBox)] (let [:String->String mapFunc (evalString mapFuncStr)] (_mapLinesSync selectedText mapFunc)))) + +// Sort the selected lines of text using a comparison function (String,String) -> Int +(function _sortLinesSync [selectedText :Dynamic compareFunc] + (let [lines (selectedText.split "\n")] + (lines.sort compareFunc) + (.edit activeTextEditor + (lambda [e] + (let [editor activeTextEditor] + (e.delete editor.selection) + (e.insert editor.selection.active (lines.join "\n"))))))) + +(function sortLinesSync [&opt selectedText] + (awaitLet [compareFuncStr (inputBox)] + (_sortLinesSync selectedText (if (< 0 compareFuncStr.length) (evalString compareFuncStr) Reflect.compare)))) + (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 + (registerCommand "${prefix} [L]ines - [M]ap synchronously" mapLinesSync) + (registerCommand "${prefix} [L]ines - [S]ort synchronously" sortLinesSync))) \ No newline at end of file