Skip to content

Commit

Permalink
refactor: consolidate find-in-page handling into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bush2021 committed May 6, 2024
1 parent b29bdec commit 9bcdb1e
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/tabbookmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ bool IsNeedKeep(HWND hwnd, int32_t* ptr = nullptr) {
return keep_tab;
}

// If the top_container_view is not found at the first time, try to close the
// find-in-page bar and find the top_container_view again.
NodePtr IsFindBarOn(HWND hwnd) {
NodePtr top_container_view = GetTopContainerView(hwnd);
if (!top_container_view) {
ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd);
top_container_view = GetTopContainerView(hwnd);
if (!top_container_view) {
return nullptr;
}
}
return top_container_view;
}

class IniConfig {
public:
IniConfig()
Expand Down Expand Up @@ -108,16 +122,9 @@ int HandleDoubleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) {
}

HWND hwnd = WindowFromPoint(pmouse->pt);
NodePtr top_container_view = GetTopContainerView(hwnd);

// If the top_container_view is not found at the first time, try to close the
// find-in-page bar and find the top_container_view again.
NodePtr top_container_view = IsFindBarOn(hwnd);
if (!top_container_view) {
ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd);
top_container_view = GetTopContainerView(hwnd);
if (!top_container_view) {
return 0;
}
return 0;
}

bool is_on_one_tab = IsOnOneTab(top_container_view, pmouse->pt);
Expand All @@ -143,13 +150,9 @@ int HandleRightClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) {
}

HWND hwnd = WindowFromPoint(pmouse->pt);
NodePtr top_container_view = GetTopContainerView(hwnd);
NodePtr top_container_view = IsFindBarOn(hwnd);
if (!top_container_view) {
ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd);
top_container_view = GetTopContainerView(hwnd);
if (!top_container_view) {
return 0;
}
return 0;
}

bool is_on_one_tab = IsOnOneTab(top_container_view, pmouse->pt);
Expand All @@ -174,13 +177,9 @@ int HandleMiddleClick(WPARAM wParam, PMOUSEHOOKSTRUCT pmouse) {
}

HWND hwnd = WindowFromPoint(pmouse->pt);
NodePtr top_container_view = GetTopContainerView(hwnd);
NodePtr top_container_view = IsFindBarOn(hwnd);
if (!top_container_view) {
ExecuteCommand(IDC_CLOSE_FIND_OR_STOP, hwnd);
top_container_view = GetTopContainerView(hwnd);
if (!top_container_view) {
return 0;
}
return 0;
}

bool is_on_one_tab = IsOnOneTab(top_container_view, pmouse->pt);
Expand Down

0 comments on commit 9bcdb1e

Please sign in to comment.