Commit 6f9849b3 authored by Simone Vuotto's avatar Simone Vuotto

Add caret position in requirement textarea.

parent cd33edbd
......@@ -12,7 +12,10 @@
<div class="modal-body">
<div class="form-group">
<label for="reqTextarea">Requirement</label>
<textarea class="form-control" id="reqTextarea" rows="2" [(ngModel)]="requirement.text"></textarea>
<textarea class="form-control" id="reqTextarea" rows="2"
#reqTextarea (click)="getCaretPos(reqTextarea)" (keyup)="getCaretPos(reqTextarea)"
[(ngModel)]="requirement.text" ></textarea>
<p class="small pull-right">line {{caretPos[0]}}:{{caretPos[1]}}</p>
</div>
<div class="form-group">
......
......@@ -18,6 +18,8 @@ export class RequirementDetailsComponent implements OnInit {
loading = false;
caretPos = [1, 1];
constructor(private requirementService: RequirementService,
private alertService: AlertService) { }
......@@ -49,4 +51,19 @@ export class RequirementDetailsComponent implements OnInit {
);
}
getCaretPos(oField) {
if (!isNaN(oField.selectionStart)) {
let i = this.requirement.text.indexOf('\n', 0);
let j = 0;
let row = 1;
while (i >= 0 && i < oField.selectionStart) {
j = i + 1;
i = this.requirement.text.indexOf('\n', i + 1);
++row;
}
this.caretPos[0] = row;
this.caretPos[1] = oField.selectionStart - j;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment