Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,32 @@ InputMask.prototype.backspace = function backspace() {
var selectionBefore = copy(this.selection)
var valueBefore = this.getValue()

// No range selected - work on the character preceding the cursor
if (this.selection.start === this.selection.end) {
if (this.pattern.isEditableIndex(this.selection.start - 1)) {
this.value[this.selection.start - 1] = this.placeholderChar
}
this.selection.start--
this.selection.end--
}
// Range selected - delete characters and leave the cursor at the start of the selection
else {
if (this.selection.start !== this.selection.end) {
var end = this.selection.end - 1
while (end >= this.selection.start) {
while (end > this.selection.start) {
if (this.pattern.isEditableIndex(end)) {
this.value[end] = this.placeholderChar
}
end--
}
this.selection.end = this.selection.start

this.selection.start = this.selection.end = (this.selection.start + 1);
}
// No range selected - work on the character preceding the cursor
if (this.selection.start === this.selection.end) {
var current = this.selection.start - 1;
var deleted = false;
while (current >= this.pattern.firstEditableIndex && (!this.pattern.isEditableIndex(current) || !deleted)) {
if(this.pattern.isEditableIndex(current)){
this.value[current] = this.placeholderChar;
deleted = true;
}

current--;
}

this.selection.start = this.selection.end = current + 1;
}

// History
Expand Down