@@ -1020,8 +1020,14 @@ var WidgetCustomizer = ( function ($) {
10201020var widget_content = control . container . find ( '.widget-content' ) ;
10211021
10221022var element_id_to_refocus = null ;
1023+ var active_input_selection_start = null ;
1024+ var active_input_selection_end = null ;
1025+ // @todo Support more selectors than IDs?
10231026if ( $ . contains ( control . container [ 0 ] , document . activeElement ) && $ ( document . activeElement ) . is ( '[id]' ) ) {
10241027element_id_to_refocus = $ ( document . activeElement ) . prop ( 'id' ) ;
1028+ // @todo IE8 support: http://stackoverflow.com/a/4207763/93579
1029+ active_input_selection_start = $ ( document . activeElement ) . prop ( 'selectionStart' ) ;
1030+ active_input_selection_end = $ ( document . activeElement ) . prop ( 'selectionEnd' ) ;
10251031}
10261032
10271033control . container . addClass ( 'widget-form-loading' ) ;
@@ -1092,10 +1098,13 @@ var WidgetCustomizer = ( function ($) {
10921098widget_content . html ( r . data . form ) ;
10931099// @todo yellowfade all widget-inside?
10941100if ( element_id_to_refocus ) {
1095- // @todo Prevent focus() from doing a select()
1096- // @todo try to preserve cursor location after replacing value
10971101// not using jQuery selector so we don't have to worry about escaping IDs with brackets and other characters
1098- $ ( document . getElementById ( element_id_to_refocus ) ) . focus ( ) ;
1102+ $ ( document . getElementById ( element_id_to_refocus ) )
1103+ . prop ( {
1104+ selectionStart : active_input_selection_start ,
1105+ selectionEnd : active_input_selection_end
1106+ } )
1107+ . focus ( ) ;
10991108}
11001109}
11011110
0 commit comments