forked from qt-creator/qt-creator
FakeVim: Correct the selection in VisualBlockMode
The selection was not visible when moving cursor up. Reviewed-by: hjk Merge-request: 1016 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
committed by
Oswald Buddenhagen
parent
ec0f5172c9
commit
dd408d10e6
@@ -536,7 +536,8 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
|||||||
//endEditBlock();
|
//endEditBlock();
|
||||||
|
|
||||||
// We fake vi-style end-of-line behaviour
|
// We fake vi-style end-of-line behaviour
|
||||||
m_fakeEnd = (atEndOfLine() && m_mode == CommandMode);
|
m_fakeEnd = (atEndOfLine() && m_mode == CommandMode
|
||||||
|
&& m_visualMode != VisualBlockMode);
|
||||||
|
|
||||||
if (m_fakeEnd)
|
if (m_fakeEnd)
|
||||||
moveLeft();
|
moveLeft();
|
||||||
@@ -774,18 +775,22 @@ void FakeVimHandler::Private::updateSelection()
|
|||||||
} else if (m_visualMode == VisualBlockMode) {
|
} else if (m_visualMode == VisualBlockMode) {
|
||||||
QTextCursor tc = m_tc;
|
QTextCursor tc = m_tc;
|
||||||
tc.setPosition(anchorPos);
|
tc.setPosition(anchorPos);
|
||||||
tc.movePosition(StartOfLine, MoveAnchor);
|
int anchorColumn = tc.columnNumber();
|
||||||
QTextBlock anchorBlock = tc.block();
|
int cursorColumn = m_tc.columnNumber();
|
||||||
QTextBlock cursorBlock = m_tc.block();
|
int anchorRow = tc.blockNumber();
|
||||||
int anchorColumn = anchorPos - anchorBlock.position();
|
int cursorRow = m_tc.blockNumber();
|
||||||
int cursorColumn = cursorPos - cursorBlock.position();
|
|
||||||
int startColumn = qMin(anchorColumn, cursorColumn);
|
int startColumn = qMin(anchorColumn, cursorColumn);
|
||||||
int endColumn = qMax(anchorColumn, cursorColumn);
|
int endColumn = qMax(anchorColumn, cursorColumn);
|
||||||
int endPos = cursorBlock.position();
|
int diffRow = cursorRow - anchorRow;
|
||||||
while (tc.position() <= endPos) {
|
if (anchorRow > cursorRow) {
|
||||||
|
tc.setPosition(cursorPos);
|
||||||
|
diffRow = -diffRow;
|
||||||
|
}
|
||||||
|
tc.movePosition(StartOfLine, MoveAnchor);
|
||||||
|
for (int i = 0; i <= diffRow; ++i) {
|
||||||
if (startColumn < tc.block().length() - 1) {
|
if (startColumn < tc.block().length() - 1) {
|
||||||
int last = qMin(tc.block().length() - 1, endColumn);
|
int last = qMin(tc.block().length(), endColumn + 1);
|
||||||
int len = last - startColumn + 1;
|
int len = last - startColumn;
|
||||||
sel.cursor = tc;
|
sel.cursor = tc;
|
||||||
sel.cursor.movePosition(Right, MoveAnchor, startColumn);
|
sel.cursor.movePosition(Right, MoveAnchor, startColumn);
|
||||||
sel.cursor.movePosition(Right, KeepAnchor, len);
|
sel.cursor.movePosition(Right, KeepAnchor, len);
|
||||||
|
|||||||
Reference in New Issue
Block a user