@@ -91,12 +91,25 @@ export function initRepoEditor() {
91
91
$ ( '#commit-button' ) . text ( $ ( this ) . attr ( 'button_text' ) ) ;
92
92
} ) ;
93
93
94
+ const joinTreePath = ( $fileNameEl ) => {
95
+ const parts = [ ] ;
96
+ $ ( '.breadcrumb span.section' ) . each ( function ( ) {
97
+ const element = $ ( this ) ;
98
+ if ( element . find ( 'a' ) . length ) {
99
+ parts . push ( element . find ( 'a' ) . text ( ) ) ;
100
+ } else {
101
+ parts . push ( element . text ( ) ) ;
102
+ }
103
+ } ) ;
104
+ if ( $fileNameEl . val ( ) ) parts . push ( $fileNameEl . val ( ) ) ;
105
+ $ ( '#tree_path' ) . val ( parts . join ( '/' ) ) ;
106
+ } ;
107
+
94
108
const $editFilename = $ ( '#file-name' ) ;
95
109
$editFilename . on ( 'input' , function ( ) {
96
110
let value ;
97
- let parts ;
111
+ const parts = $ ( this ) . val ( ) . split ( '/' ) ;
98
112
99
- parts = $ ( this ) . val ( ) . split ( '/' ) ;
100
113
if ( parts . length > 1 ) {
101
114
for ( let i = 0 ; i < parts . length ; ++ i ) {
102
115
value = parts [ i ] ;
@@ -111,17 +124,8 @@ export function initRepoEditor() {
111
124
$ ( this ) [ 0 ] . setSelectionRange ( 0 , 0 ) ;
112
125
}
113
126
}
114
- parts = [ ] ;
115
- $ ( '.breadcrumb span.section' ) . each ( function ( ) {
116
- const element = $ ( this ) ;
117
- if ( element . find ( 'a' ) . length ) {
118
- parts . push ( element . find ( 'a' ) . text ( ) ) ;
119
- } else {
120
- parts . push ( element . text ( ) ) ;
121
- }
122
- } ) ;
123
- if ( $ ( this ) . val ( ) ) parts . push ( $ ( this ) . val ( ) ) ;
124
- $ ( '#tree_path' ) . val ( parts . join ( '/' ) ) ;
127
+
128
+ joinTreePath ( $ ( this ) ) ;
125
129
} ) ;
126
130
127
131
$editFilename . on ( 'keyup' , function ( e ) {
@@ -136,6 +140,8 @@ export function initRepoEditor() {
136
140
$section . last ( ) . remove ( ) ;
137
141
$divider . last ( ) . remove ( ) ;
138
142
}
143
+
144
+ joinTreePath ( $ ( this ) ) ;
139
145
} ) ;
140
146
141
147
const $editArea = $ ( '.repository.editor textarea#edit_area' ) ;
0 commit comments