From b4466b63f6c7ee665b8c3e18629a6595132a1b80 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Tue, 4 Mar 2008 09:43:32 +0000 Subject: [PATCH] * fix another crash due to the redraw opti-/minimization during completion. We have to show and hide the popup asynchronously with a singleshot timer. Otherwise it might trigger accesses to the coord cache although the metrics have not been done yet. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23424 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiCompleter.cpp | 32 ++++++++++++++++++++++++++---- src/frontends/qt4/GuiCompleter.h | 4 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index 8459bf630a..11348e5dcb 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -171,7 +171,7 @@ private: GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent) : QCompleter(parent), gui_(gui), updateLock_(0), - inlineVisible_(false) + inlineVisible_(false), popupVisible_(false) { // Setup the completion popup setModel(new GuiCompletionModel(this, 0)); @@ -260,7 +260,7 @@ bool GuiCompleter::completionAvailable() const bool GuiCompleter::popupVisible() const { - return popup()->isVisible(); + return popupVisible_; } @@ -392,9 +392,28 @@ void GuiCompleter::updatePopup(Cursor & cur) if (!cur.inset().completionSupported(cur)) return; - if (completionCount() == 0) + popupVisible_ = true; + + if (completionCount() == 0) { + QTimer::singleShot(0, popup(), SLOT(hide())); return; - + } + + // show asynchronously to avoid lookups before the metrics + // have been computed. This can happen because we might be in + // the middle of a dispatch. + QTimer::singleShot(0, this, SLOT(asyncCompletePopup())); +} + + +void GuiCompleter::asyncCompletePopup() +{ + Cursor cur = gui_->bufferView().cursor(); + if (!cur.inset().completionSupported(cur)) { + popupVisible_ = false; + return; + } + // get dimensions of completion prefix Dimension dim; int x; @@ -504,6 +523,8 @@ void GuiCompleter::showPopup(Cursor & cur) void GuiCompleter::hidePopup(Cursor & cur) { + popupVisible_ = false; + // hide popup asynchronously because we might be here inside of // LFUN dispatchers. Hiding a popup can trigger a focus event on the // workarea which then redisplays the cursor. But the metrics are not @@ -533,6 +554,9 @@ void GuiCompleter::hideInline(Cursor & cur) gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring()); inlineVisible_ = false; + if (inline_timer_.isActive()) + inline_timer_.stop(); + if (!popupVisible()) setModel(new GuiCompletionModel(this, 0)); } diff --git a/src/frontends/qt4/GuiCompleter.h b/src/frontends/qt4/GuiCompleter.h index b53220c161..7cb87535a0 100644 --- a/src/frontends/qt4/GuiCompleter.h +++ b/src/frontends/qt4/GuiCompleter.h @@ -88,6 +88,8 @@ private Q_SLOTS: void popupHighlighted(const QString & completion); /// void updateAvailability(); + /// + void asyncCompletePopup(); private: /// @@ -128,6 +130,8 @@ private: /// in addition to know whether the completion is to be kept visible. bool inlineVisible_; /// + bool popupVisible_; + /// RtlItemDelegate * rtlItemDelegate_; }; // GuiCompleter -- 2.39.2