sort lines kvscode command
This commit is contained in:
@@ -225,7 +225,7 @@
|
|||||||
(registerCommand "${prefix} [r]eload Config.kiss" tryLoadConfig)
|
(registerCommand "${prefix} [r]eload Config.kiss" tryLoadConfig)
|
||||||
// In this file:
|
// In this file:
|
||||||
(registerCommand "${prefix} [q]uickPick and run a command" runCommand)
|
(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)
|
(registerCommand "${prefix} Run a keyboard [s]hortcut command" runKeyboardShortcut)
|
||||||
// KissTools.kiss:
|
// KissTools.kiss:
|
||||||
(registerCommand "${prefix} [e]valuate and print an expression" evalAndPrint)
|
(registerCommand "${prefix} [e]valuate and print an expression" evalAndPrint)
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
// Perform a synchronous transformation on each selected line of text
|
||||||
(function _mapLinesSync [selectedText mapFunc]
|
(function _mapLinesSync [selectedText mapFunc]
|
||||||
(let [:String->String safeMapFunc
|
(let [:String->String safeMapFunc
|
||||||
->[line]
|
->[line]
|
||||||
@@ -18,8 +19,24 @@
|
|||||||
(awaitLet [mapFuncStr (inputBox)]
|
(awaitLet [mapFuncStr (inputBox)]
|
||||||
(let [:String->String mapFunc (evalString mapFuncStr)]
|
(let [:String->String mapFunc (evalString mapFuncStr)]
|
||||||
(_mapLinesSync selectedText mapFunc))))
|
(_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]
|
(function :Void registerMapLinesCommands [&opt leaderKeys]
|
||||||
(unless leaderKeys (set leaderKeys ""))
|
(unless leaderKeys (set leaderKeys ""))
|
||||||
(let [prefix "Kiss-VSCode:$(if leaderKeys " [${leaderKeys}]" "")"]
|
(let [prefix "Kiss-VSCode:$(if leaderKeys " [${leaderKeys}]" "")"]
|
||||||
(registerCommand "${prefix} [M]ap lines synchronously" mapLinesSync)))
|
(registerCommand "${prefix} [L]ines - [M]ap synchronously" mapLinesSync)
|
||||||
|
(registerCommand "${prefix} [L]ines - [S]ort synchronously" sortLinesSync)))
|
Reference in New Issue
Block a user