X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiCompleter.cpp;h=661178575b1f860e2a71ce82bedd42dd5470456f;hb=8863d6d785358680d05b4b34b35ca09a15cccb82;hp=064049c60bbd614c29e11c9f4b3515aa5fe224b4;hpb=2d48072e664099385b2442f7166b3c57129799bb;p=lyx.git diff --git a/src/frontends/qt/GuiCompleter.cpp b/src/frontends/qt/GuiCompleter.cpp index 064049c60b..661178575b 100644 --- a/src/frontends/qt/GuiCompleter.cpp +++ b/src/frontends/qt/GuiCompleter.cpp @@ -59,7 +59,7 @@ public: protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const + const QModelIndex &index) const override { if (index.column() == 0) { QItemDelegate::paint(painter, option, index); @@ -107,12 +107,12 @@ public: return false; } /// - int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const + int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override { return 2; } /// - int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const + int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override { if (list_ == 0) return 0; @@ -120,7 +120,7 @@ public: } /// - QVariant data(const QModelIndex & index, int role) const + QVariant data(const QModelIndex & index, int role) const override { if (list_ == 0) return QVariant(); @@ -348,8 +348,7 @@ void GuiCompleter::updateVisibility(bool start, bool keep) updateVisibility(cur, start, keep); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -456,8 +455,8 @@ void GuiCompleter::asyncUpdatePopup() // has a bad memory about it and we have to tell him again and again. QTreeView * listView = static_cast(popup()); listView->header()->setStretchLastSection(false); - setSectionResizeMode(listView->header(), 0, QHeaderView::Stretch); - setSectionResizeMode(listView->header(), 1, QHeaderView::Fixed); + listView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + listView->header()->setSectionResizeMode(1, QHeaderView::Fixed); listView->header()->resizeSection(1, 22); // show/update popup @@ -597,8 +596,7 @@ void GuiCompleter::showPopup() showPopup(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -610,8 +608,7 @@ void GuiCompleter::showInline() showInline(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -643,8 +640,7 @@ void GuiCompleter::hideInline() hideInline(cur); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } @@ -659,8 +655,8 @@ void GuiCompleter::activate() void GuiCompleter::tab() { - BufferView * bv = &gui_->bufferView(); - Cursor cur = bv->cursor(); + BufferView & bv = gui_->bufferView(); + Cursor cur = bv.cursor(); cur.screenUpdateFlags(Update::None); // check that inline completion is active @@ -686,9 +682,8 @@ void GuiCompleter::tab() return; } - // Make undo possible - UndoGroupHelper ugh; - cur.recordUndo(); + // Prepare for undo (recordUndo is invoked in the insets' insertCompletion methods) + UndoGroupHelper ugh(cur.buffer()); // If completion is active, at least complete by one character docstring prefix = cur.inset().completionPrefix(cur); @@ -701,6 +696,9 @@ void GuiCompleter::tab() hidePopup(); hideInline(cur); updateVisibility(false, false); + + // redraw if needed + bv.processUpdateFlags(cur.result().screenUpdate()); return; } docstring nextchar = completion.substr(prefix.size(), 1); @@ -712,8 +710,8 @@ void GuiCompleter::tab() docstring longestCompletion = longestUniqueCompletion(); prefix = cur.inset().completionPrefix(cur); docstring postfix = longestCompletion.substr(min(longestCompletion.size(), prefix.size())); - cur.inset().insertCompletion(cur, postfix, false); - old_cursor_ = bv->cursor(); + cur.inset().insertCompletion(cur, postfix, uniqueCompletionAvailable()); + old_cursor_ = bv.cursor(); updatePrefix(cur); // show popup without delay because the completion was not unique @@ -723,8 +721,7 @@ void GuiCompleter::tab() popup_timer_.start(0); // redraw if needed - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + bv.processUpdateFlags(cur.result().screenUpdate()); } @@ -891,8 +888,7 @@ void GuiCompleter::popupActivated(const QString & completion) hidePopup(); hideInline(cur); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); cur.endUndoGroup(); } @@ -908,8 +904,7 @@ void GuiCompleter::popupHighlighted(const QString & completion) if (inlineVisible()) updateInline(cur, completion); - if (cur.result().screenUpdate()) - gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); + gui_->bufferView().processUpdateFlags(cur.result().screenUpdate()); } } // namespace frontend