forked from qt-creator/qt-creator
'd' works, but no visual feedback so far
This commit is contained in:
@@ -132,7 +132,8 @@ public:
|
|||||||
bool atEol() const { return m_tc.atBlockEnd() && m_tc.block().length()>1; }
|
bool atEol() const { return m_tc.atBlockEnd() && m_tc.block().length()>1; }
|
||||||
|
|
||||||
int lastPositionInDocument() const;
|
int lastPositionInDocument() const;
|
||||||
int positionForLine(int line) const; // 1 based
|
int positionForLine(int line) const; // 1 based line, 0 based pos
|
||||||
|
int lineForPosition(int pos) const; // 1 based line, 0 based pos
|
||||||
|
|
||||||
// all zero-based counting
|
// all zero-based counting
|
||||||
int cursorLineOnScreen() const;
|
int cursorLineOnScreen() const;
|
||||||
@@ -184,15 +185,20 @@ public:
|
|||||||
bool m_lastSearchForward;
|
bool m_lastSearchForward;
|
||||||
QString m_lastInsertion;
|
QString m_lastInsertion;
|
||||||
|
|
||||||
// History for '/'
|
// history for '/'
|
||||||
QString lastSearchString() const;
|
QString lastSearchString() const;
|
||||||
QStringList m_searchHistory;
|
QStringList m_searchHistory;
|
||||||
int m_searchHistoryIndex;
|
int m_searchHistoryIndex;
|
||||||
|
|
||||||
// History for ':'
|
// history for ':'
|
||||||
QStringList m_commandHistory;
|
QStringList m_commandHistory;
|
||||||
int m_commandHistoryIndex;
|
int m_commandHistoryIndex;
|
||||||
|
|
||||||
|
// visual line mode
|
||||||
|
void enterVisualLineMode();
|
||||||
|
void leaveVisualLineMode();
|
||||||
|
bool m_visualLineMode;
|
||||||
|
|
||||||
// marks as lines
|
// marks as lines
|
||||||
QHash<int, int> m_marks;
|
QHash<int, int> m_marks;
|
||||||
|
|
||||||
@@ -214,6 +220,7 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent)
|
|||||||
m_gflag = false;
|
m_gflag = false;
|
||||||
m_textedit = 0;
|
m_textedit = 0;
|
||||||
m_plaintextedit = 0;
|
m_plaintextedit = 0;
|
||||||
|
m_visualLineMode = false;
|
||||||
|
|
||||||
m_config[ConfigStartOfLine] = ConfigOn;
|
m_config[ConfigStartOfLine] = ConfigOn;
|
||||||
}
|
}
|
||||||
@@ -292,7 +299,12 @@ void FakeVimHandler::Private::updateMiniBuffer()
|
|||||||
if (m_tc.isNull())
|
if (m_tc.isNull())
|
||||||
return;
|
return;
|
||||||
QString msg;
|
QString msg;
|
||||||
if (m_currentMessage.isEmpty()) {
|
if (!m_currentMessage.isEmpty()) {
|
||||||
|
msg = m_currentMessage;
|
||||||
|
m_currentMessage.clear();
|
||||||
|
} else if (m_visualLineMode) {
|
||||||
|
msg = "-- VISUAL LINE--";
|
||||||
|
} else {
|
||||||
msg = QChar(m_commandCode ? m_commandCode : ' ');
|
msg = QChar(m_commandCode ? m_commandCode : ' ');
|
||||||
for (int i = 0; i != m_commandBuffer.size(); ++i) {
|
for (int i = 0; i != m_commandBuffer.size(); ++i) {
|
||||||
QChar c = m_commandBuffer.at(i);
|
QChar c = m_commandBuffer.at(i);
|
||||||
@@ -303,9 +315,6 @@ void FakeVimHandler::Private::updateMiniBuffer()
|
|||||||
msg += c;
|
msg += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
msg = m_currentMessage;
|
|
||||||
m_currentMessage.clear();
|
|
||||||
}
|
}
|
||||||
int l = cursorLineInDocument();
|
int l = cursorLineInDocument();
|
||||||
int w = columnsOnScreen();
|
int w = columnsOnScreen();
|
||||||
@@ -433,11 +442,19 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
m_tc.movePosition(EndOfLine, KeepAnchor);
|
m_tc.movePosition(EndOfLine, KeepAnchor);
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (key == 'd') {
|
} else if (key == 'd') {
|
||||||
if (atEol())
|
if (m_visualLineMode) {
|
||||||
m_tc.movePosition(Left, MoveAnchor, 1);
|
leaveVisualLineMode();
|
||||||
m_opcount = m_mvcount;
|
int beginLine = lineForPosition(m_marks['<']);
|
||||||
m_mvcount.clear();
|
int endLine = lineForPosition(m_marks['>']);
|
||||||
m_submode = DeleteSubMode;
|
m_tc = selectRange(beginLine, endLine);
|
||||||
|
m_tc.removeSelectedText();
|
||||||
|
} else {
|
||||||
|
if (atEol())
|
||||||
|
m_tc.movePosition(Left, MoveAnchor, 1);
|
||||||
|
m_opcount = m_mvcount;
|
||||||
|
m_mvcount.clear();
|
||||||
|
m_submode = DeleteSubMode;
|
||||||
|
}
|
||||||
} else if (key == 'D') {
|
} else if (key == 'D') {
|
||||||
m_submode = DeleteSubMode;
|
m_submode = DeleteSubMode;
|
||||||
m_tc.movePosition(Down, KeepAnchor, qMax(count() - 1, 0));
|
m_tc.movePosition(Down, KeepAnchor, qMax(count() - 1, 0));
|
||||||
@@ -559,6 +576,8 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
m_subsubdata = key;
|
m_subsubdata = key;
|
||||||
} else if (key == 'u') {
|
} else if (key == 'u') {
|
||||||
EDITOR(undo());
|
EDITOR(undo());
|
||||||
|
} else if (key == 'V') {
|
||||||
|
enterVisualLineMode();
|
||||||
} else if (key == 'w') {
|
} else if (key == 'w') {
|
||||||
moveToNextWord(false);
|
moveToNextWord(false);
|
||||||
finishMovement();
|
finishMovement();
|
||||||
@@ -599,7 +618,8 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
} else if (key == Key_Delete) {
|
} else if (key == Key_Delete) {
|
||||||
m_tc.deleteChar();
|
m_tc.deleteChar();
|
||||||
} else if (key == Key_Escape) {
|
} else if (key == Key_Escape) {
|
||||||
// harmless
|
if (m_visualLineMode)
|
||||||
|
leaveVisualLineMode();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Ignored" << key << text;
|
qDebug() << "Ignored" << key << text;
|
||||||
}
|
}
|
||||||
@@ -740,6 +760,15 @@ int FakeVimHandler::Private::readLineCode(QString &cmd)
|
|||||||
int n = readLineCode(cmd);
|
int n = readLineCode(cmd);
|
||||||
return cursorLineInDocument() + 1 + (n == -1 ? 1 : n);
|
return cursorLineInDocument() + 1 + (n == -1 ? 1 : n);
|
||||||
}
|
}
|
||||||
|
if (c == '\'' && !cmd.isEmpty()) {
|
||||||
|
int pos = m_marks.value(cmd.at(0).unicode());
|
||||||
|
if (!pos) {
|
||||||
|
showMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
cmd = cmd.mid(1);
|
||||||
|
return lineForPosition(pos);
|
||||||
|
}
|
||||||
if (c.isDigit()) {
|
if (c.isDigit()) {
|
||||||
int n = c.unicode() - '0';
|
int n = c.unicode() - '0';
|
||||||
while (!cmd.isEmpty()) {
|
while (!cmd.isEmpty()) {
|
||||||
@@ -1042,6 +1071,28 @@ int FakeVimHandler::Private::positionForLine(int line) const
|
|||||||
return m_tc.block().document()->findBlockByNumber(line - 1).position();
|
return m_tc.block().document()->findBlockByNumber(line - 1).position();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FakeVimHandler::Private::lineForPosition(int pos) const
|
||||||
|
{
|
||||||
|
QTextCursor tc = m_tc;
|
||||||
|
tc.setPosition(pos);
|
||||||
|
return tc.block().blockNumber() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::enterVisualLineMode()
|
||||||
|
{
|
||||||
|
m_visualLineMode = true;
|
||||||
|
m_marks['<'] = m_tc.position();
|
||||||
|
updateMiniBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::leaveVisualLineMode()
|
||||||
|
{
|
||||||
|
m_visualLineMode = false;
|
||||||
|
m_marks['>'] = m_tc.position();
|
||||||
|
updateMiniBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// FakeVimHandler
|
// FakeVimHandler
|
||||||
|
|||||||
Reference in New Issue
Block a user