Commit 6159e5b8 authored by hjk's avatar hjk
Browse files

fakevim: start with work on Ctrl-N/Ctrl-P

parent 91a3e02b
......@@ -2094,10 +2094,12 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
} else if (input.is('b') || input.isShift(Key_Left)) {
m_movetype = MoveExclusive;
moveToWordBoundary(false, false);
setTargetColumn();
finishMovement();
} else if (input.is('B')) {
m_movetype = MoveExclusive;
moveToWordBoundary(true, false);
setTargetColumn();
finishMovement();
} else if (input.is('c') && isNoVisualMode()) {
if (atEndOfLine())
......@@ -2193,10 +2195,12 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
} else if (input.is('e') || input.isShift(Key_Right)) {
m_movetype = MoveInclusive;
moveToWordBoundary(false, true);
setTargetColumn();
finishMovement("%1e", count());
} else if (input.is('E')) {
m_movetype = MoveInclusive;
moveToWordBoundary(true, true);
setTargetColumn();
finishMovement("%1E", count());
} else if (input.isControl('e')) {
// FIXME: this should use the "scroll" option, and "count"
......@@ -2470,6 +2474,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
// character of a word: only the current word will be changed
if (m_submode == ChangeSubMode) {
moveToWordBoundary(false, true, true);
setTargetColumn();
m_movetype = MoveInclusive;
} else {
moveToNextWord(false, m_submode == DeleteSubMode);
......@@ -2479,6 +2484,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
} else if (input.is('W')) {
if (m_submode == ChangeSubMode) {
moveToWordBoundary(true, true, true);
setTargetColumn();
m_movetype = MoveInclusive;
} else {
moveToNextWord(true, m_submode == DeleteSubMode);
......@@ -2705,6 +2711,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
} else if (input.isControl('w')) {
int endPos = position();
moveToWordBoundary(false, false, false);
setTargetColumn();
int beginPos = position();
Range range(beginPos, endPos, RangeCharMode);
removeText(range);
......@@ -2825,6 +2832,12 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
removeText(Range(pos, pos+i));
//} else if (key >= control('a') && key <= control('z')) {
// // ignore these
} else if (input.isControl('p') || input.isControl('n')) {
QTextCursor tc = EDITOR(textCursor());
moveToWordBoundary(false, false);
QString str = selectText(Range(position(), tc.position()));
EDITOR(setTextCursor(tc));
emit q->simpleCompletionRequested(str, input.isControl('n'));
} else if (!input.text().isEmpty()) {
insertInInsertMode(input.text());
} else {
......@@ -3960,7 +3973,6 @@ void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward, bool
if (repeat == -1)
break;
}
setTargetColumn();
}
bool FakeVimHandler::Private::handleFfTt(QString key)
......@@ -4690,6 +4702,7 @@ void FakeVimHandler::Private::selectWordTextObject(bool inner)
//if (isVisualMode())
// setMark('<', cursor().position());
moveToWordBoundary(false, true, true);
setTargetColumn();
m_movetype = MoveInclusive;
}
......@@ -4703,6 +4716,7 @@ void FakeVimHandler::Private::selectWORDTextObject(bool inner)
//if (isVisualMode())
// setMark('<', cursor().position());
moveToWordBoundary(true, true, true);
setTargetColumn();
m_movetype = MoveInclusive;
}
......
......@@ -122,6 +122,7 @@ signals:
void checkForElectricCharacter(bool *result, QChar c);
void indentRegion(int beginLine, int endLine, QChar typedChar);
void completionRequested();
void simpleCompletionRequested(const QString &needle, bool forward);
void windowCommandRequested(int key);
void findRequested(bool reverse);
void findNextRequested(bool reverse);
......
......@@ -63,6 +63,7 @@
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/indenter.h>
#include <texteditor/icompletioncollector.h>
#include <find/findplugin.h>
#include <find/textfindconstants.h>
......@@ -508,6 +509,7 @@ private slots:
void setUseFakeVim(const QVariant &value);
void quitFakeVim();
void triggerCompletions();
void triggerSimpleCompletions(const QString &needle, bool forward);
void windowCommand(int key);
void find(bool reverse);
void findNext(bool reverse);
......@@ -963,6 +965,8 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
this, SLOT(hasBlockSelection(bool*)));
connect(handler, SIGNAL(completionRequested()),
this, SLOT(triggerCompletions()));
connect(handler, SIGNAL(simpleCompletionRequested(QString,bool)),
this, SLOT(triggerSimpleCompletions(QString,bool)));
connect(handler, SIGNAL(windowCommandRequested(int)),
this, SLOT(windowCommand(int)));
connect(handler, SIGNAL(findRequested(bool)),
......@@ -1022,6 +1026,95 @@ void FakeVimPluginPrivate::triggerCompletions()
// bt->triggerCompletions();
}
class WordCompletion : public ICompletionCollector
{
public:
WordCompletion(ITextEditable *editor = 0) : m_editor(editor) {}
virtual ~WordCompletion() {}
virtual bool shouldRestartCompletion() { return false; }
virtual ITextEditable *editor() const { return m_editor; }
virtual int startPosition() const { return 0; }
virtual bool supportsEditor(ITextEditable *editor)
{ Q_UNUSED(editor); return true; }
virtual bool triggersCompletion(ITextEditable *editor)
{
qDebug() << "TRIGGERS?";
Q_UNUSED(editor); return false;
}
virtual int startCompletion(ITextEditable *editor)
{
qDebug() << "START COMPLETION";
Q_UNUSED(editor); return false;
}
/*
QList<CompletionItem> getCompletions()
{
QList<CompletionItem> completionItems;
completions(&completionItems);
return completionItems;
}
*/
/* This method should add all the completions it wants to show into
the list, based on the given cursor position. */
virtual void completions(QList<CompletionItem> *completions)
{
CompletionItem item;
item.text = "1st thing";
item.collector = this;
completions->append(item);
}
virtual bool typedCharCompletes(const CompletionItem &item, QChar typedChar)
{
qDebug() << "COMPLETE? " << typedChar;
Q_UNUSED(item); Q_UNUSED(typedChar); return false;
}
virtual void complete(const CompletionItem &item, QChar typedChar)
{
Q_UNUSED(item); Q_UNUSED(typedChar);
qDebug() << "COMPLETE: " << typedChar;
}
virtual bool partiallyComplete(const QList<CompletionItem> &completionItems)
{
qDebug() << "PARTIALLY";
Q_UNUSED(completionItems); return false;
}
virtual void cleanup() {}
private:
int findStartOfName(int pos = -1) const;
bool isInComment() const;
ITextEditable *m_editor;
QList<CompletionItem> m_items;
int m_startPosition;
};
void FakeVimPluginPrivate::triggerSimpleCompletions(const QString &needle,
bool forward)
{
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler)
return;
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget());
if (!bt)
return;
qDebug() << "NOT IMPLEMENTED, NEEDLE: " << needle << forward;
//WordCompletion *collector = new WordCompletion(bt->editableInterface());
TextEditor::CompletionSupport::instance()->
autoComplete(bt->editableInterface(), false);
// bt->triggerCompletions();
}
void FakeVimPluginPrivate::setBlockSelection(bool on)
{
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
......@@ -1326,6 +1419,17 @@ bool FakeVimPlugin::initialize(const QStringList &arguments, QString *errorMessa
{
Q_UNUSED(arguments)
Q_UNUSED(errorMessage)
/*
WordCompletion *completion = new WordCompletion;
addAutoReleasedObject(completion);
// Set completion settings and keep them up to date.
TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
completion->setCompletionSettings(textEditorSettings->completionSettings());
connect(textEditorSettings,
SIGNAL(completionSettingsChanged(TextEditor::CompletionSettings)),
completion,
SLOT(setCompletionSettings(TextEditor::CompletionSettings)));
*/
return d->initialize();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment