fix autosuggest not opening with emoji

This commit is contained in:
Nicolas Constant 2019-10-11 19:59:53 -04:00
parent 4b0924dd3b
commit 24324ddccb
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 18 additions and 11 deletions

View File

@ -224,18 +224,24 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
private detectAutosuggestion(status: string) { private detectAutosuggestion(status: string) {
if (!this.statusLoaded) return; if (!this.statusLoaded) return;
if(!status.includes('@') && !status.includes('#')){
this.autosuggestData = null;
this.hasSuggestions = false;
return;
}
const caretPosition = this.replyElement.nativeElement.selectionStart; const caretPosition = this.replyElement.nativeElement.selectionStart;
const lastChar = status.substr(caretPosition - 1, 1); const lastChar = status.substr(caretPosition - 1, 1);
const lastCharIsSpace = lastChar === ' '; const lastCharIsSpace = lastChar === ' ';
const splitedStatus = status.split(/(\r\n|\n|\r)/); const splitedStatus = status.split(/(\r\n|\n|\r)/);
let offset = 0; let offset = 0;
let currentSection = ''; let currentSection = '';
for(let x of splitedStatus){ for (let x of splitedStatus) {
const sectionLength = [...x].length; const sectionLength = x.length;
if(offset + sectionLength >= caretPosition){ if (offset + sectionLength >= caretPosition) {
currentSection = x; currentSection = x;
break; break;
} else { } else {
@ -248,6 +254,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.autosuggestData = word; this.autosuggestData = word;
return; return;
} }
this.autosuggestData = null; this.autosuggestData = null;
this.hasSuggestions = false; this.hasSuggestions = false;
} }
@ -328,7 +335,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.toolsService.getInstanceInfo(this.selectedAccount) this.toolsService.getInstanceInfo(this.selectedAccount)
.then((instance: InstanceInfo) => { .then((instance: InstanceInfo) => {
if(instance.type === InstanceType.Pixelfed){ if (instance.type === InstanceType.Pixelfed) {
this.instanceSupportsPoll = false; this.instanceSupportsPoll = false;
this.instanceSupportsScheduling = false; this.instanceSupportsScheduling = false;
this.pollIsActive = false; this.pollIsActive = false;
@ -337,7 +344,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.instanceSupportsPoll = true; this.instanceSupportsPoll = true;
this.instanceSupportsScheduling = true; this.instanceSupportsScheduling = true;
} }
}); });
} }
} }
@ -489,9 +496,9 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
} }
let scheduledTime = null; let scheduledTime = null;
if(this.scheduleIsActive){ if (this.scheduleIsActive) {
scheduledTime = this.statusScheduler.getScheduledDate(); scheduledTime = this.statusScheduler.getScheduledDate();
if(!scheduledTime || scheduledTime === '') { if (!scheduledTime || scheduledTime === '') {
this.isSending = false; this.isSending = false;
return; return;
} }
@ -506,7 +513,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
this.status = ''; this.status = '';
this.onClose.emit(); this.onClose.emit();
if(this.scheduleIsActive){ if (this.scheduleIsActive) {
this.scheduledStatusService.statusAdded(acc); this.scheduledStatusService.statusAdded(acc);
} }
}) })