Skip to content

Commit 5160b87

Browse files
Merge pull request #125 from zenn-dev/canary
release 0.4.0
2 parents 027350e + 3429307 commit 5160b87

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

package.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "https://github.com/zenn-dev/zenn-vscode-extension.git"
1111
},
1212
"license": "MIT",
13-
"version": "0.3.0",
13+
"version": "0.4.0",
1414
"pricing": "Free",
1515
"engines": {
1616
"vscode": "^1.72.0"
@@ -192,6 +192,19 @@
192192
"default": 50,
193193
"minimum": 5,
194194
"markdownDescription": "プレビューパネルに表示されるタブタイトルを指定した文字数で切り詰めます。"
195+
},
196+
"zenn-preview.sortArticle": {
197+
"type": "string",
198+
"default": null,
199+
"enum": [
200+
null,
201+
"title"
202+
],
203+
"enumDescriptions": [
204+
"ファイルパスの昇順で表示",
205+
"タイトルの昇順で表示"
206+
],
207+
"markdownDescription": "記事の並び順を設定します。"
195208
}
196209
}
197210
}

src/treeview/previewTreeItem.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import naturalCompare from "natural-compare-lite";
21
import * as vscode from "vscode";
32

43
import { AppContext } from "../context/app";
54
import { ContentError } from "../schemas/error";
65
import { Contents, ContentsType } from "../types";
6+
import { EMOJI_REGEX } from "../utils/patterns";
77

88
/** TreeItem の `contextValue` に設定できる値 */
99
export type TreeItemType = ContentsType | "error" | "none";
@@ -64,6 +64,43 @@ export abstract class PreviewTreeItem extends vscode.TreeItem {
6464
* TreeItemをソートする
6565
*/
6666
static sortTreeItems(items: PreviewTreeItem[]): PreviewTreeItem[] {
67-
return items.sort((a, b) => naturalCompare(a.path, b.path));
67+
// 設定からソート順を取得
68+
const sortArticle = vscode.workspace
69+
.getConfiguration("zenn-preview")
70+
.get<string | null>("sortArticle");
71+
72+
return items.sort((a, b) => {
73+
// 記事タイトルでソート
74+
if (sortArticle === "title") {
75+
const getCleanLabel = (item: PreviewTreeItem): string => {
76+
const labelProp = item.label;
77+
let labelStr = "";
78+
if (typeof labelProp === "string") {
79+
labelStr = labelProp;
80+
} else if (labelProp && typeof labelProp.label === "string") {
81+
labelStr = labelProp.label;
82+
}
83+
return labelStr.replace(EMOJI_REGEX, "").trim();
84+
};
85+
86+
const aCleanLabel = getCleanLabel(a);
87+
const bCleanLabel = getCleanLabel(b);
88+
89+
if (aCleanLabel || bCleanLabel) {
90+
// どちらかに絵文字除去後ラベルがあれば比較
91+
return aCleanLabel.localeCompare(bCleanLabel, "ja", {
92+
sensitivity: "base",
93+
});
94+
}
95+
96+
// 絵文字除去後ラベルが両方空の場合はpathで比較 (元々ラベルがなかった場合など)
97+
return a.path.localeCompare(b.path, "ja", { sensitivity: "base" });
98+
}
99+
100+
// ファイルパスでソート
101+
else {
102+
return a.path.localeCompare(b.path, "ja", { sensitivity: "base" });
103+
}
104+
});
68105
}
69106
}

0 commit comments

Comments
 (0)