@@ -27,27 +27,28 @@ import { TabsUtilService } from './tabs-util.service';
27
27
export class DomUtilService {
28
28
29
29
private editableSelector = '.value-container input, div[contenteditable=true]' ;
30
+ // highlight class is defined in json-editor.component.scss
31
+ private highlightClass = 'highlight' ;
32
+ private highlightedElement : HTMLElement ;
30
33
31
34
constructor ( public tabsUtilService : TabsUtilService ) { }
32
35
33
- focusAndSelectFirstEditableChildById ( id : string ) {
36
+ focusAndSelectFirstEditableChildById ( id : string , highlight = false ) {
34
37
this . tabsUtilService . selectTabIfNeeded ( id ) ;
35
38
setTimeout ( ( ) => {
36
39
let el = document . getElementById ( id ) ;
37
40
if ( el ) {
38
- let firstInput = el . querySelector ( this . editableSelector ) as HTMLElement ;
39
- if ( firstInput ) {
40
- firstInput . focus ( ) ;
41
- this . selectAllContent ( firstInput ) ;
41
+ let firstEditable = el . querySelector ( this . editableSelector ) as HTMLElement ;
42
+ if ( firstEditable ) {
43
+ firstEditable . focus ( ) ;
44
+ this . selectAllContent ( firstEditable ) ;
45
+ if ( highlight ) {
46
+ firstEditable . classList . add ( this . highlightClass ) ;
47
+ this . highlightedElement = firstEditable ;
48
+ }
42
49
} else {
43
50
// if element doesn't have any input, open add-field-dropdown if it exists.
44
- firstInput = el . querySelector ( 'div.btn-group' ) as HTMLInputElement ;
45
- if ( firstInput ) {
46
- let dropDownButton = el . querySelector ( 'div.btn-group button' ) as HTMLButtonElement ;
47
- if ( dropDownButton ) {
48
- dropDownButton . click ( ) ;
49
- }
50
- }
51
+ this . openDropdown ( el ) ;
51
52
}
52
53
}
53
54
} ) ;
@@ -80,25 +81,18 @@ export class DomUtilService {
80
81
}
81
82
}
82
83
83
- flashElementById ( id : string ) {
84
- this . tabsUtilService . selectTabIfNeeded ( id ) ;
85
- setTimeout ( ( ) => {
86
- let el = document . getElementById ( id ) ;
87
- if ( el ) {
88
- // .flash is defined json-editor.component.scss, {border: 2px solid yellow;}
89
- el . classList . add ( 'flash' ) ;
90
- setTimeout ( ( ) => {
91
- el . classList . remove ( 'flash' ) ;
92
- } , 500 ) ;
93
- }
94
- } ) ;
95
- }
96
-
97
84
blurFirstEditableChildById ( id : string ) {
98
85
let el = document . getElementById ( id ) ;
99
- let firstInput = el . querySelector ( this . editableSelector ) as HTMLElement ;
100
- if ( firstInput ) {
101
- firstInput . blur ( ) ;
86
+ let firstEditable = el . querySelector ( this . editableSelector ) as HTMLElement ;
87
+ if ( firstEditable ) {
88
+ firstEditable . blur ( ) ;
89
+ }
90
+ }
91
+
92
+ clearHighlight ( ) {
93
+ if ( this . highlightedElement ) {
94
+ this . highlightedElement . classList . remove ( this . highlightClass ) ;
95
+ this . highlightedElement = undefined ;
102
96
}
103
97
}
104
98
@@ -115,4 +109,14 @@ export class DomUtilService {
115
109
}
116
110
}
117
111
112
+ private openDropdown ( el : HTMLElement ) {
113
+ let dropdown = el . querySelector ( 'div.btn-group' ) ;
114
+ if ( dropdown ) {
115
+ let dropDownButton = dropdown . querySelector ( 'button' ) as HTMLButtonElement ;
116
+ if ( dropDownButton ) {
117
+ dropDownButton . click ( ) ;
118
+ }
119
+ }
120
+ }
121
+
118
122
}
0 commit comments