Bugfixes and improvements
This commit is contained in:
parent
870695102a
commit
089150b88a
@ -1,5 +1,5 @@
|
|||||||
<div #commentInput cdkOverlayOrigin #commentBox="cdkOverlayOrigin" class="comment-box" contenteditable="true"
|
<div #commentInput cdkOverlayOrigin #commentBox="cdkOverlayOrigin" class="comment-box" contenteditable="true"
|
||||||
(input)="handleTextChangedEvent($event)" (keydown)="handleKeyEvent($event)" (focus)="onFocusIn($event)"
|
(input)="handleInputEvent($event)" (keydown)="handleKeyEvent($event)" (focus)="onFocusIn($event)"
|
||||||
(blur)="onFocusOut($event)">
|
(blur)="onFocusOut($event)">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -26,13 +26,14 @@
|
|||||||
offsetX: menuOffsetX,
|
offsetX: menuOffsetX,
|
||||||
offsetY: menuOffsetY - menuOpenAboveYShift
|
offsetY: menuOffsetY - menuOpenAboveYShift
|
||||||
}
|
}
|
||||||
]">
|
]" (overlayOutsideClick)="clickOutsideMenu($event)">
|
||||||
<div class="mat-mdc-menu-panel" #menuContent>
|
<div class="mat-mdc-menu-panel" #menuContent>
|
||||||
<div class="mat-mdc-menu-content">
|
<div class="mat-mdc-menu-content">
|
||||||
@for (item of filteredSelectionList; track item; let index_ = $index) {
|
@for (item of filteredSelectionList; track item; let index_ = $index) {
|
||||||
<div class="mat-mdc-menu-item mat-focus-indicator"
|
<div class="mat-mdc-menu-item mat-focus-indicator"
|
||||||
[class.mat-mdc-menu-item-highlighted]="index_ === selectedDropdownItemIndex"
|
[class.mat-mdc-menu-item-highlighted]="index_ === selectedDropdownItemIndex"
|
||||||
[class.active]="index_ === selectedDropdownItemIndex">{{item}}</div>
|
[class.active]="index_ === selectedDropdownItemIndex" (click)="clickMention(index_)">{{item}}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -117,12 +117,11 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
|
|
||||||
onFocusOut(event: FocusEvent) {
|
onFocusOut(event: FocusEvent) {
|
||||||
if (!this._commentInputRef.nativeElement.contains(event.relatedTarget as Element)) {
|
if (!this._commentInputRef.nativeElement.contains(event.relatedTarget as Element)) {
|
||||||
this.commentText = JSON.stringify(this._commentInputRef.nativeElement.innerHTML);
|
this.commentText = this._commentInputRef.nativeElement.innerHTML;
|
||||||
this.touched = true;
|
this.touched = true;
|
||||||
this.focused = false;
|
this.focused = false;
|
||||||
this.onTouched();
|
this.onTouched();
|
||||||
this.onChange(this.commentText);
|
this.onChange(this.commentText);
|
||||||
this.isOpen = false;
|
|
||||||
this.stateChanges.next();
|
this.stateChanges.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,17 +181,33 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
break;
|
break;
|
||||||
case ENTER || TAB:
|
case ENTER || TAB:
|
||||||
this.addMention(event.target as HTMLInputElement);
|
this.addMention(event.target as HTMLInputElement);
|
||||||
this.handleTextChangedEvent(event, true, 1);
|
this.handleTextChanged(true, 1);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTextChangedEvent(event: any, skipPositionGetting: boolean = false, offset: number = 0) {
|
clickOutsideMenu(event: any) {
|
||||||
event.preventDefault();
|
if (this.isOpen)
|
||||||
|
this.removeFocusedMention(this._commentInputRef.nativeElement as HTMLInputElement);
|
||||||
|
this.isOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
let htmlElement = (event.target as HTMLInputElement);
|
clickMention(selectedIndex: number) {
|
||||||
|
this.selectedDropdownItemIndex = selectedIndex;
|
||||||
|
this.addMention(this._commentInputRef.nativeElement as HTMLInputElement);
|
||||||
|
this.handleTextChanged(true, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
handleInputEvent(event: Event) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.handleTextChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleTextChanged(skipPositionGetting: boolean = false, offset: number = 0) {
|
||||||
|
let htmlElement = this._commentInputRef.nativeElement as HTMLInputElement;
|
||||||
if (!skipPositionGetting)
|
if (!skipPositionGetting)
|
||||||
offset = Cursor.getPosition(htmlElement);
|
offset = Cursor.getPosition(htmlElement);
|
||||||
|
|
||||||
@ -214,6 +229,8 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
// filter menu entries
|
// filter menu entries
|
||||||
let searchQuery = focusedMentionElement.textContent?.substring(1);
|
let searchQuery = focusedMentionElement.textContent?.substring(1);
|
||||||
this.filteredSelectionList = this.mentionListItems.filter((element) => element.toLocaleLowerCase().includes(searchQuery?.toLocaleLowerCase() ?? ""))
|
this.filteredSelectionList = this.mentionListItems.filter((element) => element.toLocaleLowerCase().includes(searchQuery?.toLocaleLowerCase() ?? ""))
|
||||||
|
if (this.selectedDropdownItemIndex > this.filteredSelectionList.length - 1)
|
||||||
|
this.selectedDropdownItemIndex = this.filteredSelectionList.length - 1;
|
||||||
|
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
} else {
|
} else {
|
||||||
@ -253,7 +270,7 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.selectedDropdownItemIndex < this.mentionListItems.length - 1)
|
if (this.selectedDropdownItemIndex < this.filteredSelectionList.length - 1)
|
||||||
this.selectedDropdownItemIndex += 1;
|
this.selectedDropdownItemIndex += 1;
|
||||||
else {
|
else {
|
||||||
this.selectedDropdownItemIndex = 0;
|
this.selectedDropdownItemIndex = 0;
|
||||||
@ -278,7 +295,7 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
if (this.selectedDropdownItemIndex > 0)
|
if (this.selectedDropdownItemIndex > 0)
|
||||||
this.selectedDropdownItemIndex -= 1;
|
this.selectedDropdownItemIndex -= 1;
|
||||||
else {
|
else {
|
||||||
this.selectedDropdownItemIndex = this.mentionListItems.length - 1;
|
this.selectedDropdownItemIndex = this.filteredSelectionList.length - 1;
|
||||||
this._menuContent.nativeElement.scrollTop = listEl.scrollHeight;
|
this._menuContent.nativeElement.scrollTop = listEl.scrollHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,7 +305,7 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
|
|||||||
let focusedElements = element.querySelectorAll(Cursor.focusedClassName);
|
let focusedElements = element.querySelectorAll(Cursor.focusedClassName);
|
||||||
if (focusedMention) {
|
if (focusedMention) {
|
||||||
// set text and remove ignore to style mention
|
// set text and remove ignore to style mention
|
||||||
focusedMention.textContent = `@${this.mentionListItems[this.selectedDropdownItemIndex]}`;
|
focusedMention.textContent = `@${this.filteredSelectionList[this.selectedDropdownItemIndex]}`;
|
||||||
focusedMention.classList.remove(Cursor.focusedClassName);
|
focusedMention.classList.remove(Cursor.focusedClassName);
|
||||||
focusedMention.classList.remove("ignore")
|
focusedMention.classList.remove("ignore")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user