Skip to content

Commit

Permalink
fix: tisfeng#452 blank for tips view
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark committed Apr 7, 2024
1 parent 91ad693 commit 4169f64
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ @interface EZBaseQueryViewController () <NSTableViewDelegate, NSTableViewDataSou

@property (nonatomic, assign) BOOL lockResizeWindow;

@property (nonatomic, assign, getter=isShowTipsView) BOOL showTipsView;
@property (nonatomic, assign) BOOL showTipsView;

@property (nonatomic, assign) BOOL hasShowTips;

Expand Down Expand Up @@ -124,6 +124,14 @@ - (void)viewWillAppear {
[super viewWillAppear];

[EZLog logWindowAppear:self.windowType];
[self recoverStatus];
}

- (void)recoverStatus {
self.showTipsView = [self isShowTipsView];
[self.tableView reloadData];
[self updateWindowViewHeight];
self.hasShowTips = NO;
}

- (void)setupData {
Expand Down Expand Up @@ -374,6 +382,9 @@ - (void)setInputText:(NSString *)inputText {

self.queryModel.inputText = _inputText;

// update showTipsView status
self.showTipsView = [self isShowTipsView];

[self updateQueryViewModelAndDetectedLanguage:self.queryModel];
}

Expand All @@ -394,18 +405,14 @@ - (BOOL)isShowTipsView {
if (Configuration.shared.disableTipsView) {
return NO;
}
if (EZ_isEmptyString(self.queryModel.queryText) &&
if (EZ_isEmptyString(self.queryModel.queryText) &&
!self.hasShowTips &&
self.queryModel.actionType != EZActionTypeInputQuery) {
return YES;
}
return NO;
}

- (BOOL)isTipsCellRow:(NSInteger)row {
return (self.isShowTipsView && row == 2 && self.windowType != EZWindowTypeMini) || (self.isShowTipsView && row == 1);
}

#pragma mark - Public Methods

/// Before starting query text, close all result view.
Expand All @@ -417,6 +424,7 @@ - (void)startQueryText:(NSString *)text actionType:(EZActionType)actionType {
NSLog(@"query actionType: %@", actionType);

if (text.trim.length == 0) {
self.showTipsView = [self isShowTipsView];
NSLog(@"query text is empty");
return;
}
Expand Down Expand Up @@ -526,6 +534,10 @@ - (void)startOCRImage:(NSImage *)image actionType:(EZActionType)actionType {
if (error) {
NSString *errorMsg = [error localizedDescription];
self.queryView.alertText = errorMsg;

self.showTipsView = [self isShowTipsView];
[self.tableView reloadData];
[self updateWindowViewHeight];
return;
}

Expand Down Expand Up @@ -859,7 +871,7 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null
}

// show tips view
if ([self isTipsCellRow:row]) {
if (row == 2 && self.showTipsView && !self.hasShowTips) {
EZTableTipsCell *tipsCell = [self.tableView makeViewWithIdentifier:EZTableTipsCellId owner:self];
if (!tipsCell) {
tipsCell = [[EZTableTipsCell alloc] initWithFrame:[self tableViewContentBounds]];
Expand All @@ -884,9 +896,9 @@ - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
height = self.queryModel.queryViewHeight;
} else if (row == 1 && self.windowType != EZWindowTypeMini) {
height = 35;
} else if ([self isTipsCellRow:row]) {
} else if (row == 2 && self.showTipsView && !self.hasShowTips) {
if (!self.tipsCell) {
height = 100;
height = 1;
} else {
height = [self.tipsCell cellHeight];
}
Expand Down Expand Up @@ -1416,7 +1428,7 @@ - (NSInteger)resultCellOffset {
}
}

if (self.isShowTipsView) {
if (self.showTipsView && !self.hasShowTips) {
offset += 1;
}

Expand Down Expand Up @@ -1536,11 +1548,6 @@ - (CGFloat)getScrollViewContentHeight {
}
// NSLog(@"scrollViewContentHeight: %.1f", scrollViewContentHeight);

if (!self.hasShowTips &&
!EZ_isEmptyString(self.queryModel.queryText) &&
!Configuration.shared.disableTipsView) {
scrollViewContentHeight += [self.tipsCell cellHeight];
}

return scrollViewContentHeight;
}
Expand Down

0 comments on commit 4169f64

Please sign in to comment.