|
9 | 9 | "net/url" |
10 | 10 | "os" |
11 | 11 | "path/filepath" |
| 12 | + "slices" |
12 | 13 | "strconv" |
13 | 14 | "strings" |
14 | 15 |
|
@@ -54,6 +55,8 @@ const ( |
54 | 55 | ACTION_TO_LOWERCASE = "ToLowercase" |
55 | 56 | ACTION_URL_ENCODE = "UrlEncode" |
56 | 57 | ACTION_URL_DECODE = "UrlDecode" |
| 58 | + ACTION_SORT_LINES = "SortLines" |
| 59 | + ACTION_REVERSE_LINES = "ReverseLines" |
57 | 60 | ) |
58 | 61 |
|
59 | 62 | var dinkyActionMapping map[string]func() tview.Primitive |
@@ -95,6 +98,8 @@ func init() { |
95 | 98 | ACTION_TO_LOWERCASE: handleToLowercase, |
96 | 99 | ACTION_URL_ENCODE: handleURLEncode, |
97 | 100 | ACTION_URL_DECODE: handleURLDecode, |
| 101 | + ACTION_SORT_LINES: handleSortLines, |
| 102 | + ACTION_REVERSE_LINES: handleReverseLines, |
98 | 103 | } |
99 | 104 | } |
100 | 105 |
|
@@ -696,3 +701,29 @@ func handleURLDecode() tview.Primitive { |
696 | 701 | }) |
697 | 702 | return nil |
698 | 703 | } |
| 704 | + |
| 705 | +func handleSortLines() tview.Primitive { |
| 706 | + if !currentFileBuffer.editor.Cursor().HasSelection() { |
| 707 | + statusBar.ShowWarning("No text selected") |
| 708 | + return nil |
| 709 | + } |
| 710 | + currentFileBuffer.editor.ActionController().TransformSelection(func(lines []string) []string { |
| 711 | + result := append([]string(nil), lines...) |
| 712 | + slices.Sort(result) |
| 713 | + return result |
| 714 | + }) |
| 715 | + return nil |
| 716 | +} |
| 717 | + |
| 718 | +func handleReverseLines() tview.Primitive { |
| 719 | + if !currentFileBuffer.editor.Cursor().HasSelection() { |
| 720 | + statusBar.ShowWarning("No text selected") |
| 721 | + return nil |
| 722 | + } |
| 723 | + currentFileBuffer.editor.ActionController().TransformSelection(func(lines []string) []string { |
| 724 | + result := append([]string(nil), lines...) |
| 725 | + slices.Reverse(result) |
| 726 | + return result |
| 727 | + }) |
| 728 | + return nil |
| 729 | +} |
0 commit comments