@@ -67,7 +67,7 @@ export default class DataBrowser extends React.Component {
67
67
simplifiedSchema : this . getSimplifiedSchema ( props . schema , props . className )
68
68
} ) ;
69
69
} else if ( Object . keys ( props . columns ) . length !== Object . keys ( this . props . columns ) . length
70
- || ( props . isUnique && props . uniqueField !== this . props . uniqueField ) ) {
70
+ || ( props . isUnique && props . uniqueField !== this . props . uniqueField ) ) {
71
71
const columnPreferences = context . currentApp . columnPreference || { }
72
72
let order = ColumnPreferences . getOrder (
73
73
props . columns ,
@@ -127,7 +127,7 @@ export default class DataBrowser extends React.Component {
127
127
* @param {Number } hoverIndex - index of headerbar moved to left of
128
128
*/
129
129
handleHeaderDragDrop ( dragIndex , hoverIndex ) {
130
- const newOrder = [ ...this . state . order ] ;
130
+ const newOrder = [ ...this . state . order ] ;
131
131
const movedIndex = newOrder . splice ( dragIndex , 1 ) ;
132
132
newOrder . splice ( hoverIndex , 0 , movedIndex [ 0 ] ) ;
133
133
this . setState ( { order : newOrder } , ( ) => {
@@ -154,9 +154,9 @@ export default class DataBrowser extends React.Component {
154
154
}
155
155
return ;
156
156
}
157
- if ( ! this . state . editing && this . props . newObject ) {
157
+ if ( ! this . state . editing && this . props . newObject ) {
158
158
// if user is not editing any row but there's new row
159
- if ( e . keyCode === 27 ) {
159
+ if ( e . keyCode === 27 ) {
160
160
this . props . onAbortAddRow ( ) ;
161
161
e . preventDefault ( ) ;
162
162
}
@@ -176,6 +176,14 @@ export default class DataBrowser extends React.Component {
176
176
if ( ! this . state . current ) {
177
177
return ;
178
178
}
179
+
180
+ const visibleColumnIndexes = [ ] ;
181
+ this . state . order . forEach ( ( column , index ) => {
182
+ column . visible && visibleColumnIndexes . push ( index ) ;
183
+ } )
184
+ const firstVisibleColumnIndex = Math . min ( ...visibleColumnIndexes ) ;
185
+ const lastVisibleColumnIndex = Math . max ( ...visibleColumnIndexes ) ;
186
+
179
187
switch ( e . keyCode ) {
180
188
case 8 :
181
189
case 46 :
@@ -191,37 +199,47 @@ export default class DataBrowser extends React.Component {
191
199
}
192
200
e . preventDefault ( ) ;
193
201
break ;
194
- case 37 : // Left
202
+ case 37 :
203
+ // Left - standalone (move to the next visible column on the left)
204
+ // or with ctrl/meta (excel style - move to the first visible column)
195
205
this . setState ( {
196
206
current : {
197
207
row : this . state . current . row ,
198
- col : Math . max ( this . state . current . col - 1 , 0 )
208
+ col : ( e . ctrlKey || e . metaKey ) ? firstVisibleColumnIndex :
209
+ this . getNextVisibleColumnIndex ( - 1 , firstVisibleColumnIndex , lastVisibleColumnIndex )
199
210
}
200
211
} ) ;
201
212
e . preventDefault ( ) ;
202
213
break ;
203
- case 38 : // Up
214
+ case 38 :
215
+ // Up - standalone (move to the previous row)
216
+ // or with ctrl/meta (excel style - move to the first row)
204
217
this . setState ( {
205
218
current : {
206
- row : Math . max ( this . state . current . row - 1 , 0 ) ,
219
+ row : ( e . ctrlKey || e . metaKey ) ? 0 : Math . max ( this . state . current . row - 1 , 0 ) ,
207
220
col : this . state . current . col
208
221
}
209
222
} ) ;
210
223
e . preventDefault ( ) ;
211
224
break ;
212
- case 39 : // Right
225
+ case 39 :
226
+ // Right - standalone (move to the next visible column on the right)
227
+ // or with ctrl/meta (excel style - move to the last visible column)
213
228
this . setState ( {
214
229
current : {
215
230
row : this . state . current . row ,
216
- col : Math . min ( this . state . current . col + 1 , this . state . order . length - 1 )
231
+ col : ( e . ctrlKey || e . metaKey ) ? lastVisibleColumnIndex :
232
+ this . getNextVisibleColumnIndex ( 1 , firstVisibleColumnIndex , lastVisibleColumnIndex )
217
233
}
218
234
} ) ;
219
235
e . preventDefault ( ) ;
220
236
break ;
221
- case 40 : // Down
237
+ case 40 :
238
+ // Down - standalone (move to the next row)
239
+ // or with ctrl/meta (excel style - move to the last row)
222
240
this . setState ( {
223
241
current : {
224
- row : Math . min ( this . state . current . row + 1 , this . props . data . length - 1 ) ,
242
+ row : ( e . ctrlKey || e . metaKey ) ? this . props . data . length - 1 : Math . min ( this . state . current . row + 1 , this . props . data . length - 1 ) ,
225
243
col : this . state . current . col
226
244
}
227
245
} ) ;
@@ -239,6 +257,17 @@ export default class DataBrowser extends React.Component {
239
257
}
240
258
}
241
259
260
+ getNextVisibleColumnIndex ( distance = 1 , min = 0 , max = 0 ) {
261
+ if ( distance === 0 ) { return this . state . current . col ; }
262
+ let newIndex = this . state . current . col + distance ;
263
+ while ( true ) {
264
+ if ( this . state . order [ newIndex ] ?. visible ) { return newIndex ; }
265
+ if ( newIndex <= min ) { return min ; }
266
+ if ( newIndex >= max ) { return max ; }
267
+ newIndex += distance ;
268
+ }
269
+ }
270
+
242
271
setEditing ( editing ) {
243
272
if ( this . props . updateRow ) {
244
273
if ( this . state . editing !== editing ) {
@@ -264,7 +293,7 @@ export default class DataBrowser extends React.Component {
264
293
}
265
294
266
295
handleColumnsOrder ( order , shouldReload ) {
267
- this . setState ( { order : [ ...order ] } , ( ) => {
296
+ this . setState ( { order : [ ...order ] } , ( ) => {
268
297
this . updatePreferences ( order , shouldReload ) ;
269
298
} ) ;
270
299
}
0 commit comments