From c6d2d028d966e3ffa0ed9abd21a0a3cd3482a9b5 Mon Sep 17 00:00:00 2001 From: Enzo Mourany Date: Tue, 14 Feb 2023 12:20:49 +0100 Subject: [PATCH 1/2] feat: add comments list --- src/sort.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sort.ts b/src/sort.ts index 2c318a6..c85d73b 100644 --- a/src/sort.ts +++ b/src/sort.ts @@ -23,6 +23,9 @@ export const sortProperties = (): void => { let i: number = 0; let workspaceIndentation = vscode.workspace.getConfiguration('editor').get('tabSize') as number; + + // Comments management + let comments: { line: number, text: string }[] = []; while (i < lines.length) { let line: string = lines[i]; From 7fc661c3fa8a92a1cd2f7ecd79f423148addf5c4 Mon Sep 17 00:00:00 2001 From: Enzo Mourany Date: Sun, 19 Feb 2023 11:31:21 +0100 Subject: [PATCH 2/2] feat: add comments list --- src/sort.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sort.ts b/src/sort.ts index c85d73b..eef10ae 100644 --- a/src/sort.ts +++ b/src/sort.ts @@ -23,9 +23,11 @@ export const sortProperties = (): void => { let i: number = 0; let workspaceIndentation = vscode.workspace.getConfiguration('editor').get('tabSize') as number; - + // Comments management - let comments: { line: number, text: string }[] = []; + let comments: { + includes(arg0: string): unknown; line: number, text: string + }[] = []; while (i < lines.length) { let line: string = lines[i]; @@ -71,11 +73,17 @@ export const sortProperties = (): void => { sortedLines.push(`${selectorIndent}${selector}`); } + // Add the properties to the sortedLines array for (let prop of properties) { if (!prop.endsWith(';')) { prop += ';'; } + let commentIndex = comments.findIndex(c => c.line === i + 1); + if (commentIndex !== -1) { + sortedLines.push(comments[commentIndex].text); + comments.splice(commentIndex, 1); + } sortedLines.push(indentation + prop); } if(lines[i + 1] && lines[i + 1].trim() !== '}') {