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

Commit2adaa43

Browse files
authored
feat: Customize the shortcuts in editor (LeetCode-OpenSource#340)
1 parent41b3d32 commit2adaa43

File tree

4 files changed

+64
-14
lines changed

4 files changed

+64
-14
lines changed

‎package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,25 @@
331331
"type":"boolean",
332332
"default":true,
333333
"scope":"application",
334-
"description":"Show the submit and test shortcuts in editor or not."
334+
"description":"[Deprecated] Show the submit and test shortcuts in editor or not."
335+
},
336+
"leetcode.editor.shortcuts": {
337+
"type":"array",
338+
"default": [
339+
"submit",
340+
"test"
341+
],
342+
"scope":"application",
343+
"items": {
344+
"type":"string",
345+
"enum": [
346+
"submit",
347+
"test",
348+
"solution",
349+
"description"
350+
]
351+
},
352+
"description":"Customize the shorcuts in editor."
335353
},
336354
"leetcode.enableSideMode": {
337355
"type":"boolean",

‎src/codelens/CodeLensController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class CodeLensController implements Disposable {
1515
this.configurationChangeListener=workspace.onDidChangeConfiguration((event:ConfigurationChangeEvent)=>{
1616
if(event.affectsConfiguration("leetcode.enableShortcuts")){
1717
this.setCodeLensVisibility();
18+
}elseif(event.affectsConfiguration("leetcode.editor.shortcuts")){
19+
this.internalProvider.refresh();
1820
}
1921
},this);
2022

‎src/codelens/CustomCodeLensProvider.ts

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

44
import*asvscodefrom"vscode";
5+
import{getEditorShortcuts}from"../utils/settingUtils";
56

67
exportclassCustomCodeLensProviderimplementsvscode.CodeLensProvider{
78

8-
privatevalidFileNamePattern:RegExp=/\d+\..*\.(.+)/;
9+
privateonDidChangeCodeLensesEmitter:vscode.EventEmitter<void>=newvscode.EventEmitter<void>();
10+
11+
getonDidChangeCodeLenses():vscode.Event<void>{
12+
returnthis.onDidChangeCodeLensesEmitter.event;
13+
}
14+
15+
publicrefresh():void{
16+
this.onDidChangeCodeLensesEmitter.fire();
17+
}
918

1019
publicprovideCodeLenses(document:vscode.TextDocument):vscode.ProviderResult<vscode.CodeLens[]>{
20+
constshortcuts:string[]=getEditorShortcuts();
21+
if(!shortcuts){
22+
return;
23+
}
24+
1125
constfileName:string=document.fileName.trim();
12-
constmatchResult:RegExpMatchArray|null=fileName.match(this.validFileNamePattern);
26+
constmatchResult:RegExpMatchArray|null=fileName.match(/\d+\..*\.(.+)/);
1327
if(!matchResult){
1428
returnundefined;
1529
}
1630

1731
constrange:vscode.Range=newvscode.Range(document.lineCount-1,0,document.lineCount-1,0);
32+
constcodeLens:vscode.CodeLens[]=[];
1833

19-
return[
20-
newvscode.CodeLens(range,{
34+
if(shortcuts.indexOf("submit")>=0){
35+
codeLens.push(newvscode.CodeLens(range,{
2136
title:"Submit",
2237
command:"leetcode.submitSolution",
2338
arguments:[document.uri],
24-
}),
25-
newvscode.CodeLens(range,{
39+
}));
40+
}
41+
42+
if(shortcuts.indexOf("test")>=0){
43+
codeLens.push(newvscode.CodeLens(range,{
2644
title:"Test",
2745
command:"leetcode.testSolution",
2846
arguments:[document.uri],
29-
}),
30-
newvscode.CodeLens(range,{
47+
}));
48+
}
49+
50+
if(shortcuts.indexOf("solution")>=0){
51+
codeLens.push(newvscode.CodeLens(range,{
3152
title:"Solution",
3253
command:"leetcode.showSolution",
3354
arguments:[document.uri],
34-
}),
35-
newvscode.CodeLens(range,{
36-
title:"Preview",
55+
}));
56+
}
57+
58+
if(shortcuts.indexOf("description")>=0){
59+
codeLens.push(newvscode.CodeLens(range,{
60+
title:"Description",
3761
command:"leetcode.previewProblem",
3862
arguments:[document.uri],
39-
}),
40-
];
63+
}));
64+
}
65+
66+
returncodeLens;
4167
}
4268
}

‎src/utils/settingUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ export function getWorkspaceConfiguration(): WorkspaceConfiguration {
1010
exportfunctionshouldHideSolvedProblem():boolean{
1111
returngetWorkspaceConfiguration().get<boolean>("hideSolved",false);
1212
}
13+
14+
exportfunctiongetEditorShortcuts():string[]{
15+
returngetWorkspaceConfiguration().get<string[]>("editor.shortcuts",["submit","test"]);
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp