GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
- : QCompleter(parent), gui_(gui), updateLock_(0),
+ : QCompleter(parent), gui_(gui), old_cursor_(0), updateLock_(0),
inlineVisible_(false), popupVisible_(false),
modelActive_(false)
{
model_ = new GuiCompletionModel(this, 0);
setModel(model_);
setCompletionMode(QCompleter::PopupCompletion);
+ setCaseSensitivity(Qt::CaseInsensitive);
setWidget(gui_);
// create the popup
}
+bool GuiCompleter::uniqueCompletionAvailable() const
+{
+ if (!modelActive_)
+ return false;
+
+ size_t n = popup()->model()->rowCount();
+ if (n > 1 || n == 0)
+ return false;
+
+ // if there is exactly one, we have to check whether it is a
+ // real completion, i.e. longer than the current prefix.
+ if (completionPrefix() == currentCompletion())
+ return false;
+
+ return true;
+}
+
+
bool GuiCompleter::completionAvailable() const
{
if (!modelActive_)
if (!inlineVisible() && possibleInlineState && start
&& cur.inset().automaticInlineCompletion())
inline_timer_.start(int(lyxrc.completion_inline_delay * 1000));
+ else {
+ // no inline completion, hence a metrics update is needed
+ if (!(cur.disp_.update() & Update::Force))
+ cur.updateFlags(cur.disp_.update() | Update::SinglePar);
+ }
// update prefix if any completion is possible
bool modelActive = modelActive_ && model()->rowCount() > 0;
void GuiCompleter::hideInline(Cursor & cur)
{
- gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring());
+ gui_->bufferView().setInlineCompletion(cur, DocIterator(cur.buffer()), docstring());
inlineVisible_ = false;
if (inline_timer_.isActive())
void GuiCompleter::activate()
{
if (!popupVisible() && !inlineVisible())
- return;
-
- popupActivated(currentCompletion());
+ tab();
+ else
+ popupActivated(currentCompletion());
}
cur.updateFlags(Update::None);
// check that inline completion is active
- if (!inlineVisible()) {
+ if (!inlineVisible() && !uniqueCompletionAvailable()) {
// try to activate the inline completion
if (cur.inset().inlineCompletionSupported(cur)) {
showInline();
return;
}
+ // Make undo possible
+ cur.recordUndo();
+
// If completion is active, at least complete by one character
docstring prefix = cur.inset().completionPrefix(cur);
docstring completion = qstring_to_ucs4(currentCompletion());
if (n == 0)
return docstring();
QString s = model.data(model.index(0, 0), Qt::EditRole).toString();
-
+
if (modelSorting() == QCompleter::UnsortedModel) {
// For unsorted model we cannot do more than iteration.
// Iterate through the completions and cut off where s differs
Cursor cur = gui_->bufferView().cursor();
cur.updateFlags(Update::None);
+ cur.recordUndo();
+
docstring prefix = cur.inset().completionPrefix(cur);
docstring postfix = qstring_to_ucs4(completion.mid(prefix.length()));
cur.inset().insertCompletion(cur, postfix, true);