From 34f75ff02079ec2dd5a670fd1a8b7657a28b7638 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Tue, 13 Feb 2024 21:15:09 +0800 Subject: [PATCH] perf: do not clear result if text length is 0, means @"" --- .../Window/WindowManager/EZWindowManager.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index 1b098b8d5..7eb580313 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -691,9 +691,13 @@ - (void)selectTextTranslate { [self.eventMonitor getSelectedText:^(NSString *_Nullable text) { self.actionType = self.eventMonitor.actionType; - // Clear query if text is nil and user don't want to keep the last result. - if (!text && !Configuration.shared.keepPrevResultWhenEmpty) { - text = @""; + /** + Clear query if text is nil and user don't want to keep the last result. + + !!!: text may be @"" when no selected text in Chrome, so we need to handle it. + */ + if (text.length == 0) { + text = Configuration.shared.keepPrevResultWhenEmpty ? nil : @""; } self.selectedText = [text trim];