UI/Qt: Restore address bar URL when pressing Escape

When the user focuses the address bar and presses Escape, the original
URL is now restored. Previously, the address bar would show whatever
text the user had typed, or be empty if they had cleared it.

This matches the AppKit implementation and Chrome/Firefox behavior.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/7264
This commit is contained in:
sideshowbarker 2026-01-06 18:42:05 +09:00 committed by Tim Flynn
parent 34d7fe2074
commit 16fd2ccee0
2 changed files with 16 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <UI/Qt/StringUtils.h>
#include <QApplication>
#include <QKeyEvent>
#include <QPalette>
#include <QTextLayout>
#include <QTimer>
@ -77,6 +78,20 @@ void LocationEdit::focusOutEvent(QFocusEvent* event)
}
}
void LocationEdit::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Escape) {
if (m_autocomplete->popup()->isVisible()) {
QLineEdit::keyPressEvent(event);
return;
}
setText(qstring_from_ak_string(m_url.serialize()));
clearFocus();
return;
}
QLineEdit::keyPressEvent(event);
}
void LocationEdit::search_engine_changed()
{
update_placeholder();

View file

@ -32,6 +32,7 @@ public:
private:
virtual void focusInEvent(QFocusEvent* event) override;
virtual void focusOutEvent(QFocusEvent* event) override;
virtual void keyPressEvent(QKeyEvent* event) override;
virtual void search_engine_changed() override;