forked from qt-creator/qt-creator
visual feedback for block selection. othewise block selection still does
not work..
This commit is contained in:
@@ -355,26 +355,41 @@ void FakeVimHandler::Private::updateSelection()
|
|||||||
sel.format = m_tc.blockCharFormat();
|
sel.format = m_tc.blockCharFormat();
|
||||||
sel.format.setFontWeight(QFont::Bold);
|
sel.format.setFontWeight(QFont::Bold);
|
||||||
sel.format.setFontUnderline(true);
|
sel.format.setFontUnderline(true);
|
||||||
int pos = m_tc.position();
|
int cursorPos = m_tc.position();
|
||||||
int anchor = m_marks['<'];
|
int anchorPos = m_marks['<'];
|
||||||
//qDebug() << "POS: " << pos << " ANCHOR: " << anchor;
|
//qDebug() << "POS: " << cursorPos << " ANCHOR: " << anchorPos;
|
||||||
if (m_visualMode == VisualCharMode) {
|
if (m_visualMode == VisualCharMode) {
|
||||||
sel.cursor.setPosition(anchor, KeepAnchor);
|
sel.cursor.setPosition(anchorPos, KeepAnchor);
|
||||||
selections.append(sel);
|
selections.append(sel);
|
||||||
} else if (m_visualMode == VisualLineMode) {
|
} else if (m_visualMode == VisualLineMode) {
|
||||||
sel.cursor.setPosition(qMin(pos, anchor), MoveAnchor);
|
sel.cursor.setPosition(qMin(cursorPos, anchorPos), MoveAnchor);
|
||||||
sel.cursor.movePosition(StartOfLine, MoveAnchor);
|
sel.cursor.movePosition(StartOfLine, MoveAnchor);
|
||||||
sel.cursor.setPosition(qMax(pos, anchor), KeepAnchor);
|
sel.cursor.setPosition(qMax(cursorPos, anchorPos), KeepAnchor);
|
||||||
sel.cursor.movePosition(EndOfLine, KeepAnchor);
|
sel.cursor.movePosition(EndOfLine, KeepAnchor);
|
||||||
selections.append(sel);
|
selections.append(sel);
|
||||||
} else if (m_visualMode == VisualBlockMode) {
|
} else if (m_visualMode == VisualBlockMode) {
|
||||||
// FIXME: This shows lines right now...
|
QTextCursor tc = m_tc;
|
||||||
sel.cursor.setPosition(qMin(pos, anchor), MoveAnchor);
|
tc.setPosition(anchorPos);
|
||||||
sel.cursor.movePosition(StartOfLine, MoveAnchor);
|
tc.movePosition(StartOfLine, MoveAnchor);
|
||||||
sel.cursor.setPosition(qMax(pos, anchor), KeepAnchor);
|
QTextBlock anchorBlock = tc.block();
|
||||||
sel.cursor.movePosition(EndOfLine, KeepAnchor);
|
QTextBlock cursorBlock = m_tc.block();
|
||||||
|
int anchorColumn = anchorPos - anchorBlock.position();
|
||||||
|
int cursorColumn = cursorPos - cursorBlock.position();
|
||||||
|
int startColumn = qMin(anchorColumn, cursorColumn);
|
||||||
|
int endColumn = qMax(anchorColumn, cursorColumn);
|
||||||
|
int endPos = cursorBlock.position();
|
||||||
|
while (tc.position() <= endPos) {
|
||||||
|
if (startColumn < tc.block().length() - 1) {
|
||||||
|
int last = qMin(tc.block().length() - 1, endColumn);
|
||||||
|
int len = last - startColumn + 1;
|
||||||
|
sel.cursor = tc;
|
||||||
|
sel.cursor.movePosition(Right, MoveAnchor, startColumn);
|
||||||
|
sel.cursor.movePosition(Right, KeepAnchor, len);
|
||||||
selections.append(sel);
|
selections.append(sel);
|
||||||
}
|
}
|
||||||
|
tc.movePosition(Down, MoveAnchor, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EDITOR(setExtraSelections(selections));
|
EDITOR(setExtraSelections(selections));
|
||||||
}
|
}
|
||||||
@@ -1196,6 +1211,7 @@ void FakeVimHandler::Private::enterVisualMode(VisualMode visualMode)
|
|||||||
m_visualMode = visualMode;
|
m_visualMode = visualMode;
|
||||||
m_marks['<'] = m_tc.position();
|
m_marks['<'] = m_tc.position();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
|
updateSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::leaveVisualMode()
|
void FakeVimHandler::Private::leaveVisualMode()
|
||||||
@@ -1203,6 +1219,7 @@ void FakeVimHandler::Private::leaveVisualMode()
|
|||||||
m_visualMode = NoVisualMode;
|
m_visualMode = NoVisualMode;
|
||||||
m_marks['>'] = m_tc.position();
|
m_marks['>'] = m_tc.position();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
|
updateSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *FakeVimHandler::Private::editor() const
|
QWidget *FakeVimHandler::Private::editor() const
|
||||||
|
|||||||
Reference in New Issue
Block a user