File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -142,13 +142,17 @@ var codeInput = {
142142 }
143143 new_line += text_after_cursor ;
144144
145+ // save the current cursor position
146+ let selection_start = input_element . selectionStart ;
147+ let selection_end = input_element . selectionEnd ;
148+
145149 // splice our new line into the list of existing lines and join them all back up
146150 lines . splice ( current_line + 1 , 0 , new_line ) ;
147151 input_element . value = lines . join ( "\n" ) ;
148152
149153 // move cursor to new position
150- input_element . selectionStart += number_indents + 1 ; // count the indent level and the newline character
151- input_element . selectionEnd += number_indents + 1 ;
154+ input_element . selectionStart = selection_start + number_indents + 1 ; // count the indent level and the newline character
155+ input_element . selectionEnd = selection_end + number_indents + 1 ;
152156
153157 this . update ( input_element . value ) ;
154158 }
You can’t perform that action at this time.
0 commit comments