Add showContentCompleted for improved semantic clarity

This commit is contained in:
toasted-nutbread 2019-12-11 21:31:21 -05:00
parent 99867ebdd8
commit f287d68624
2 changed files with 9 additions and 5 deletions

View File

@ -166,7 +166,7 @@ class SettingsPopupPreview {
source.cleanup(); source.cleanup();
} }
this.textSource = source; this.textSource = source;
await this.frontend.lastShowPromise; await this.frontend.showContentCompleted();
if (this.frontend.popup.isVisible()) { if (this.frontend.popup.isVisible()) {
this.popupShown = true; this.popupShown = true;

View File

@ -37,7 +37,7 @@ class Frontend extends TextScanner {
this.isPreparedPromiseResolve = null; this.isPreparedPromiseResolve = null;
this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; }); this.isPreparedPromise = new Promise((resolve) => { this.isPreparedPromiseResolve = resolve; });
this.lastShowPromise = Promise.resolve(); this._lastShowPromise = Promise.resolve();
} }
static create() { static create() {
@ -68,7 +68,7 @@ class Frontend extends TextScanner {
async onResize() { async onResize() {
const textSource = this.textSourceCurrent; const textSource = this.textSourceCurrent;
if (textSource !== null && await this.popup.isVisibleAsync()) { if (textSource !== null && await this.popup.isVisibleAsync()) {
this.lastShowPromise = this.popup.showContent( this._lastShowPromise = this.popup.showContent(
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode() textSource.getWritingMode()
); );
@ -124,7 +124,7 @@ class Frontend extends TextScanner {
} catch (e) { } catch (e) {
if (window.yomichan_orphaned) { if (window.yomichan_orphaned) {
if (textSource !== null && this.options.scanning.modifier !== 'none') { if (textSource !== null && this.options.scanning.modifier !== 'none') {
this.lastShowPromise = this.popup.showContent( this._lastShowPromise = this.popup.showContent(
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode(), textSource.getWritingMode(),
'orphaned' 'orphaned'
@ -145,7 +145,7 @@ class Frontend extends TextScanner {
showContent(textSource, focus, definitions, type) { showContent(textSource, focus, definitions, type) {
const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt); const sentence = docSentenceExtract(textSource, this.options.anki.sentenceExt);
const url = window.location.href; const url = window.location.href;
this.lastShowPromise = this.popup.showContent( this._lastShowPromise = this.popup.showContent(
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode(), textSource.getWritingMode(),
type, type,
@ -153,6 +153,10 @@ class Frontend extends TextScanner {
); );
} }
showContentCompleted() {
return this._lastShowPromise;
}
async findTerms(textSource) { async findTerms(textSource) {
this.setTextSourceScanLength(textSource, this.options.scanning.length); this.setTextSourceScanLength(textSource, this.options.scanning.length);