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));
bool GuiCompleter::popupVisible() const
{
- return popup()->isVisible();
+ return popupVisible_;
}
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;
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
gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
inlineVisible_ = false;
+ if (inline_timer_.isActive())
+ inline_timer_.stop();
+
if (!popupVisible())
setModel(new GuiCompletionModel(this, 0));
}