From b9c68179e4074db5a3e85a9c28721b14a4edc1a7 Mon Sep 17 00:00:00 2001 From: sienori Date: Thu, 22 Aug 2019 14:37:41 +0900 Subject: [PATCH] Fix infinite loop when switching to second language --- src/popup/components/PopupPage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/popup/components/PopupPage.js b/src/popup/components/PopupPage.js index ffaf757..dad1570 100644 --- a/src/popup/components/PopupPage.js +++ b/src/popup/components/PopupPage.js @@ -60,7 +60,7 @@ export default class PopupPage extends Component { tabUrl: tabInfo.url, isEnabledOnPage: tabInfo.isEnabledOnPage }); - if (tabInfo.selectedText !== "") this.translateText(tabInfo.selectedText, targetLang); + if (tabInfo.selectedText !== "") this.handleInputText(tabInfo.selectedText); }; handleInputText = inputText => { @@ -68,10 +68,10 @@ export default class PopupPage extends Component { const waitTime = getSettings("waitTime"); clearTimeout(this.inputTimer); - this.inputTimer = setTimeout( - () => this.translateText(inputText, this.state.targetLang), - waitTime - ); + this.inputTimer = setTimeout(async () => { + const result = await this.translateText(inputText, this.state.targetLang); + this.switchSecondLang(result); + }, waitTime); }; handleLangChange = lang => { @@ -87,7 +87,7 @@ export default class PopupPage extends Component { candidateText: result.candidateText, statusText: result.statusText }); - this.switchSecondLang(result); + return result; }; switchSecondLang = result => {