place emoji under the current caret position

This commit is contained in:
Nicolas Constant 2019-07-27 21:17:38 -04:00
parent 9b7f60c0e2
commit 4ed3483b81
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 14 additions and 7 deletions

View File

@ -50,6 +50,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
if (value) {
this.countStatusChar(value);
this.detectAutosuggestion(value);
this._status = value;
setTimeout(() => {
@ -629,9 +630,12 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
private emojiCloseSub: Subscription;
private emojiSelectedSub: Subscription;
private beforeEmojiCaretPosition: number;
openEmojiPicker(e: MouseEvent): boolean {
if (this.overlayRef) return false;
this.beforeEmojiCaretPosition = this.replyElement.nativeElement.selectionStart;
let topPosition = e.pageY;
if (this.innerHeight - e.pageY < 360) {
topPosition -= 360;
@ -653,23 +657,26 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
let comp = new ComponentPortal(EmojiPickerComponent);
const compRef: ComponentRef<EmojiPickerComponent> = this.overlayRef.attach(comp);
this.emojiCloseSub = compRef.instance.closedEvent.subscribe(() => {
this.closeEEmojiPanel();
this.closeEmojiPanel();
});
this.emojiSelectedSub = compRef.instance.emojiSelectedEvent.subscribe((emoji) => {
if (emoji) {
this.status += ` ${emoji}`;
this.closeEEmojiPanel();
this.status = [this.status.slice(0, this.beforeEmojiCaretPosition), emoji, ' ', this.status.slice(this.beforeEmojiCaretPosition)].join('').replace(' ', ' ');
this.beforeEmojiCaretPosition += emoji.length + 1;
this.closeEmojiPanel();
}
});
return false;
}
private closeEEmojiPanel() {
if(this.emojiCloseSub) this.emojiCloseSub.unsubscribe();
if(this.emojiSelectedSub) this.emojiSelectedSub.unsubscribe();
if(this.overlayRef) this.overlayRef.dispose();
private closeEmojiPanel() {
if (this.emojiCloseSub) this.emojiCloseSub.unsubscribe();
if (this.emojiSelectedSub) this.emojiSelectedSub.unsubscribe();
if (this.overlayRef) this.overlayRef.dispose();
this.overlayRef = null;
this.focus(this.beforeEmojiCaretPosition);
}
closeEmoji(): boolean {