Commit 772c2b3c authored by hjk's avatar hjk

fakevim: refactor register handling

Change-Id: If3551627a8457853c0dedee7a61b388ff3232980
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 0e0b356b
......@@ -1016,6 +1016,12 @@ public:
int m_justAutoIndented;
void handleStartOfLine();
// register handling
QString registerContents(int reg) const;
void setRegisterContents(int reg, const QString &contents);
RangeMode registerRangeMode(int reg) const;
void setRegisterRangeMode(int reg, RangeMode mode);
void recordJump();
QVector<CursorPosition> m_jumpListUndo;
QVector<CursorPosition> m_jumpListRedo;
......@@ -1565,7 +1571,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
if (m_submode != TransformSubMode) {
yankText(currentRange(), m_register);
if (m_movetype == MoveLineWise)
g.registers[m_register].rangemode = RangeLineMode;
setRegisterRangeMode(m_register, RangeLineMode);
}
m_positionPastEnd = m_anchorPastEnd = false;
......@@ -2492,7 +2498,7 @@ EventResult FakeVimHandler::Private::handleCommandMode2(const Input &input)
beginEditBlock(position());
moveToFirstNonBlankOnLine();
moveBehindEndOfLine();
insertText(Register("\n"));
insertText(QString("\n"));
insertAutomaticIndentation(true);
endEditBlock();
} else if (input.is('O')) {
......@@ -2503,7 +2509,7 @@ EventResult FakeVimHandler::Private::handleCommandMode2(const Input &input)
beginEditBlock(position());
moveToFirstNonBlankOnLine();
moveToStartOfLine();
insertText(Register("\n"));
insertText(QString("\n"));
moveUp();
insertAutomaticIndentation(false);
endEditBlock();
......@@ -2912,7 +2918,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
m_lastInsertion.clear();
} else if (input.isReturn()) {
m_submode = NoSubMode;
insertText(Register("\n"));
insertText(QString("\n"));
m_lastInsertion += '\n';
insertAutomaticIndentation(true);
setTargetColumn();
......@@ -3441,7 +3447,7 @@ bool FakeVimHandler::Private::handleExRegisterCommand(const ExCommand &cmd)
QString info;
info += "--- Registers ---\n";
foreach (char reg, regs) {
QString value = quoteUnprintable(g.registers[reg].contents);
QString value = quoteUnprintable(registerContents(reg));
info += QString("\"%1 %2\n").arg(reg).arg(value);
}
emit q->extraInformationChanged(info);
......@@ -3512,9 +3518,9 @@ bool FakeVimHandler::Private::handleExDeleteCommand(const ExCommand &cmd)
QString text = selectText(range);
removeText(currentRange());
if (!reg.isEmpty()) {
Register &r = g.registers[reg.at(0).unicode()];
r.contents = text;
r.rangemode = RangeLineMode;
const int r = reg.at(0).unicode();
setRegisterContents(r, text);
setRegisterRangeMode(r, RangeLineMode);
}
return true;
}
......@@ -4424,11 +4430,10 @@ QString FakeVimHandler::Private::selectText(const Range &range) const
return contents;
}
void FakeVimHandler::Private::yankText(const Range &range, int toregister)
void FakeVimHandler::Private::yankText(const Range &range, int reg)
{
Register &reg = g.registers[toregister];
reg.contents = selectText(range);
reg.rangemode = range.rangemode;
setRegisterContents(reg, selectText(range));
setRegisterRangeMode(reg, range.rangemode);
}
void FakeVimHandler::Private::transformText(const Range &range,
......@@ -4576,7 +4581,7 @@ void FakeVimHandler::Private::replaceByCharTransform(TransformationData *td)
void FakeVimHandler::Private::pasteText(bool afterCursor)
{
const QString text = g.registers[m_register].contents;
const QString text = registerContents(m_register);
const QStringList lines = text.split(QChar('\n'));
beginEditBlock();
......@@ -4599,7 +4604,7 @@ void FakeVimHandler::Private::pasteText(bool afterCursor)
setPosition(qMin(position(), anchor()));
}
switch (g.registers[m_register].rangemode) {
switch (registerRangeMode(m_register)) {
case RangeCharMode: {
m_targetColumn = 0;
for (int i = count(); --i >= 0; ) {
......@@ -5008,6 +5013,26 @@ void FakeVimHandler::Private::setMark(int code, int position)
m_marks[code] = tc;
}
void FakeVimHandler::Private::setRegisterRangeMode(int reg, RangeMode mode)
{
g.registers[reg].rangemode = mode;
}
RangeMode FakeVimHandler::Private::registerRangeMode(int reg) const
{
return g.registers[reg].rangemode;
}
void FakeVimHandler::Private::setRegisterContents(int reg, const QString &contents)
{
g.registers[reg].contents = contents;
}
QString FakeVimHandler::Private::registerContents(int reg) const
{
return g.registers[reg].contents;
}
///////////////////////////////////////////////////////////////////////
//
// FakeVimHandler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment