Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitade48fb

Browse files
authored
add: star command in shortcuts (LeetCode-OpenSource#601)
1 parent7bc6d6c commitade48fb

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

‎README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
9090
<imgsrc="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/shortcuts.png"alt="Editor Shortcuts" />
9191
</p>
9292

93-
- The extension supports4 editor shortcuts (aka Code Lens):
93+
- The extension supports5 editor shortcuts (aka Code Lens):
9494
-`Submit`: Submit your answer to LeetCode.
9595
-`Test`: Test your answer with customized test cases.
96+
-`Star/Unstar`: Star or unstar the current problem.
9697
-`Solution`: Show the top voted solution for the current problem.
9798
-`Description`: Show the problem description page.
9899

@@ -128,7 +129,7 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
128129
|`leetcode.workspaceFolder`| Specify the path of the workspace folder to store the problem files.|`""`|
129130
|`leetcode.filePath`| Specify the relative path under the workspace and the file name to save the problem files. More details can be found[here](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/Customize-the-Relative-Folder-and-the-File-Name-of-the-Problem-File).||
130131
|`leetcode.enableStatusBar`| Specify whether the LeetCode status bar will be shown or not.|`true`|
131-
|`leetcode.editor.shortcuts`| Specify the customized shorcuts in editors. Supported values are:`submit`,`test`,`solution` and`description`.|`["submit, test"]`|
132+
|`leetcode.editor.shortcuts`| Specify the customized shorcuts in editors. Supported values are:`submit`,`test`,`star`,`solution` and`description`.|`["submit, test"]`|
132133
|`leetcode.enableSideMode`| Specify whether`preview`,`solution` and`submission` tab should be grouped into the second editor column when solving a problem.|`true`|
133134
|`leetcode.nodePath`| Specify the`Node.js` executable path. for example, C:\Program Files\nodejs\node.exe|`node`|
134135
|`leetcode.showCommentDescription`| Specify whether to include the problem description in the comments|`false`|

‎docs/README_zh-CN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@
9191
<imgsrc="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/shortcuts.png"alt="Editor Shortcuts" />
9292
</p>
9393

94-
-插件会在编辑区域内支持四种不同的快捷方式(Code Lens):
94+
-插件会在编辑区域内支持五种不同的快捷方式(Code Lens):
9595
-`Submit`: 提交你的答案至 LeetCode;
9696
-`Test`: 用给定的测试用例测试你的答案;
97+
-`Star`: 收藏或取消收藏该问题;
9798
-`Solution`: 显示该问题的高票解答;
9899
-`Description`: 显示该问题的题目描述。
99100

@@ -129,7 +130,7 @@
129130
|`leetcode.workspaceFolder`| 指定保存文件的工作区目录|`""`|
130131
|`leetcode.filePath`| 指定生成题目文件的相对文件夹路径名和文件名。点击查看[更多详细用法](https://github.com/LeetCode-OpenSource/vscode-leetcode/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%98%E7%9B%AE%E6%96%87%E4%BB%B6%E7%9A%84%E7%9B%B8%E5%AF%B9%E6%96%87%E4%BB%B6%E5%A4%B9%E8%B7%AF%E5%BE%84%E5%92%8C%E6%96%87%E4%BB%B6%E5%90%8D)||
131132
|`leetcode.enableStatusBar`| 指定是否在 VS Code 下方显示插件状态栏。|`true`|
132-
|`leetcode.editor.shortcuts`| 指定在编辑器内所自定义的快捷方式。可用的快捷方式有:`submit`,`test`,`solution`,`description`|`["submit, test"]`|
133+
|`leetcode.editor.shortcuts`| 指定在编辑器内所自定义的快捷方式。可用的快捷方式有:`submit`,`test`,`star`,`solution`,`description`|`["submit, test"]`|
133134
|`leetcode.enableSideMode`| 指定在解决一道题时,是否将`问题预览``高票答案``提交结果`窗口集中在编辑器的第二栏。|`true`|
134135
|`leetcode.nodePath`| 指定`Node.js` 可执行文件的路径。如:C:\Program Files\nodejs\node.exe|`node`|
135136
|`leetcode.showCommentDescription`| 指定是否要在注释中显示题干。|`false`|

‎package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,16 @@
629629
"enum": [
630630
"submit",
631631
"test",
632+
"star",
632633
"solution",
633634
"description"
635+
],
636+
"enumDescriptions": [
637+
"Submit your answer to LeetCode.",
638+
"Test your answer with customized test cases.",
639+
"Star or unstar the current problem.",
640+
"Show the top voted solution for the current problem.",
641+
"Show the problem description page."
634642
]
635643
},
636644
"description":"Customize the shorcuts in editors."

‎src/codelens/CodeLensController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Licensed under the MIT license.
33

44
import{ConfigurationChangeEvent,Disposable,languages,workspace}from"vscode";
5-
import{CustomCodeLensProvider}from"./CustomCodeLensProvider";
5+
import{customCodeLensProvider,CustomCodeLensProvider}from"./CustomCodeLensProvider";
66

77
classCodeLensControllerimplementsDisposable{
88
privateinternalProvider:CustomCodeLensProvider;
99
privateregisteredProvider:Disposable|undefined;
1010
privateconfigurationChangeListener:Disposable;
1111

1212
constructor(){
13-
this.internalProvider=newCustomCodeLensProvider();
13+
this.internalProvider=customCodeLensProvider;
1414

1515
this.configurationChangeListener=workspace.onDidChangeConfiguration((event:ConfigurationChangeEvent)=>{
1616
if(event.affectsConfiguration("leetcode.editor.shortcuts")){

‎src/codelens/CustomCodeLensProvider.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license.
33

44
import*asvscodefrom"vscode";
5+
import{explorerNodeManager}from"../explorer/explorerNodeManager";
6+
import{LeetCodeNode}from"../explorer/LeetCodeNode";
57
import{getEditorShortcuts}from"../utils/settingUtils";
68

79
exportclassCustomCodeLensProviderimplementsvscode.CodeLensProvider{
@@ -23,10 +25,15 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
2325
}
2426

2527
constcontent:string=document.getText();
26-
constmatchResult:RegExpMatchArray|null=content.match(/@lcapp=.*id=.*lang=.*/);
28+
constmatchResult:RegExpMatchArray|null=content.match(/@lcapp=.*id=(.*)lang=.*/);
2729
if(!matchResult){
2830
returnundefined;
2931
}
32+
constnodeId:string|undefined=matchResult[1];
33+
letnode:LeetCodeNode|undefined;
34+
if(nodeId){
35+
node=explorerNodeManager.getNodeById(nodeId);
36+
}
3037

3138
letcodeLensLine:number=document.lineCount-1;
3239
for(leti:number=document.lineCount-1;i>=0;i--){
@@ -56,6 +63,14 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
5663
}));
5764
}
5865

66+
if(shortcuts.indexOf("star")>=0&&node){
67+
codeLens.push(newvscode.CodeLens(range,{
68+
title:node.isFavorite ?"Unstar" :"Star",
69+
command:node.isFavorite ?"leetcode.removeFavorite" :"leetcode.addFavorite",
70+
arguments:[node],
71+
}));
72+
}
73+
5974
if(shortcuts.indexOf("solution")>=0){
6075
codeLens.push(newvscode.CodeLens(range,{
6176
title:"Solution",
@@ -75,3 +90,5 @@ export class CustomCodeLensProvider implements vscode.CodeLensProvider {
7590
returncodeLens;
7691
}
7792
}
93+
94+
exportconstcustomCodeLensProvider:CustomCodeLensProvider=newCustomCodeLensProvider();

‎src/commands/star.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
// Copyright (c) jdneo. All rights reserved.
33
// Licensed under the MIT license.
44

5+
import{customCodeLensProvider}from"../codelens/CustomCodeLensProvider";
56
import{LeetCodeNode}from"../explorer/LeetCodeNode";
67
import{leetCodeTreeDataProvider}from"../explorer/LeetCodeTreeDataProvider";
78
import{leetCodeExecutor}from"../leetCodeExecutor";
9+
import{hasStarShortcut}from"../utils/settingUtils";
810
import{DialogType,promptForOpenOutputChannel}from"../utils/uiUtils";
911

1012
exportasyncfunctionaddFavorite(node:LeetCodeNode):Promise<void>{
1113
try{
1214
awaitleetCodeExecutor.toggleFavorite(node,true);
13-
leetCodeTreeDataProvider.refresh();
15+
awaitleetCodeTreeDataProvider.refresh();
16+
if(hasStarShortcut()){
17+
customCodeLensProvider.refresh();
18+
}
1419
}catch(error){
1520
awaitpromptForOpenOutputChannel("Failed to add the problem to favorite. Please open the output channel for details.",DialogType.error);
1621
}
@@ -19,7 +24,10 @@ export async function addFavorite(node: LeetCodeNode): Promise<void> {
1924
exportasyncfunctionremoveFavorite(node:LeetCodeNode):Promise<void>{
2025
try{
2126
awaitleetCodeExecutor.toggleFavorite(node,false);
22-
leetCodeTreeDataProvider.refresh();
27+
awaitleetCodeTreeDataProvider.refresh();
28+
if(hasStarShortcut()){
29+
customCodeLensProvider.refresh();
30+
}
2331
}catch(error){
2432
awaitpromptForOpenOutputChannel("Failed to remove the problem from favorite. Please open the output channel for details.",DialogType.error);
2533
}

‎src/utils/settingUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export function getEditorShortcuts(): string[] {
2020
returngetWorkspaceConfiguration().get<string[]>("editor.shortcuts",["submit","test"]);
2121
}
2222

23+
exportfunctionhasStarShortcut():boolean{
24+
constshortcuts:string[]=getWorkspaceConfiguration().get<string[]>("editor.shortcuts",["submit","test"]);
25+
returnshortcuts.indexOf("star")>=0;
26+
}
27+
2328
exportfunctiongetDescriptionConfiguration():IDescriptionConfiguration{
2429
constsetting:string=getWorkspaceConfiguration().get<string>("showDescription",DescriptionConfiguration.InWebView);
2530
constconfig:IDescriptionConfiguration={

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp