Skip to content

Commit

Permalink
#15293 fixed inputNumber selection lost when selecting left prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmBBconsult committed May 15, 2024
1 parent 4154d61 commit 205c204
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,14 +1181,23 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control

initCursor() {
let selectionStart = this.input?.nativeElement.selectionStart;
let selectionEnd = this.input?.nativeElement.selectionEnd;
let inputValue = this.input?.nativeElement.value;
let valueLength = inputValue.length;
let index = null;

// remove prefix
let prefixLength = (this.prefixChar || '').length;
inputValue = inputValue.replace(this._prefix, '');
selectionStart = selectionStart - prefixLength;

// Will allow selecting whole prefix. But not a part of it.
// Negative values will trigger clauses after this to fix the cursor position.
if (selectionStart === selectionEnd
|| selectionStart !== 0
|| selectionEnd < prefixLength)
{
selectionStart -= prefixLength;
}

let char = inputValue.charAt(selectionStart);
if (this.isNumeralChar(char)) {
Expand Down

0 comments on commit 205c204

Please sign in to comment.