From c5c7351db395be60de2d56f7df68d305d5acd338 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 12 Nov 2024 19:09:35 -0600 Subject: [PATCH] sort lines by EOL --- package.json | 10 +++++++++- src/Main.hx | 1 + src/commands/Lines.kiss | 10 ++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4baccde4..3942151a 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "key": "Ctrl+; Ctrl+m" }, { - "command": "kiss-vscode.sortLinesSync", + "command": "kiss-vscode.sortLinesSyncDefault", "mac": "Cmd+; Cmd+s", "key": "Ctrl+; Ctrl+s" } @@ -102,6 +102,14 @@ { "title": "kiss-vscode: Sort the selected text lines using a (String,String)->Int comparator function", "command": "kiss-vscode.sortLinesSync" + }, + { + "title": "kiss-vscode: Sort the selected lines lexicographically", + "command": "kiss-vscode.sortLinesSyncDefault" + }, + { + "title": "kiss-vscode: Sort the selected lines lexicographically from the end of each line", + "command": "kiss-vscode.sortLinesSyncEOL" } ], "languages": [ diff --git a/src/Main.hx b/src/Main.hx index 772efb5e..99406c57 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -12,6 +12,7 @@ import re_flex.R; using haxe.io.Path; using StringTools; using uuid.Uuid; +using hx.strings.Strings; @:build(kiss.Kiss.build()) class Main {} diff --git a/src/commands/Lines.kiss b/src/commands/Lines.kiss index 4c42870b..b95de819 100644 --- a/src/commands/Lines.kiss +++ b/src/commands/Lines.kiss @@ -30,6 +30,12 @@ (e.delete editor.selection) (e.insert editor.selection.active (lines.join "\n"))))))) -(defCommand context sortLinesSync "Sort the selected text lines using a (String,String)->Int comparator function" "C-; C-s" [] +(defCommand context sortLinesSync "Sort the selected text lines using a (String,String)->Int comparator function" "" [] (awaitLet [compareFuncStr (inputEditor "sortLinesFunc.kiss" "a (String,String) -> Int function with which to sort the selected lines")] - (_sortLinesSync (selectedText) (if (< 0 compareFuncStr.length) (evalString compareFuncStr) Reflect.compare)))) \ No newline at end of file + (_sortLinesSync (selectedText) (if (< 0 compareFuncStr.length) (evalString compareFuncStr) Reflect.compare)))) + +(defCommand context sortLinesSyncDefault "Sort the selected lines lexicographically" "C-; C-s" [] + (_sortLinesSync (selectedText) Reflect.compare)) + +(defCommand context sortLinesSyncEOL "Sort the selected lines lexicographically from the end of each line" "" [] + (_sortLinesSync (selectedText) ->[:String s1 :String s2] (Reflect.compare (s1.reverse) (s2.reverse)))) \ No newline at end of file