diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d26ecf..9ba0462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## version 2.19.7 + +- 随机一题可以指定 tag 分类 + ## version 2.19.6 - 获取题目错误,则不生成文件 diff --git a/package.json b/package.json index 4296acb..20296e4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-leetcode-problem-rating", "displayName": "LeetCode", "description": "%main.description%", - "version": "2.19.6", + "version": "2.19.7", "author": "ccagml", "publisher": "ccagml", "license": "MIT", @@ -76,7 +76,8 @@ { "command": "lcpr.pickOne", "title": "%main.contributes.commands.lcpr.pickOne.title%", - "category": "LeetCode" + "category": "LeetCode", + "icon": "$(compass)" }, { "command": "lcpr.deleteAllCache", @@ -372,17 +373,17 @@ { "command": "lcpr.pickOne", "when": "view == QuestionExplorer", - "group": "overflow@0" + "group": "navigation@4" }, { "command": "lcpr.problems.sort", "when": "view == QuestionExplorer", - "group": "overflow@1" + "group": "overflow@0" }, { "command": "lcpr.deleteAllCache", "when": "view == QuestionExplorer", - "group": "overflow@2" + "group": "overflow@1" }, { "command": "lcpr.newBrickGroup", diff --git a/src/controller/TreeViewController.ts b/src/controller/TreeViewController.ts index 3f6ef6c..1f9bc99 100644 --- a/src/controller/TreeViewController.ts +++ b/src/controller/TreeViewController.ts @@ -74,6 +74,7 @@ import { fileButtonService } from "../service/FileButtonService"; import * as fse from "fs-extra"; import { submissionService } from "../service/SubmissionService"; import { bricksDataService } from "../service/BricksDataService"; +import { groupDao } from "../dao/groupDao"; // 视图控制器 class TreeViewController implements Disposable { @@ -665,6 +666,45 @@ class TreeViewController implements Disposable { } public async pickOne(): Promise { + const picks: Array> = []; + + let last_pick = await groupDao.getPickOneTags(); + + let last_tag_set: Set = new Set(); + last_pick.forEach((tag_name) => { + last_tag_set.add(tag_name); + }); + + for (const tag of this.tagSet.values()) { + let pick_item: IQuickItemEx = { + label: tag, + detail: "", + value: tag, + }; + if (last_tag_set.has(tag)) { + pick_item.picked = true; + } + + picks.push(pick_item); + } + + const choice: Array> | undefined = await window.showQuickPick(picks, { + title: "指定Tag类型", + matchOnDescription: false, + matchOnDetail: false, + placeHolder: "指定Tag类型", + canPickMany: true, + }); + if (!choice) { + return; + } + + // 写入选择 + let cur_tag_set: Set = new Set(); + choice.forEach((element) => { + cur_tag_set.add(element.value); + }); + const problems: IProblem[] = await this.getAllProblems(); let randomProblem: IProblem; @@ -678,7 +718,11 @@ class TreeViewController implements Disposable { problems.forEach((element) => { if (element.scoreData?.Rating) { if (element.scoreData.Rating >= need_min && element.scoreData.Rating <= need_max) { - temp_problems.push(element); + for (const q_tag of element.tags) { + if (cur_tag_set.has(q_tag)) { + temp_problems.push(element); + } + } } } }); @@ -689,6 +733,13 @@ class TreeViewController implements Disposable { if (randomProblem) { await this.showProblemInternal(randomProblem); } + + // 写入 + let new_pick_one_tags: Array = []; + for (const new_tag of cur_tag_set) { + new_pick_one_tags.push(new_tag); + } + await groupDao.setPickOneTags(new_pick_one_tags); } public async showProblemInternal(node: IProblem): Promise { diff --git a/src/dao/groupDao.ts b/src/dao/groupDao.ts index 2da65ed..5fc3c79 100644 --- a/src/dao/groupDao.ts +++ b/src/dao/groupDao.ts @@ -135,6 +135,17 @@ class GroupDao { old_data.all_group = all_group; this._write_data(old_data); } + + public async getPickOneTags() { + let old_data = await this._read_data(); + let pick_one_tags = old_data.pick_one_tags || []; + return pick_one_tags; + } + public async setPickOneTags(new_pick_one_tags) { + let old_data = await this._read_data(); + old_data.pick_one_tags = new_pick_one_tags; + this._write_data(old_data); + } } export const groupDao: GroupDao = new GroupDao();