}
-void BufferView::setInlineCompletion(DocIterator const & pos,
+bool samePar(DocIterator const & a, DocIterator const & b)
+{
+ if (a.empty() && b.empty())
+ return true;
+ if (a.empty() || b.empty())
+ return false;
+ return &a.innerParagraph() == &b.innerParagraph();
+}
+
+
+void BufferView::setInlineCompletion(Cursor & cur, DocIterator const & pos,
docstring const & completion, size_t uniqueChars)
{
- d->inlineCompletionPos = pos;
+ uniqueChars = min(completion.size(), uniqueChars);
+ bool changed = d->inlineCompletion != completion
+ || d->inlineCompletionUniqueChars != uniqueChars;
+ bool singlePar = true;
d->inlineCompletion = completion;
d->inlineCompletionUniqueChars = min(completion.size(), uniqueChars);
+
+ lyxerr << "setInlineCompletion pos=" << pos << " completion=" << completion << " uniqueChars=" << uniqueChars << std::endl;
+
+ // at new position?
+ DocIterator const & old = d->inlineCompletionPos;
+ if (old != pos) {
+ lyxerr << "inlineCompletionPos changed" << std::endl;
+ // old or pos are in another paragraph?
+ if ((!samePar(cur, pos) && !pos.empty())
+ || (!samePar(cur, old) && !old.empty())) {
+ singlePar = false;
+ lyxerr << "different paragraph" << std::endl;
+ }
+ d->inlineCompletionPos = pos;
+ }
+
+ // set update flags
+ if (changed) {
+ lyxerr << "inlineCompletion changed" << std::endl;
+
+ Update::flags flags
+ = cur.disp_.update() | Update::Force;
+ if (singlePar && !(flags | Update::SinglePar))
+ flags = flags | Update::SinglePar;
+ cur.updateFlags(flags);
+ }
}
} // namespace lyx
/// return the position in the buffer of the inline completion postfix.
DocIterator const & inlineCompletionPos() const;
/// set the inline completion postfix and its position in the buffer.
- void setInlineCompletion(DocIterator const & pos, docstring const & completion,
- size_t uniqueChars = 0);
+ /// Updates the updateFlags in \c cur.
+ void setInlineCompletion(Cursor & cur, DocIterator const & pos,
+ docstring const & completion, size_t uniqueChars = 0);
/// translate and insert a character, using the correct keymap.
void translateAndInsert(char_type c, Text * t, Cursor & cur);
}
private:
+ ///
Inset::CompletionListPtr list;
};
GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
- : QCompleter(parent), gui_(gui)
+ : QCompleter(parent), gui_(gui), updateLock_(0)
{
// Setup the completion popup
setModel(new GuiCompletionModel(this, Inset::CompletionListPtr()));
inline_timer_.stop();
// hide old inline completion
- if (inlineVisible()) {
- gui_->bufferView().setInlineCompletion(DocIterator(), docstring());
- cur.updateFlags(Update::Force | Update::SinglePar);
- }
+ if (inlineVisible())
+ gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
}
// we inserted something and are in a possible popup state?
void GuiCompleter::updateVisibility(bool start, bool keep)
{
Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
updateVisibility(cur, start, keep);
+
if (cur.disp_.update())
gui_->bufferView().processUpdateFlags(cur.disp_.update());
}
// set inline completion at cursor position
size_t uniqueTo = max(longestUniqueCompletion().size(), prefix.size());
- gui_->bufferView().setInlineCompletion(cur, postfix, uniqueTo - prefix.size());
- cur.updateFlags(Update::Force | Update::SinglePar);
+ gui_->bufferView().setInlineCompletion(cur, cur, postfix, uniqueTo - prefix.size());
}
complete(insetRect);
QTreeView * p = static_cast<QTreeView *>(popup());
p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width());
-
- // update highlight
- updateInline(cur, currentCompletion());
}
void GuiCompleter::showPopup()
{
Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
showPopup(cur);
// redraw if needed
void GuiCompleter::showInline()
{
Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
showInline(cur);
// redraw if needed
void GuiCompleter::tab()
{
BufferView * bv = &gui_->bufferView();
- Cursor & cur = bv->cursor();
-
+ Cursor cur = bv->cursor();
+ cur.updateFlags(Update::None);
+
// check that inline completion is active
if (!inlineVisible()) {
// try to activate the inline completion
void GuiCompleter::setCurrentCompletion(QString const & s)
-{
+{
QAbstractItemModel const & model = *popup()->model();
size_t n = model.rowCount();
if (n == 0)
// select the first if s is empty
if (s.length() == 0) {
+ updateLock_++;
popup()->setCurrentIndex(model.index(0, 0));
+ updateLock_--;
return;
}
if (i == n)
i = 0;
+ updateLock_++;
popup()->setCurrentIndex(model.index(i, 0));
+ updateLock_--;
}
void GuiCompleter::popupActivated(const QString & completion)
{
- Cursor & cur = gui_->bufferView().cursor();
+ Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
docstring prefix = cur.inset().completionPrefix(cur);
docstring postfix = from_utf8(fromqstr(completion.mid(prefix.length())));
cur.inset().insertCompletion(cur, postfix, true);
updateVisibility(cur, false);
+
if (cur.disp_.update())
gui_->bufferView().processUpdateFlags(cur.disp_.update());
}
void GuiCompleter::popupHighlighted(const QString & completion)
{
+ if (updateLock_ > 0)
+ return;
+
Cursor cur = gui_->bufferView().cursor();
+ cur.updateFlags(Update::None);
+
updateInline(cur, completion);
+
if (cur.disp_.update())
gui_->bufferView().processUpdateFlags(cur.disp_.update());
}