Commit f2e0dd85 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

urlbar: Don't rely on focus change

Fixes the crash with stale QModelIndex + other focus issues and
accidental urlbar opening.
parent 89a5a235
Pipeline #139548 passed with stage
in 2 minutes and 26 seconds
......@@ -359,22 +359,13 @@ public:
m.exec(pos);
}
protected:
void focusInEvent(QFocusEvent *f) override
void openLastIndex()
{
if (f->reason() == Qt::OtherFocusReason) {
const auto last = m_model.index(m_model.rowCount() - 1, 0);
if (last.isValid()) {
setCurrentIndex(last);
QMetaObject::invokeMethod(
this,
[this, last] {
clicked(last);
},
Qt::QueuedConnection);
}
const auto last = m_model.index(m_model.rowCount() - 1, 0);
if (last.isValid()) {
setCurrentIndex(last);
clicked(last);
}
QListView::focusInEvent(f);
}
private:
......@@ -475,6 +466,13 @@ KateUrlBar::KateUrlBar(KateViewSpace *parent)
setHidden(!vm->showUrlNavBar());
}
void KateUrlBar::open()
{
if (m_breadCrumbView && m_stack->currentWidget() == m_breadCrumbView) {
m_breadCrumbView->openLastIndex();
}
}
void KateUrlBar::onViewChanged(KTextEditor::View *v)
{
if (!v) {
......
......@@ -15,6 +15,7 @@ class KateUrlBar : public QWidget
Q_OBJECT
public:
explicit KateUrlBar(KateViewSpace *parent = nullptr);
void open();
Q_SIGNALS:
void openUrlRequested(const QUrl &url, Qt::KeyboardModifiers);
......
......@@ -745,7 +745,7 @@ void KateViewSpace::closeTabWithWidget(QWidget *widget)
void KateViewSpace::focusNavigationBar()
{
if (!m_urlBar->isHidden()) {
m_urlBar->setFocus();
m_urlBar->open();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment