forked from qt-creator/qt-creator
fakevim: Handle completion in insert and replace modes
Text inserted without FakeVim's intervention (code completion) is handled in insert and replace mode so that '.' command also inserts any externally inserted text. After movement in insert mode last command (initiated by '.') is not cleared until new text is inserted. Deletion in insert mode is part of dot command. Change-Id: Ic55b3cdecaf4323e88cd321b218fae661de7a63e Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -218,6 +218,14 @@ struct FakeVimPlugin::TestData
|
|||||||
setPosition(i);
|
setPosition(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Simulate text completion by inserting text directly to editor widget (bypassing FakeVim).
|
||||||
|
void completeText(const QString &text)
|
||||||
|
{
|
||||||
|
QTextCursor tc = editor()->textCursor();
|
||||||
|
tc.insertText(text);
|
||||||
|
editor()->setTextCursor(tc);
|
||||||
|
}
|
||||||
|
|
||||||
int lines() const
|
int lines() const
|
||||||
{
|
{
|
||||||
QTextDocument *doc = editor()->document();
|
QTextDocument *doc = editor()->document();
|
||||||
@@ -476,6 +484,28 @@ void FakeVimPlugin::test_vim_insert()
|
|||||||
data.setText("abc" N "def");
|
data.setText("abc" N "def");
|
||||||
KEYS("<insert>XYZ<insert>xyz<esc>", "XYZxy" X "z" N "def");
|
KEYS("<insert>XYZ<insert>xyz<esc>", "XYZxy" X "z" N "def");
|
||||||
KEYS("<insert><insert>" "<c-o>0<c-o>j" "XY<insert>Z", "XYZxyz" N "XYZ" X "f");
|
KEYS("<insert><insert>" "<c-o>0<c-o>j" "XY<insert>Z", "XYZxyz" N "XYZ" X "f");
|
||||||
|
|
||||||
|
// dot command for insert
|
||||||
|
data.setText("abc" N "def");
|
||||||
|
KEYS("ix<insert>X<insert>y<esc>", "xX" X "ybc" N "def");
|
||||||
|
KEYS("0j.", "xXybc" N "xX" X "yef");
|
||||||
|
|
||||||
|
data.setText("abc" N "def");
|
||||||
|
KEYS("<insert>x<insert>X<right>Y<esc>", "xXb" X "Y" N "def");
|
||||||
|
KEYS("0j.", "xXbY" N X "Yef");
|
||||||
|
|
||||||
|
data.setText("abc" N "def");
|
||||||
|
KEYS("<insert>x<insert>X<left><left><down><esc>", "xXbc" N X "def");
|
||||||
|
KEYS(".", "xXbc" N "x" X "Xef");
|
||||||
|
|
||||||
|
// delete in insert mode is part of dot command
|
||||||
|
data.setText("abc" N "def");
|
||||||
|
KEYS("iX<delete>Y", "XY" X "bc" N "def");
|
||||||
|
KEYS("0j.", "XYbc" N "X" X "Yef");
|
||||||
|
|
||||||
|
data.setText("abc" N "def");
|
||||||
|
KEYS("2iX<delete>Y<esc>", "XYX" X "Yc" N "def");
|
||||||
|
KEYS("0j.", "XYXYc" N "XYX" X "Yf");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPlugin::test_vim_fFtT()
|
void FakeVimPlugin::test_vim_fFtT()
|
||||||
@@ -1548,6 +1578,58 @@ void FakeVimPlugin::test_vim_code_folding()
|
|||||||
// Opening folds recursively isn't supported (previous position in fold isn't restored).
|
// Opening folds recursively isn't supported (previous position in fold isn't restored).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimPlugin::test_vim_code_completion()
|
||||||
|
{
|
||||||
|
// Test completion by simply bypassing FakeVim and inserting text directly in editor widget.
|
||||||
|
TestData data;
|
||||||
|
setup(&data);
|
||||||
|
data.setText(
|
||||||
|
"int test1Var;" N
|
||||||
|
"int test2Var;" N
|
||||||
|
"int main() {" N
|
||||||
|
" " X ";" N
|
||||||
|
"}" N
|
||||||
|
"");
|
||||||
|
|
||||||
|
data.doKeys("i" "te");
|
||||||
|
data.completeText("st");
|
||||||
|
data.doKeys("1");
|
||||||
|
data.completeText("Var");
|
||||||
|
data.doKeys(" = 0");
|
||||||
|
KEYS("",
|
||||||
|
"int test1Var;" N
|
||||||
|
"int test2Var;" N
|
||||||
|
"int main() {" N
|
||||||
|
" test1Var = " X "0;" N
|
||||||
|
"}" N
|
||||||
|
"");
|
||||||
|
|
||||||
|
data.doKeys("o" "te");
|
||||||
|
data.completeText("st");
|
||||||
|
data.doKeys("2");
|
||||||
|
data.completeText("Var");
|
||||||
|
data.doKeys(" = 1;");
|
||||||
|
KEYS("",
|
||||||
|
"int test1Var;" N
|
||||||
|
"int test2Var;" N
|
||||||
|
"int main() {" N
|
||||||
|
" test1Var = 0;" N
|
||||||
|
" test2Var = 1" X ";" N
|
||||||
|
"}" N
|
||||||
|
"");
|
||||||
|
|
||||||
|
// repeat text insertion with completion
|
||||||
|
KEYS(".",
|
||||||
|
"int test1Var;" N
|
||||||
|
"int test2Var;" N
|
||||||
|
"int main() {" N
|
||||||
|
" test1Var = 0;" N
|
||||||
|
" test2Var = 1;" N
|
||||||
|
" test2Var = 1" X ";" N
|
||||||
|
"}" N
|
||||||
|
"");
|
||||||
|
}
|
||||||
|
|
||||||
void FakeVimPlugin::test_vim_substitute()
|
void FakeVimPlugin::test_vim_substitute()
|
||||||
{
|
{
|
||||||
TestData data;
|
TestData data;
|
||||||
|
|||||||
@@ -672,6 +672,8 @@ static const QMap<QString, int> &vimKeyNames()
|
|||||||
k.insert("LEFT", Key_Left);
|
k.insert("LEFT", Key_Left);
|
||||||
k.insert("RIGHT", Key_Right);
|
k.insert("RIGHT", Key_Right);
|
||||||
|
|
||||||
|
k.insert("LT", Key_Less);
|
||||||
|
|
||||||
k.insert("F1", Key_F1);
|
k.insert("F1", Key_F1);
|
||||||
k.insert("F2", Key_F2);
|
k.insert("F2", Key_F2);
|
||||||
k.insert("F3", Key_F3);
|
k.insert("F3", Key_F3);
|
||||||
@@ -1578,6 +1580,7 @@ public:
|
|||||||
|
|
||||||
Q_SLOT void importSelection();
|
Q_SLOT void importSelection();
|
||||||
void exportSelection();
|
void exportSelection();
|
||||||
|
void recordInsertion(const QString &insert = QString());
|
||||||
void ensureCursorVisible();
|
void ensureCursorVisible();
|
||||||
void insertInInsertMode(const QString &text);
|
void insertInInsertMode(const QString &text);
|
||||||
|
|
||||||
@@ -1615,7 +1618,6 @@ public:
|
|||||||
|
|
||||||
int m_findStartPosition;
|
int m_findStartPosition;
|
||||||
QString m_lastInsertion;
|
QString m_lastInsertion;
|
||||||
QString m_lastDeletion;
|
|
||||||
|
|
||||||
bool m_breakEditBlock;
|
bool m_breakEditBlock;
|
||||||
|
|
||||||
@@ -1867,7 +1869,7 @@ void FakeVimHandler::Private::init()
|
|||||||
void FakeVimHandler::Private::focus()
|
void FakeVimHandler::Private::focus()
|
||||||
{
|
{
|
||||||
stopIncrementalFind();
|
stopIncrementalFind();
|
||||||
if (g.returnToMode != CommandMode && g.currentCommand.isEmpty() && m_mode != ExMode) {
|
if (m_mode == CommandMode && g.returnToMode != CommandMode && g.currentCommand.isEmpty()) {
|
||||||
// Return to insert mode.
|
// Return to insert mode.
|
||||||
resetCommandMode();
|
resetCommandMode();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
@@ -1962,18 +1964,8 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
|||||||
// Position changed externally, e.g. by code completion.
|
// Position changed externally, e.g. by code completion.
|
||||||
if (position() != m_oldPosition) {
|
if (position() != m_oldPosition) {
|
||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
//qDebug() << "POSITION CHANGED EXTERNALLY";
|
if (atEndOfLine() && !isVisualMode() && m_mode != InsertMode && m_mode != ReplaceMode)
|
||||||
if (m_mode == InsertMode) {
|
moveLeft();
|
||||||
int dist = position() - m_oldPosition;
|
|
||||||
// Try to compensate for code completion
|
|
||||||
if (dist > 0 && dist <= physicalCursorColumn()) {
|
|
||||||
Range range(m_oldPosition, position());
|
|
||||||
m_lastInsertion.append(selectText(range));
|
|
||||||
}
|
|
||||||
} else if (!isVisualMode()) {
|
|
||||||
if (atEndOfLine())
|
|
||||||
moveLeft();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor tc = cursor();
|
QTextCursor tc = cursor();
|
||||||
@@ -2095,6 +2087,29 @@ void FakeVimHandler::Private::exportSelection()
|
|||||||
m_oldExternalAnchor = anchor();
|
m_oldExternalAnchor = anchor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::recordInsertion(const QString &insert)
|
||||||
|
{
|
||||||
|
const int pos = position();
|
||||||
|
|
||||||
|
if (insert.isNull()) {
|
||||||
|
const int dist = pos - m_oldPosition;
|
||||||
|
|
||||||
|
if (dist > 0) {
|
||||||
|
Range range(m_oldPosition, pos);
|
||||||
|
QString text = selectText(range);
|
||||||
|
// escape text like <ESC>
|
||||||
|
text.replace("<", "<LT>");
|
||||||
|
m_lastInsertion.append(text);
|
||||||
|
} else if (dist < 0) {
|
||||||
|
m_lastInsertion.resize(m_lastInsertion.size() + dist);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_lastInsertion += insert;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_oldPosition = position();
|
||||||
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::ensureCursorVisible()
|
void FakeVimHandler::Private::ensureCursorVisible()
|
||||||
{
|
{
|
||||||
int pos = position();
|
int pos = position();
|
||||||
@@ -2628,6 +2643,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
|
|||||||
insertAutomaticIndentation(true);
|
insertAutomaticIndentation(true);
|
||||||
endEditBlock();
|
endEditBlock();
|
||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
|
m_lastInsertion.clear();
|
||||||
g.returnToMode = InsertMode;
|
g.returnToMode = InsertMode;
|
||||||
} else if (m_submode == DeleteSubMode) {
|
} else if (m_submode == DeleteSubMode) {
|
||||||
setUndoPosition();
|
setUndoPosition();
|
||||||
@@ -2712,16 +2728,18 @@ void FakeVimHandler::Private::resetCommandMode()
|
|||||||
m_register = '"';
|
m_register = '"';
|
||||||
//m_tc.clearSelection();
|
//m_tc.clearSelection();
|
||||||
m_rangemode = RangeCharMode;
|
m_rangemode = RangeCharMode;
|
||||||
if (isNoVisualMode())
|
|
||||||
setAnchor();
|
|
||||||
g.currentCommand.clear();
|
g.currentCommand.clear();
|
||||||
if (g.returnToMode != CommandMode) {
|
if (g.returnToMode != CommandMode) {
|
||||||
|
const QString lastInsertion = m_lastInsertion;
|
||||||
if (g.returnToMode == InsertMode)
|
if (g.returnToMode == InsertMode)
|
||||||
enterInsertMode();
|
enterInsertMode();
|
||||||
else
|
else
|
||||||
enterReplaceMode();
|
enterReplaceMode();
|
||||||
|
m_lastInsertion = lastInsertion;
|
||||||
moveToTargetColumn();
|
moveToTargetColumn();
|
||||||
}
|
}
|
||||||
|
if (isNoVisualMode())
|
||||||
|
setAnchor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::updateSelection()
|
void FakeVimHandler::Private::updateSelection()
|
||||||
@@ -3383,11 +3401,10 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
} else if ((!isVisualMode() && input.is('a')) || (isVisualMode() && input.is('A'))) {
|
} else if ((!isVisualMode() && input.is('a')) || (isVisualMode() && input.is('A'))) {
|
||||||
leaveVisualMode();
|
leaveVisualMode();
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
enterInsertMode();
|
|
||||||
setDotCommand("%1a", count());
|
setDotCommand("%1a", count());
|
||||||
m_lastInsertion.clear();
|
if (!atEndOfLine() && !atEmptyLine())
|
||||||
if (!atEndOfLine())
|
|
||||||
moveRight();
|
moveRight();
|
||||||
|
enterInsertMode();
|
||||||
setUndoPosition();
|
setUndoPosition();
|
||||||
} else if (input.is('A')) {
|
} else if (input.is('A')) {
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
@@ -3396,7 +3413,6 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
setAnchor();
|
setAnchor();
|
||||||
enterInsertMode();
|
enterInsertMode();
|
||||||
setDotCommand("%1A", count());
|
setDotCommand("%1A", count());
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isControl('a')) {
|
} else if (input.isControl('a')) {
|
||||||
changeNumberTextObject(count());
|
changeNumberTextObject(count());
|
||||||
setDotCommand("%1<c-a>", count());
|
setDotCommand("%1<c-a>", count());
|
||||||
@@ -3548,10 +3564,10 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
}
|
}
|
||||||
beginEditBlock();
|
beginEditBlock();
|
||||||
insertText(QString("\n"));
|
insertText(QString("\n"));
|
||||||
m_lastInsertion += '\n';
|
|
||||||
if (!appendLine)
|
if (!appendLine)
|
||||||
moveUp();
|
moveUp();
|
||||||
insertAutomaticIndentation(insertAfter);
|
insertAutomaticIndentation(insertAfter);
|
||||||
|
recordInsertion(QString("\n"));
|
||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
endEditBlock();
|
endEditBlock();
|
||||||
} else if (input.isControl('o')) {
|
} else if (input.isControl('o')) {
|
||||||
@@ -3758,7 +3774,6 @@ bool FakeVimHandler::Private::handleChangeDeleteSubModes(const Input &input)
|
|||||||
const int pos = lastPositionInLine(line + count() - 1);
|
const int pos = lastPositionInLine(line + count() - 1);
|
||||||
setAnchorAndPosition(anc, pos);
|
setAnchorAndPosition(anc, pos);
|
||||||
if (m_submode == ChangeSubMode) {
|
if (m_submode == ChangeSubMode) {
|
||||||
m_lastInsertion.clear();
|
|
||||||
setDotCommand("%1cc", count());
|
setDotCommand("%1cc", count());
|
||||||
} else {
|
} else {
|
||||||
setDotCommand("%1dd", count());
|
setDotCommand("%1dd", count());
|
||||||
@@ -3967,44 +3982,54 @@ bool FakeVimHandler::Private::handleCapitalZSubMode(const Input &input)
|
|||||||
|
|
||||||
EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input)
|
EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input)
|
||||||
{
|
{
|
||||||
|
bool clearLastInsertion = m_breakEditBlock;
|
||||||
|
if (m_oldPosition != position()) {
|
||||||
|
if (clearLastInsertion) {
|
||||||
|
clearLastInsertion = false;
|
||||||
|
m_lastInsertion = "<INSERT>";
|
||||||
|
}
|
||||||
|
recordInsertion();
|
||||||
|
}
|
||||||
|
|
||||||
if (input.isEscape()) {
|
if (input.isEscape()) {
|
||||||
moveLeft(qMin(1, leftDist()));
|
moveLeft(qMin(1, leftDist()));
|
||||||
setTargetColumn();
|
|
||||||
enterCommandMode();
|
enterCommandMode();
|
||||||
|
g.dotCommand += m_lastInsertion;
|
||||||
|
g.dotCommand += QChar(27);
|
||||||
} else if (input.isKey(Key_Left)) {
|
} else if (input.isKey(Key_Left)) {
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
moveLeft(1);
|
moveLeft(1);
|
||||||
setTargetColumn();
|
|
||||||
} else if (input.isKey(Key_Right)) {
|
} else if (input.isKey(Key_Right)) {
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
moveRight(1);
|
moveRight(1);
|
||||||
setTargetColumn();
|
|
||||||
} else if (input.isKey(Key_Up)) {
|
} else if (input.isKey(Key_Up)) {
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
moveUp(1);
|
moveUp(1);
|
||||||
setTargetColumn();
|
|
||||||
} else if (input.isKey(Key_Down)) {
|
} else if (input.isKey(Key_Down)) {
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
moveDown(1);
|
moveDown(1);
|
||||||
} else if (input.isKey(Key_Insert)) {
|
} else if (input.isKey(Key_Insert)) {
|
||||||
m_mode = InsertMode;
|
m_mode = InsertMode;
|
||||||
|
recordInsertion("<INSERT>");
|
||||||
} else if (input.isControl('o')) {
|
} else if (input.isControl('o')) {
|
||||||
enterCommandMode(ReplaceMode);
|
enterCommandMode(ReplaceMode);
|
||||||
} else {
|
} else {
|
||||||
|
if (clearLastInsertion)
|
||||||
|
m_lastInsertion = "<INSERT>";
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
if (!atEndOfLine()) {
|
if (!atEndOfLine()) {
|
||||||
setAnchor();
|
setAnchor();
|
||||||
moveRight();
|
moveRight();
|
||||||
m_lastDeletion += selectText(Range(position(), anchor()));
|
|
||||||
removeText(currentRange());
|
removeText(currentRange());
|
||||||
}
|
}
|
||||||
const QString text = input.text();
|
const QString text = input.text();
|
||||||
m_lastInsertion += text;
|
|
||||||
setAnchor();
|
setAnchor();
|
||||||
insertText(text);
|
insertText(text);
|
||||||
endEditBlock();
|
endEditBlock();
|
||||||
setTargetColumn();
|
recordInsertion();
|
||||||
}
|
}
|
||||||
|
m_oldPosition = position();
|
||||||
|
setTargetColumn();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
|
|
||||||
return EventHandled;
|
return EventHandled;
|
||||||
@@ -4012,9 +4037,17 @@ EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input)
|
|||||||
|
|
||||||
EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
||||||
{
|
{
|
||||||
//const int key = input.key;
|
bool clearLastInsertion = m_breakEditBlock;
|
||||||
//const QString &text = input.text;
|
if (m_oldPosition != position()) {
|
||||||
|
if (clearLastInsertion) {
|
||||||
|
clearLastInsertion = false;
|
||||||
|
m_lastInsertion.clear();
|
||||||
|
}
|
||||||
|
recordInsertion();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString insert;
|
||||||
|
bool move = false;
|
||||||
if (input.isEscape()) {
|
if (input.isEscape()) {
|
||||||
if (isVisualBlockMode() && !m_lastInsertion.contains('\n')) {
|
if (isVisualBlockMode() && !m_lastInsertion.contains('\n')) {
|
||||||
leaveVisualMode();
|
leaveVisualMode();
|
||||||
@@ -4022,7 +4055,6 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
moveLeft(m_lastInsertion.size());
|
moveLeft(m_lastInsertion.size());
|
||||||
setAnchor();
|
setAnchor();
|
||||||
int pos = position();
|
int pos = position();
|
||||||
setTargetColumn();
|
|
||||||
for (int i = 0; i < m_visualInsertCount; ++i) {
|
for (int i = 0; i < m_visualInsertCount; ++i) {
|
||||||
moveDown();
|
moveDown();
|
||||||
insertText(m_lastInsertion);
|
insertText(m_lastInsertion);
|
||||||
@@ -4039,23 +4071,19 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
const int repeat = count();
|
const int repeat = count();
|
||||||
if (repeat > 1) {
|
if (repeat > 1) {
|
||||||
const QString text = m_lastInsertion;
|
const QString text = m_lastInsertion;
|
||||||
for (int i = 1; i < repeat; ++i) {
|
m_lastInsertion.clear();
|
||||||
m_lastInsertion.truncate(0);
|
for (int i = 1; i < repeat; ++i)
|
||||||
foreach (const QChar &c, text)
|
replay(text);
|
||||||
handleInsertMode(Input(c));
|
|
||||||
}
|
|
||||||
m_lastInsertion = text;
|
m_lastInsertion = text;
|
||||||
}
|
}
|
||||||
moveLeft(qMin(1, leftDist()));
|
moveLeft(qMin(1, leftDist()));
|
||||||
setTargetColumn();
|
|
||||||
leaveVisualMode();
|
leaveVisualMode();
|
||||||
breakEditBlock();
|
breakEditBlock();
|
||||||
}
|
}
|
||||||
// If command is 'o' or 'O' don't include the first line feed in dot command.
|
// If command is 'o' or 'O' don't include the first line feed in dot command.
|
||||||
if (g.dotCommand.endsWith(QChar('o'), Qt::CaseInsensitive))
|
if (g.dotCommand.endsWith(QChar('o'), Qt::CaseInsensitive))
|
||||||
m_lastInsertion.remove(0, 1);
|
m_lastInsertion.remove(0, 1);
|
||||||
g.dotCommand += m_lastInsertion;
|
g.dotCommand += m_lastInsertion + "<ESC>";
|
||||||
g.dotCommand += QChar(27);
|
|
||||||
enterCommandMode();
|
enterCommandMode();
|
||||||
m_ctrlVActive = false;
|
m_ctrlVActive = false;
|
||||||
m_opcount.clear();
|
m_opcount.clear();
|
||||||
@@ -4066,6 +4094,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
enterCommandMode(InsertMode);
|
enterCommandMode(InsertMode);
|
||||||
} else if (input.isControl('v')) {
|
} else if (input.isControl('v')) {
|
||||||
m_ctrlVActive = true;
|
m_ctrlVActive = true;
|
||||||
|
insert = "<C-V>";
|
||||||
} else if (input.isControl('w')) {
|
} else if (input.isControl('w')) {
|
||||||
const int blockNumber = cursor().blockNumber();
|
const int blockNumber = cursor().blockNumber();
|
||||||
const int endPos = position();
|
const int endPos = position();
|
||||||
@@ -4075,61 +4104,47 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
const int beginPos = position();
|
const int beginPos = position();
|
||||||
Range range(beginPos, endPos, RangeCharMode);
|
Range range(beginPos, endPos, RangeCharMode);
|
||||||
removeText(range);
|
removeText(range);
|
||||||
setTargetColumn();
|
insert = "<C-W>";
|
||||||
} else if (input.isKey(Key_Insert)) {
|
} else if (input.isKey(Key_Insert)) {
|
||||||
m_mode = ReplaceMode;
|
m_mode = ReplaceMode;
|
||||||
|
insert = "<INSERT>";
|
||||||
} else if (input.isKey(Key_Left)) {
|
} else if (input.isKey(Key_Left)) {
|
||||||
moveLeft(count());
|
moveLeft(count());
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isControl(Key_Left)) {
|
} else if (input.isControl(Key_Left)) {
|
||||||
moveToNextWordStart(count(), false, false);
|
moveToNextWordStart(count(), false, false);
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_Down)) {
|
} else if (input.isKey(Key_Down)) {
|
||||||
//removeAutomaticIndentation();
|
//removeAutomaticIndentation();
|
||||||
m_submode = NoSubMode;
|
m_submode = NoSubMode;
|
||||||
moveDown(count());
|
moveDown(count());
|
||||||
breakEditBlock();
|
move = true;
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_Up)) {
|
} else if (input.isKey(Key_Up)) {
|
||||||
//removeAutomaticIndentation();
|
//removeAutomaticIndentation();
|
||||||
m_submode = NoSubMode;
|
m_submode = NoSubMode;
|
||||||
moveUp(count());
|
moveUp(count());
|
||||||
breakEditBlock();
|
move = true;
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_Right)) {
|
} else if (input.isKey(Key_Right)) {
|
||||||
moveRight(count());
|
moveRight(count());
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isControl(Key_Right)) {
|
} else if (input.isControl(Key_Right)) {
|
||||||
moveToNextWordStart(count(), false, true);
|
moveToNextWordStart(count(), false, true);
|
||||||
moveRight(); // we need one more move since we are in insert mode
|
moveRight(); // we need one more move since we are in insert mode
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_Home)) {
|
} else if (input.isKey(Key_Home)) {
|
||||||
moveToStartOfLine();
|
moveToStartOfLine();
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_End)) {
|
} else if (input.isKey(Key_End)) {
|
||||||
if (count() > 1)
|
if (count() > 1)
|
||||||
moveDown(count() - 1);
|
moveDown(count() - 1);
|
||||||
moveBehindEndOfLine();
|
moveBehindEndOfLine();
|
||||||
setTargetColumn();
|
move = true;
|
||||||
breakEditBlock();
|
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isReturn() || input.isControl('j') || input.isControl('m')) {
|
} else if (input.isReturn() || input.isControl('j') || input.isControl('m')) {
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
m_submode = NoSubMode;
|
m_submode = NoSubMode;
|
||||||
insertText(QString("\n"));
|
insertText(QString("\n"));
|
||||||
m_lastInsertion += '\n';
|
insert = "\n";
|
||||||
insertAutomaticIndentation(true);
|
insertAutomaticIndentation(true);
|
||||||
setTargetColumn();
|
|
||||||
endEditBlock();
|
endEditBlock();
|
||||||
} else if (input.isBackspace()) {
|
} else if (input.isBackspace()) {
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
@@ -4149,29 +4164,25 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
setLineContents(line, prefix + data.mid(col.physical));
|
setLineContents(line, prefix + data.mid(col.physical));
|
||||||
moveToStartOfLine();
|
moveToStartOfLine();
|
||||||
moveRight(prefix.size());
|
moveRight(prefix.size());
|
||||||
m_lastInsertion.clear(); // FIXME
|
|
||||||
} else {
|
} else {
|
||||||
setAnchor();
|
setAnchor();
|
||||||
cursor().deletePreviousChar();
|
cursor().deletePreviousChar();
|
||||||
m_lastInsertion.chop(1);
|
|
||||||
}
|
}
|
||||||
setTargetColumn();
|
|
||||||
}
|
}
|
||||||
|
insert = "<BS>";
|
||||||
endEditBlock();
|
endEditBlock();
|
||||||
} else if (input.isKey(Key_Delete)) {
|
} else if (input.isKey(Key_Delete)) {
|
||||||
setAnchor();
|
setAnchor();
|
||||||
cursor().deleteChar();
|
cursor().deleteChar();
|
||||||
m_lastInsertion.clear();
|
insert = "<DELETE>";
|
||||||
} else if (input.isKey(Key_PageDown) || input.isControl('f')) {
|
} else if (input.isKey(Key_PageDown) || input.isControl('f')) {
|
||||||
removeAutomaticIndentation();
|
removeAutomaticIndentation();
|
||||||
moveDown(count() * (linesOnScreen() - 2));
|
moveDown(count() * (linesOnScreen() - 2));
|
||||||
breakEditBlock();
|
move = true;
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_PageUp) || input.isControl('b')) {
|
} else if (input.isKey(Key_PageUp) || input.isControl('b')) {
|
||||||
removeAutomaticIndentation();
|
removeAutomaticIndentation();
|
||||||
moveUp(count() * (linesOnScreen() - 2));
|
moveUp(count() * (linesOnScreen() - 2));
|
||||||
breakEditBlock();
|
move = true;
|
||||||
m_lastInsertion.clear();
|
|
||||||
} else if (input.isKey(Key_Tab)) {
|
} else if (input.isKey(Key_Tab)) {
|
||||||
m_justAutoIndented = 0;
|
m_justAutoIndented = 0;
|
||||||
if (hasConfig(ConfigExpandTab)) {
|
if (hasConfig(ConfigExpandTab)) {
|
||||||
@@ -4180,10 +4191,10 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
QString str = QString(ts - col % ts, ' ');
|
QString str = QString(ts - col % ts, ' ');
|
||||||
m_lastInsertion.append(str);
|
m_lastInsertion.append(str);
|
||||||
insertText(str);
|
insertText(str);
|
||||||
setTargetColumn();
|
|
||||||
} else {
|
} else {
|
||||||
insertInInsertMode(input.raw());
|
insertInInsertMode(input.raw());
|
||||||
}
|
}
|
||||||
|
insert = "\t";
|
||||||
} else if (input.isControl('d')) {
|
} else if (input.isControl('d')) {
|
||||||
// remove one level of indentation from the current line
|
// remove one level of indentation from the current line
|
||||||
int shift = config(ConfigShiftWidth).toInt();
|
int shift = config(ConfigShiftWidth).toInt();
|
||||||
@@ -4202,6 +4213,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
removeText(Range(pos, pos+i));
|
removeText(Range(pos, pos+i));
|
||||||
|
insert = "<C-D>";
|
||||||
//} else if (key >= control('a') && key <= control('z')) {
|
//} else if (key >= control('a') && key <= control('z')) {
|
||||||
// // ignore these
|
// // ignore these
|
||||||
} else if (input.isControl('p') || input.isControl('n')) {
|
} else if (input.isControl('p') || input.isControl('n')) {
|
||||||
@@ -4210,13 +4222,29 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
|
|||||||
QString str = selectText(Range(position(), tc.position()));
|
QString str = selectText(Range(position(), tc.position()));
|
||||||
setCursor(tc);
|
setCursor(tc);
|
||||||
emit q->simpleCompletionRequested(str, input.isControl('n'));
|
emit q->simpleCompletionRequested(str, input.isControl('n'));
|
||||||
|
if (input.isControl('p'))
|
||||||
|
insert = "<C-P>";
|
||||||
|
else
|
||||||
|
insert = "<C-N>";
|
||||||
} else if (!input.text().isEmpty()) {
|
} else if (!input.text().isEmpty()) {
|
||||||
insertInInsertMode(input.text());
|
insert = input.text();
|
||||||
|
insertInInsertMode(insert);
|
||||||
} else {
|
} else {
|
||||||
// We don't want fancy stuff in insert mode.
|
// We don't want fancy stuff in insert mode.
|
||||||
return EventHandled;
|
return EventHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (move) {
|
||||||
|
breakEditBlock();
|
||||||
|
m_oldPosition = position();
|
||||||
|
} else {
|
||||||
|
if (clearLastInsertion)
|
||||||
|
m_lastInsertion.clear();
|
||||||
|
recordInsertion(insert);
|
||||||
|
}
|
||||||
|
setTargetColumn();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
|
|
||||||
return EventHandled;
|
return EventHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4224,7 +4252,6 @@ void FakeVimHandler::Private::insertInInsertMode(const QString &text)
|
|||||||
{
|
{
|
||||||
joinPreviousEditBlock();
|
joinPreviousEditBlock();
|
||||||
m_justAutoIndented = 0;
|
m_justAutoIndented = 0;
|
||||||
m_lastInsertion.append(text);
|
|
||||||
insertText(text);
|
insertText(text);
|
||||||
if (hasConfig(ConfigSmartIndent) && isElectricCharacter(text.at(0))) {
|
if (hasConfig(ConfigSmartIndent) && isElectricCharacter(text.at(0))) {
|
||||||
const QString leftText = block().text()
|
const QString leftText = block().text()
|
||||||
@@ -6570,7 +6597,7 @@ void FakeVimHandler::Private::enterReplaceMode()
|
|||||||
m_submode = NoSubMode;
|
m_submode = NoSubMode;
|
||||||
m_subsubmode = NoSubSubMode;
|
m_subsubmode = NoSubSubMode;
|
||||||
m_lastInsertion.clear();
|
m_lastInsertion.clear();
|
||||||
m_lastDeletion.clear();
|
m_oldPosition = position();
|
||||||
g.returnToMode = ReplaceMode;
|
g.returnToMode = ReplaceMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6580,7 +6607,7 @@ void FakeVimHandler::Private::enterInsertMode()
|
|||||||
m_submode = NoSubMode;
|
m_submode = NoSubMode;
|
||||||
m_subsubmode = NoSubSubMode;
|
m_subsubmode = NoSubSubMode;
|
||||||
m_lastInsertion.clear();
|
m_lastInsertion.clear();
|
||||||
m_lastDeletion.clear();
|
m_oldPosition = position();
|
||||||
g.returnToMode = InsertMode;
|
g.returnToMode = InsertMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ private slots:
|
|||||||
void test_vim_letter_case();
|
void test_vim_letter_case();
|
||||||
void test_vim_code_autoindent();
|
void test_vim_code_autoindent();
|
||||||
void test_vim_code_folding();
|
void test_vim_code_folding();
|
||||||
|
void test_vim_code_completion();
|
||||||
void test_vim_substitute();
|
void test_vim_substitute();
|
||||||
void test_vim_ex_yank();
|
void test_vim_ex_yank();
|
||||||
void test_vim_ex_delete();
|
void test_vim_ex_delete();
|
||||||
|
|||||||
Reference in New Issue
Block a user