Skip to content

Commit

Permalink
Merge pull request #15569 from jpmBBconsult/fix/left-prefix-input-num…
Browse files Browse the repository at this point in the history
…ber-selection

#15293 fixed inputNumber selection lost when selecting left prefix
  • Loading branch information
cetincakiroglu authored May 16, 2024
2 parents 00b443a + 205c204 commit c1f644e
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 c1f644e

Please sign in to comment.