|
1 | | -import * as vscode from "vscode"; |
2 | | -import * as nls from "vscode-nls"; |
3 | | -import { type SortMode, sortStrings } from "../utils/text"; |
4 | | -import { processAndOutput } from "./postProcessHelper"; |
| 1 | +import * as vscode from 'vscode'; |
| 2 | +import * as nls from 'vscode-nls'; |
| 3 | +import { type SortMode, sortStrings } from '../utils/text'; |
| 4 | +import { processAndOutput } from './postProcessHelper'; |
5 | 5 |
|
6 | 6 | const localize = nls.config({ messageFormat: nls.MessageFormat.file })(); |
7 | 7 |
|
8 | 8 | export function registerSortCommand(context: vscode.ExtensionContext): void { |
9 | | - context.subscriptions.push( |
10 | | - vscode.commands.registerCommand( |
11 | | - "string-le.postProcess.sort", |
12 | | - async (): Promise<void> => { |
13 | | - const editor = vscode.window.activeTextEditor; |
14 | | - if (!editor) { |
15 | | - vscode.window.showWarningMessage( |
16 | | - localize("runtime.message.error.no-editor", "No active editor") |
17 | | - ); |
18 | | - return; |
19 | | - } |
20 | | - // Sort modes presented to the user |
21 | | - const items = [ |
22 | | - { |
23 | | - label: localize( |
24 | | - "runtime.sort.option.alpha-asc", |
25 | | - "Alphabetical (A → Z)" |
26 | | - ), |
27 | | - mode: "alpha-asc", |
28 | | - }, |
29 | | - { |
30 | | - label: localize( |
31 | | - "runtime.sort.option.alpha-desc", |
32 | | - "Alphabetical (Z → A)" |
33 | | - ), |
34 | | - mode: "alpha-desc", |
35 | | - }, |
36 | | - { |
37 | | - label: localize( |
38 | | - "runtime.sort.option.length-asc", |
39 | | - "By length (short → long)" |
40 | | - ), |
41 | | - mode: "length-asc", |
42 | | - }, |
43 | | - { |
44 | | - label: localize( |
45 | | - "runtime.sort.option.length-desc", |
46 | | - "By length (long → short)" |
47 | | - ), |
48 | | - mode: "length-desc", |
49 | | - }, |
50 | | - ] as const; |
51 | | - const picked = await vscode.window.showQuickPick( |
52 | | - items.map((i) => i.label), |
53 | | - { |
54 | | - placeHolder: localize( |
55 | | - "runtime.sort.picker.placeholder", |
56 | | - "Choose sort mode" |
57 | | - ), |
58 | | - } |
59 | | - ); |
60 | | - if (!picked) return; |
61 | | - const mode = (items.find((i) => i.label === picked)?.mode ?? |
62 | | - "alpha-asc") as SortMode; |
63 | | - const values = editor.document.getText().split(/\r?\n/); |
64 | | - const processed = sortStrings(values, mode).join("\n"); |
65 | | - const success = await processAndOutput(editor, processed); |
66 | | - if (success) { |
67 | | - vscode.window.showInformationMessage( |
68 | | - localize("runtime.status.postprocess", "Dedupe/sort applied") |
69 | | - ); |
70 | | - } |
71 | | - } |
72 | | - ) |
73 | | - ); |
| 9 | + context.subscriptions.push( |
| 10 | + vscode.commands.registerCommand( |
| 11 | + 'string-le.postProcess.sort', |
| 12 | + async (): Promise<void> => { |
| 13 | + const editor = vscode.window.activeTextEditor; |
| 14 | + if (!editor) { |
| 15 | + vscode.window.showWarningMessage( |
| 16 | + localize('runtime.message.error.no-editor', 'No active editor'), |
| 17 | + ); |
| 18 | + return; |
| 19 | + } |
| 20 | + // Sort modes presented to the user |
| 21 | + const items = [ |
| 22 | + { |
| 23 | + label: localize( |
| 24 | + 'runtime.sort.option.alpha-asc', |
| 25 | + 'Alphabetical (A → Z)', |
| 26 | + ), |
| 27 | + mode: 'alpha-asc', |
| 28 | + }, |
| 29 | + { |
| 30 | + label: localize( |
| 31 | + 'runtime.sort.option.alpha-desc', |
| 32 | + 'Alphabetical (Z → A)', |
| 33 | + ), |
| 34 | + mode: 'alpha-desc', |
| 35 | + }, |
| 36 | + { |
| 37 | + label: localize( |
| 38 | + 'runtime.sort.option.length-asc', |
| 39 | + 'By length (short → long)', |
| 40 | + ), |
| 41 | + mode: 'length-asc', |
| 42 | + }, |
| 43 | + { |
| 44 | + label: localize( |
| 45 | + 'runtime.sort.option.length-desc', |
| 46 | + 'By length (long → short)', |
| 47 | + ), |
| 48 | + mode: 'length-desc', |
| 49 | + }, |
| 50 | + ] as const; |
| 51 | + const picked = await vscode.window.showQuickPick( |
| 52 | + items.map((i) => i.label), |
| 53 | + { |
| 54 | + placeHolder: localize( |
| 55 | + 'runtime.sort.picker.placeholder', |
| 56 | + 'Choose sort mode', |
| 57 | + ), |
| 58 | + }, |
| 59 | + ); |
| 60 | + if (!picked) return; |
| 61 | + const mode = (items.find((i) => i.label === picked)?.mode ?? |
| 62 | + 'alpha-asc') as SortMode; |
| 63 | + const values = editor.document.getText().split(/\r?\n/); |
| 64 | + const processed = sortStrings(values, mode).join('\n'); |
| 65 | + const success = await processAndOutput(editor, processed); |
| 66 | + if (success) { |
| 67 | + vscode.window.showInformationMessage( |
| 68 | + localize('runtime.status.postprocess', 'Dedupe/sort applied'), |
| 69 | + ); |
| 70 | + } |
| 71 | + }, |
| 72 | + ), |
| 73 | + ); |
74 | 74 | } |
0 commit comments