Skip to content

Commit

Permalink
Recognize users cursor's highlighted text
Browse files Browse the repository at this point in the history
The first step to the bootleg Google Docs commenting system is
recognizing when an abstract's text is highlighted, and what text in
particular. Using the web api `Window.getSelection()`, in the way that
was suggested by Dasari Srinivas, one can highlight text and have it
show up elsewhere.

Right now, highlighted text is in a tentative spot in the comment div
as a single comment that is not stored in any way, nor even tied to the
`comment` field of `Submissions`.

Issue #147 (Create comment object)
Epic #131 (Submission Card View)
  • Loading branch information
michael-small committed Nov 30, 2019
1 parent 77b5263 commit bb7eb13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/src/app/submissionView/submissionView.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1>{{submission.presentationTitle}}</h1>

<div class="abstract">
<h1>Abstract</h1>
<p>{{submission.abstractContent}}</p>
<p (mouseup)="highlightAbstractToCommentOn()">{{submission.abstractContent}}</p>
</div>

<div>
Expand All @@ -78,6 +78,8 @@ <h2>Comments</h2>
<mat-icon>edit</mat-icon> New Comment [W]
</button>

<p *ngIf="selectedText" class="debug-comment">"{{selectedText}}"</p>

<div class="comment" *ngIf="submission.comments">{{submission.comments}}</div>
</div>

Expand Down
5 changes: 5 additions & 0 deletions client/src/app/submissionView/submissionView.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
background-color: cadetblue;
}

.debug-comment { //for debugging
border: 1px solid black;
padding: 0.2rem;
}

// buttons
.button-container {
border: 1px solid red; //for debugging
Expand Down
12 changes: 12 additions & 0 deletions client/src/app/submissionView/submissionView.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ export class SubmissionViewComponent implements OnInit {
);
}

// Dasari Srinivas, Tuesday, 11 October 2016, "Get the Highlighted/Selected text using Angular 2"
// http://blog.sodhanalibrary.com/2016/10/get-highlightedselected-text-using.html
selectedText: string = '';
highlightAbstractToCommentOn() {
let text = "";
if (window.getSelection) {
text = window.getSelection().toString();
}
this.selectedText = text;
console.log(text);
}

ngOnInit() {
this.getSubmission();
}
Expand Down

0 comments on commit bb7eb13

Please sign in to comment.