@@ -7,13 +7,15 @@ export interface OptionalGeneralModalConfig {
7
7
allowEmpty ?: boolean ;
8
8
onlySelection ?: boolean ;
9
9
initialValue ?: string ;
10
+ obscure ?: boolean ;
10
11
}
11
12
interface GeneralModalConfig {
12
13
options : string [ ] ;
13
14
placeholder : string ;
14
15
allowEmpty : boolean ;
15
16
onlySelection : boolean ;
16
17
initialValue ?: string ;
18
+ obscure : boolean ;
17
19
}
18
20
19
21
const generalModalConfigDefaults : GeneralModalConfig = {
@@ -22,6 +24,7 @@ const generalModalConfigDefaults: GeneralModalConfig = {
22
24
allowEmpty : false ,
23
25
onlySelection : false ,
24
26
initialValue : undefined ,
27
+ obscure : false ,
25
28
} ;
26
29
27
30
export class GeneralModal extends SuggestModal < string > {
@@ -34,6 +37,29 @@ export class GeneralModal extends SuggestModal<string> {
34
37
super ( plugin . app ) ;
35
38
this . config = { ...generalModalConfigDefaults , ...config } ;
36
39
this . setPlaceholder ( this . config . placeholder ) ;
40
+ if ( this . config . obscure ) {
41
+ this . inputEl . type = "password" ;
42
+ const promptContainer = this . containerEl . querySelector (
43
+ ".prompt-input-container"
44
+ ) ! ;
45
+ promptContainer . addClass ( "git-obscure-prompt" ) ;
46
+ promptContainer . setAttr ( "git-is-obscured" , "true" ) ;
47
+ const obscureSwitchButton = promptContainer ?. createDiv ( {
48
+ cls : "search-input-clear-button" ,
49
+ } ) ;
50
+ obscureSwitchButton . style . marginRight = "32px" ;
51
+ obscureSwitchButton . id = "git-show-password" ;
52
+ obscureSwitchButton . addEventListener ( "click" , ( ) => {
53
+ const isObscured = promptContainer . getAttr ( "git-is-obscured" ) ;
54
+ if ( isObscured === "true" ) {
55
+ this . inputEl . type = "text" ;
56
+ promptContainer . setAttr ( "git-is-obscured" , "false" ) ;
57
+ } else {
58
+ this . inputEl . type = "password" ;
59
+ promptContainer . setAttr ( "git-is-obscured" , "true" ) ;
60
+ }
61
+ } ) ;
62
+ }
37
63
}
38
64
39
65
openAndGetResult ( ) : Promise < string > {
@@ -64,7 +90,11 @@ export class GeneralModal extends SuggestModal<string> {
64
90
}
65
91
66
92
renderSuggestion ( value : string , el : HTMLElement ) : void {
67
- el . setText ( value ) ;
93
+ if ( this . config . obscure ) {
94
+ el . hide ( ) ;
95
+ } else {
96
+ el . setText ( value ) ;
97
+ }
68
98
}
69
99
70
100
onChooseSuggestion ( value : string , _ : MouseEvent | KeyboardEvent ) {
0 commit comments