Skip to content

Pressing backspace leaves cursor in the wrong position #7

@John-Hird

Description

@John-Hird

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);
		}
		
	},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions