forked from qt-creator/qt-creator
fakevim: Restore last selection with proper position
Command 'gv' restores proper position in selection -- except in visual
line mode ('V') only positions at beginning and end are supported.
Change-Id: I0810808606c340b5c18fe7551a2d5fda29abfeca
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -250,6 +250,8 @@ struct CursorPosition
|
|||||||
column = position - block.position();
|
column = position - block.position();
|
||||||
}
|
}
|
||||||
bool isValid() const { return line >= 0 && column >= 0; }
|
bool isValid() const { return line >= 0 && column >= 0; }
|
||||||
|
bool operator>(const CursorPosition &other) const
|
||||||
|
{ return line > other.line || column > other.column; }
|
||||||
bool operator==(const CursorPosition &other) const
|
bool operator==(const CursorPosition &other) const
|
||||||
{ return line == other.line && column == other.column; }
|
{ return line == other.line && column == other.column; }
|
||||||
bool operator!=(const CursorPosition &other) const { return !operator==(other); }
|
bool operator!=(const CursorPosition &other) const { return !operator==(other); }
|
||||||
@@ -278,15 +280,18 @@ typedef QHashIterator<QChar, Mark> MarksIterator;
|
|||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
State() : revision(-1), position(), marks(), lastVisualMode(NoVisualMode) {}
|
State() : revision(-1), position(), marks(), lastVisualMode(NoVisualMode),
|
||||||
|
lastVisualModeInverted(false) {}
|
||||||
State(int revision, const CursorPosition &position, const Marks &marks,
|
State(int revision, const CursorPosition &position, const Marks &marks,
|
||||||
VisualMode lastVisualMode) : revision(revision), position(position), marks(marks),
|
VisualMode lastVisualMode, bool lastVisualModeInverted) : revision(revision),
|
||||||
lastVisualMode(lastVisualMode) {}
|
position(position), marks(marks), lastVisualMode(lastVisualMode),
|
||||||
|
lastVisualModeInverted(lastVisualModeInverted) {}
|
||||||
|
|
||||||
int revision;
|
int revision;
|
||||||
CursorPosition position;
|
CursorPosition position;
|
||||||
Marks marks;
|
Marks marks;
|
||||||
VisualMode lastVisualMode;
|
VisualMode lastVisualMode;
|
||||||
|
bool lastVisualModeInverted;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Column
|
struct Column
|
||||||
@@ -1689,6 +1694,7 @@ public:
|
|||||||
void leaveVisualMode();
|
void leaveVisualMode();
|
||||||
VisualMode m_visualMode;
|
VisualMode m_visualMode;
|
||||||
VisualMode m_lastVisualMode;
|
VisualMode m_lastVisualMode;
|
||||||
|
bool m_lastVisualModeInverted;
|
||||||
|
|
||||||
// marks
|
// marks
|
||||||
Mark mark(QChar code) const;
|
Mark mark(QChar code) const;
|
||||||
@@ -1848,6 +1854,7 @@ void FakeVimHandler::Private::init()
|
|||||||
m_gflag = false;
|
m_gflag = false;
|
||||||
m_visualMode = NoVisualMode;
|
m_visualMode = NoVisualMode;
|
||||||
m_lastVisualMode = NoVisualMode;
|
m_lastVisualMode = NoVisualMode;
|
||||||
|
m_lastVisualModeInverted = false;
|
||||||
m_targetColumn = 0;
|
m_targetColumn = 0;
|
||||||
m_visualTargetColumn = 0;
|
m_visualTargetColumn = 0;
|
||||||
m_movetype = MoveInclusive;
|
m_movetype = MoveInclusive;
|
||||||
@@ -2454,7 +2461,8 @@ void FakeVimHandler::Private::setUndoPosition(bool overwrite)
|
|||||||
setMark('<', mark('<').position);
|
setMark('<', mark('<').position);
|
||||||
setMark('>', mark('>').position);
|
setMark('>', mark('>').position);
|
||||||
}
|
}
|
||||||
m_undo.push(State(rev, m_lastChangePosition, m_marks, m_lastVisualMode));
|
m_undo.push(
|
||||||
|
State(rev, m_lastChangePosition, m_marks, m_lastVisualMode, m_lastVisualModeInverted));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::moveDown(int n)
|
void FakeVimHandler::Private::moveDown(int n)
|
||||||
@@ -3643,9 +3651,9 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
CursorPosition from = mark('<').position;
|
CursorPosition from = mark('<').position;
|
||||||
CursorPosition to = mark('>').position;
|
CursorPosition to = mark('>').position;
|
||||||
toggleVisualMode(m_lastVisualMode);
|
toggleVisualMode(m_lastVisualMode);
|
||||||
setCursorPosition(from);
|
setCursorPosition(m_lastVisualModeInverted ? to : from);
|
||||||
setAnchor();
|
setAnchor();
|
||||||
setCursorPosition(to);
|
setCursorPosition(m_lastVisualModeInverted ? from : to);
|
||||||
}
|
}
|
||||||
} else if (input.is('v')) {
|
} else if (input.is('v')) {
|
||||||
toggleVisualMode(VisualCharMode);
|
toggleVisualMode(VisualCharMode);
|
||||||
@@ -6458,6 +6466,7 @@ void FakeVimHandler::Private::leaveVisualMode()
|
|||||||
|
|
||||||
setMark('<', mark('<').position);
|
setMark('<', mark('<').position);
|
||||||
setMark('>', mark('>').position);
|
setMark('>', mark('>').position);
|
||||||
|
m_lastVisualModeInverted = anchor() > position();
|
||||||
if (isVisualLineMode())
|
if (isVisualLineMode())
|
||||||
m_movetype = MoveLineWise;
|
m_movetype = MoveLineWise;
|
||||||
else if (isVisualCharMode())
|
else if (isVisualCharMode())
|
||||||
@@ -6560,6 +6569,7 @@ void FakeVimHandler::Private::undoRedo(bool undo)
|
|||||||
marks.swap(state.marks);
|
marks.swap(state.marks);
|
||||||
updateMarks(marks);
|
updateMarks(marks);
|
||||||
m_lastVisualMode = state.lastVisualMode;
|
m_lastVisualMode = state.lastVisualMode;
|
||||||
|
m_lastVisualModeInverted = state.lastVisualModeInverted;
|
||||||
setMark('\'', lastPos);
|
setMark('\'', lastPos);
|
||||||
setCursorPosition(m_lastChangePosition);
|
setCursorPosition(m_lastChangePosition);
|
||||||
setAnchor();
|
setAnchor();
|
||||||
|
|||||||
Reference in New Issue
Block a user