diff --git a/Libraries/LibGUI/DragOperation.cpp b/Libraries/LibGUI/DragOperation.cpp index d85e05fd80..a21078dfa9 100644 --- a/Libraries/LibGUI/DragOperation.cpp +++ b/Libraries/LibGUI/DragOperation.cpp @@ -98,8 +98,8 @@ void DragOperation::notify_accepted(Badge) void DragOperation::notify_cancelled(Badge) { - ASSERT(s_current_drag_operation); - s_current_drag_operation->done(Outcome::Cancelled); + if (s_current_drag_operation) + s_current_drag_operation->done(Outcome::Cancelled); } void DragOperation::set_text(const String& text) diff --git a/Services/WindowServer/WindowManager.cpp b/Services/WindowServer/WindowManager.cpp index 86c9ed9c77..2002512eea 100644 --- a/Services/WindowServer/WindowManager.cpp +++ b/Services/WindowServer/WindowManager.cpp @@ -1084,8 +1084,15 @@ void WindowManager::event(Core::Event& event) auto& key_event = static_cast(event); m_keyboard_modifiers = key_event.modifiers(); + // Escape key cancels an ongoing drag. if (key_event.type() == Event::KeyDown && key_event.key() == Key_Escape && m_dnd_client) { + // Notify the drag-n-drop client that the drag was cancelled. m_dnd_client->post_message(Messages::WindowClient::DragCancelled()); + + // Also notify the currently hovered window (if any) that the ongoing drag was cancelled. + if (m_hovered_window && m_hovered_window->client() && m_hovered_window->client() != m_dnd_client) + m_hovered_window->client()->post_message(Messages::WindowClient::DragCancelled()); + end_dnd_drag(); return; }