Skip to content

Commit

Permalink
Del should not delete an annotation if editing content (fixes #3878)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Nov 17, 2023
1 parent 10b1cf4 commit f3e4d87
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/AppTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ bool ExtendedEditWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM) {

switch (msg) {
case WM_LBUTTONDOWN:
delayFocus = !IsFocused(hwnd);
delayFocus = !HwndIsFocused(hwnd);
return true;

case WM_LBUTTONUP: {
Expand Down
6 changes: 6 additions & 0 deletions src/EditAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ bool EditAnnotationsWindow::PreTranslateMessage(MSG& msg) {
if (msg.message == WM_KEYDOWN) {
int key = (int)msg.wParam;
if (key == VK_DELETE) {
// we don't want this to trigger in edit control
HWND focused = ::GetFocus();
TempStr cls = HwndGetClassName(focused);
if (str::EqI(cls, "Edit")) {
return false;
}
DeleteSelectedAnnotation(this);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SearchAndDDE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void FindFirst(MainWindow* win) {

// Don't show a dialog if we don't have to - use the Toolbar instead
if (gGlobalPrefs->showToolbar && !win->isFullScreen && !win->presentation) {
if (IsFocused(win->hwndFindEdit)) {
if (HwndIsFocused(win->hwndFindEdit)) {
SendMessageW(win->hwndFindEdit, WM_SETFOCUS, 0, 0);
} else {
SetFocus(win->hwndFindEdit);
Expand Down
2 changes: 1 addition & 1 deletion src/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void OnSelectAll(MainWindow* win, bool textOnly) {
return;
}

if (IsFocused(win->hwndFindEdit) || IsFocused(win->hwndPageEdit)) {
if (HwndIsFocused(win->hwndFindEdit) || HwndIsFocused(win->hwndPageEdit)) {
EditSelectAll(GetFocus());
return;
}
Expand Down
11 changes: 6 additions & 5 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,7 @@ static void ChangeZoomLevel(MainWindow* win, float newZoom, bool pagesContinuous
}

static void FocusPageNoEdit(HWND hwndPageEdit) {
if (IsFocused(hwndPageEdit)) {
if (HwndIsFocused(hwndPageEdit)) {
SendMessageW(hwndPageEdit, WM_SETFOCUS, 0, 0);
} else {
SetFocus(hwndPageEdit);
Expand Down Expand Up @@ -4338,7 +4338,8 @@ void SetSidebarVisibility(MainWindow* win, bool tocVisible, bool showFavorites)
// TODO: make this a per-window setting as well?
gGlobalPrefs->showFavorites = showFavorites;

if ((!tocVisible && IsFocused(win->tocTreeView->hwnd)) || (!showFavorites && IsFocused(win->favTreeView->hwnd))) {
if ((!tocVisible && HwndIsFocused(win->tocTreeView->hwnd)) ||
(!showFavorites && HwndIsFocused(win->favTreeView->hwnd))) {
SetFocus(win->hwndFrame);
}

Expand Down Expand Up @@ -4482,7 +4483,7 @@ static void CopySelectionInTabToClipboard(WindowTab* tab) {
if (!tab || !tab->win) {
return;
}
if (IsFocused(tab->win->hwndFindEdit) || IsFocused(tab->win->hwndPageEdit)) {
if (HwndIsFocused(tab->win->hwndFindEdit) || HwndIsFocused(tab->win->hwndPageEdit)) {
SendMessageW(GetFocus(), WM_COPY, 0, 0);
return;
}
Expand Down Expand Up @@ -5182,7 +5183,7 @@ static LRESULT FrameOnCommand(MainWindow* win, HWND hwnd, UINT msg, WPARAM wp, L
}

case CmdMoveFrameFocus:
if (!IsFocused(win->hwndFrame)) {
if (!HwndIsFocused(win->hwndFrame)) {
SetFocus(win->hwndFrame);
} else if (win->tocVisible) {
SetFocus(win->tocTreeView->hwnd);
Expand Down Expand Up @@ -5602,7 +5603,7 @@ LRESULT CALLBACK WndProcSumatraFrame(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
// handled as expected)
int x = GET_X_LPARAM(lp);
int y = GET_Y_LPARAM(lp);
if (win && (x == -1) && (y == -1) && !IsFocused(win->tocTreeView->hwnd)) {
if (win && (x == -1) && (y == -1) && !HwndIsFocused(win->tocTreeView->hwnd)) {
return SendMessageW(win->hwndCanvas, WM_CONTEXTMENU, wp, lp);
}
return DefWindowProc(hwnd, msg, wp, lp);
Expand Down
2 changes: 1 addition & 1 deletion src/Toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void ShowOrHideToolbar(MainWindow* win) {
ShowWindow(win->hwndReBar, SW_SHOW);
} else {
// Move the focus out of the toolbar
if (IsFocused(win->hwndFindEdit) || IsFocused(win->hwndPageEdit)) {
if (HwndIsFocused(win->hwndFindEdit) || HwndIsFocused(win->hwndPageEdit)) {
SetFocus(win->hwndFrame);
}
ShowWindow(win->hwndReBar, SW_HIDE);
Expand Down
9 changes: 8 additions & 1 deletion src/utils/WinUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ void DrawLine(HDC hdc, const Rect& rect) {
LineTo(hdc, rect.x + rect.dx, rect.y + rect.dy);
}

bool IsFocused(HWND hwnd) {
bool HwndIsFocused(HWND hwnd) {
return GetFocus() == hwnd;
}

Expand All @@ -1204,6 +1204,13 @@ bool IsCursorOverWindow(HWND hwnd) {
return rcWnd.Contains({pt.x, pt.y});
}

TempStr HwndGetClassName(HWND hwnd) {
WCHAR buf[512] = {0};
int n = GetClassNameW(hwnd, buf, dimof(buf));
CrashIf(n == 0);
return ToUtf8Temp(buf);
}

Point HwndGetCursorPos(HWND hwnd) {
POINT pt;
if (!GetCursorPos(&pt)) {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/WinUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ int HdcDrawText(HDC hdc, const char* s, const Point& pos, uint fmt, HFONT font =
Size HdcMeasureText(HDC hdc, const char* s, uint format, HFONT font = nullptr);
Size HdcMeasureText(HDC hdc, const char* s, HFONT font = nullptr);

bool IsFocused(HWND);
bool HwndIsFocused(HWND);
bool IsCursorOverWindow(HWND);

TempStr HwndGetClassName(HWND hwnd);
Point HwndGetCursorPos(HWND hwnd);
int MapWindowPoints(HWND, HWND, Point*, int);
void HwndScreenToClient(HWND, Point&);
Expand Down
2 changes: 1 addition & 1 deletion src/wingui/WinGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ void Wnd::SetFocus() const {
}

bool Wnd::IsFocused() const {
BOOL isFocused = ::IsFocused(hwnd);
BOOL isFocused = HwndIsFocused(hwnd);
return tobool(isFocused);
}

Expand Down

0 comments on commit f3e4d87

Please sign in to comment.