Skip to content

Commit 5329f4b

Browse files
fix the enter action's cursor positioning when not at the bottom of the text
1 parent f187c47 commit 5329f4b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

code-input.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)