Skip to content

Commit

Permalink
Merge pull request #4358 from dodona-edu/enhc/send-in-annotation-titl…
Browse files Browse the repository at this point in the history
…e-edit

Allow submitting an annotation with shortcut from title edit field
  • Loading branch information
chvp authored Jan 30, 2023
2 parents 1b26e9f + f0df8a1 commit 29dcb98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/code_listing/code_listing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export class CodeListing {
invalidateSavedAnnotation(e.detail.savedAnnotationId);
annotationForm.remove();
} catch (err) {
annotationForm.hasErrors= true;
annotationForm.disabled= false;
annotationForm.hasErrors = true;
annotationForm.disabled = false;
}
});

Expand Down
17 changes: 12 additions & 5 deletions app/assets/javascripts/components/annotations/annotation_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class AnnotationForm extends watchMixin(ShadowlessLitElement) {
saveAnnotation = false;

inputRef: Ref<HTMLTextAreaElement> = createRef();
titleRef: Ref<HTMLInputElement> = createRef();

watch = {
annotation: () => {
Expand Down Expand Up @@ -134,9 +135,8 @@ export class AnnotationForm extends watchMixin(ShadowlessLitElement) {
}
}

handleUpdateTitle(e: Event): void {
this.savedAnnotationTitle = (e.target as HTMLInputElement).value;
e.stopPropagation();
handleUpdateTitle(): void {
this.savedAnnotationTitle = this.titleRef.value.value;
}

firstUpdated(): void {
Expand Down Expand Up @@ -206,8 +206,15 @@ export class AnnotationForm extends watchMixin(ShadowlessLitElement) {
<label class="form-label" for="saved-annotation-title">
${I18n.t("js.saved_annotation.title")}
</label>
<input required="required" class="form-control" type="text"
@change=${e => this.handleUpdateTitle(e)} value=${this.savedAnnotationTitle} id="saved-annotation-title">
<input required="required"
class="form-control"
type="text"
${ref(this.titleRef)}
@keydown="${e => this.handleKeyDown(e)}"
@input=${() => this.handleUpdateTitle()}
value=${this.savedAnnotationTitle}
id="saved-annotation-title"
>
</div>
` : html``}
`}
Expand Down

0 comments on commit 29dcb98

Please sign in to comment.