Pressing backspace leaves cursor in the wrong position
Opened this issue · 4 comments
If you type for example: "ABCDEFG" then press the backspace button, then type "1" you shojudl end up with: "ABCDEF1" but you actually end up with "1ABCDEF" as the cursor has moved to the start of the text.
Also if I type "ABCDE" and move the cursor between the C and the D and then press backspace I would expect to see "ABD" bu instead I get "ABC" as it always deletes the last character.
I am not sure if suggesting code changes in an issue is correct, so apologies if it isn't but I changed the backspace function in the code to the following and it appears to have fixed both issues for me:
backspace: function () {
var input = this.settings.input,
input_node = input.get(0),
start = input_node.selectionStart,
val = input.val();
if (start > 0) {
input.val(val.substring(0, start - 1) + val.substring(start));
input.trigger('focus');
input_node.setSelectionRange(start - 1, start - 1);
}
else {
input.trigger('focus');
input_node.setSelectionRange(0, 0);
}
},
Thank you for this. This code worked perfectly for me to fix this bug. This change should be reflected on the master branch!
@John-Hird Thanks for code, If you send merge request I'll add it to code
Thank you @John-Hird for this fix! Although I think it still isn't merged into master branch.
I just noticed the same issue with this and the above code fixed it perfectly! Please merge into master! 👍