forked from qt-creator/qt-creator
fakevim: make undo of line shifting 'atomic'
This commit is contained in:
@@ -357,6 +357,7 @@ public:
|
|||||||
QChar characterAtCursor() const
|
QChar characterAtCursor() const
|
||||||
{ return m_tc.document()->characterAt(m_tc.position()); }
|
{ return m_tc.document()->characterAt(m_tc.position()); }
|
||||||
void beginEditBlock() { UNDO_DEBUG("BEGIN EDIT BLOCK"); m_tc.beginEditBlock(); }
|
void beginEditBlock() { UNDO_DEBUG("BEGIN EDIT BLOCK"); m_tc.beginEditBlock(); }
|
||||||
|
void beginEditBlock(int pos) { setUndoPosition(pos); beginEditBlock(); }
|
||||||
void endEditBlock() { UNDO_DEBUG("END EDIT BLOCK"); m_tc.endEditBlock(); }
|
void endEditBlock() { UNDO_DEBUG("END EDIT BLOCK"); m_tc.endEditBlock(); }
|
||||||
void joinPreviousEditBlock() { UNDO_DEBUG("JOIN EDIT BLOCK"); m_tc.joinPreviousEditBlock(); }
|
void joinPreviousEditBlock() { UNDO_DEBUG("JOIN EDIT BLOCK"); m_tc.joinPreviousEditBlock(); }
|
||||||
|
|
||||||
@@ -416,6 +417,7 @@ public:
|
|||||||
// undo handling
|
// undo handling
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
void setUndoPosition(int pos);
|
||||||
QMap<int, int> m_undoCursorPosition; // revision -> position
|
QMap<int, int> m_undoCursorPosition; // revision -> position
|
||||||
|
|
||||||
// extra data for '.'
|
// extra data for '.'
|
||||||
@@ -667,7 +669,7 @@ EventResult FakeVimHandler::Private::handleKey(int key, int unmodified,
|
|||||||
const QString &text)
|
const QString &text)
|
||||||
{
|
{
|
||||||
//qDebug() << " CURSOR POS: " << m_undoCursorPosition;
|
//qDebug() << " CURSOR POS: " << m_undoCursorPosition;
|
||||||
m_undoCursorPosition[m_tc.document()->availableUndoSteps()] = m_tc.position();
|
setUndoPosition(m_tc.position());
|
||||||
//qDebug() << "KEY: " << key << text << "POS: " << m_tc.position();
|
//qDebug() << "KEY: " << key << text << "POS: " << m_tc.position();
|
||||||
if (m_mode == InsertMode)
|
if (m_mode == InsertMode)
|
||||||
return handleInsertMode(key, unmodified, text);
|
return handleInsertMode(key, unmodified, text);
|
||||||
@@ -679,6 +681,12 @@ EventResult FakeVimHandler::Private::handleKey(int key, int unmodified,
|
|||||||
return EventUnhandled;
|
return EventUnhandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::setUndoPosition(int pos)
|
||||||
|
{
|
||||||
|
//qDebug() << " CURSOR POS: " << m_undoCursorPosition;
|
||||||
|
m_undoCursorPosition[m_tc.document()->availableUndoSteps()] = pos;
|
||||||
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::moveDown(int n)
|
void FakeVimHandler::Private::moveDown(int n)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
@@ -2256,10 +2264,12 @@ void FakeVimHandler::Private::shiftRegionRight(int repeat)
|
|||||||
QString indent(len, ' ');
|
QString indent(len, ' ');
|
||||||
int firstPos = firstPositionInLine(beginLine);
|
int firstPos = firstPositionInLine(beginLine);
|
||||||
|
|
||||||
|
beginEditBlock(firstPos);
|
||||||
for (int line = beginLine; line <= endLine; ++line) {
|
for (int line = beginLine; line <= endLine; ++line) {
|
||||||
setPosition(firstPositionInLine(line));
|
setPosition(firstPositionInLine(line));
|
||||||
m_tc.insertText(indent);
|
m_tc.insertText(indent);
|
||||||
}
|
}
|
||||||
|
endEditBlock();
|
||||||
|
|
||||||
setPosition(firstPos);
|
setPosition(firstPos);
|
||||||
moveToFirstNonBlankOnLine();
|
moveToFirstNonBlankOnLine();
|
||||||
@@ -2277,6 +2287,7 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
|
|||||||
int tab = config(ConfigTabStop).toInt();
|
int tab = config(ConfigTabStop).toInt();
|
||||||
int firstPos = firstPositionInLine(beginLine);
|
int firstPos = firstPositionInLine(beginLine);
|
||||||
|
|
||||||
|
beginEditBlock(firstPos);
|
||||||
for (int line = beginLine; line <= endLine; ++line) {
|
for (int line = beginLine; line <= endLine; ++line) {
|
||||||
int pos = firstPositionInLine(line);
|
int pos = firstPositionInLine(line);
|
||||||
setPosition(pos);
|
setPosition(pos);
|
||||||
@@ -2297,6 +2308,7 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
|
|||||||
removeSelectedText();
|
removeSelectedText();
|
||||||
setPosition(pos);
|
setPosition(pos);
|
||||||
}
|
}
|
||||||
|
endEditBlock();
|
||||||
|
|
||||||
setPosition(firstPos);
|
setPosition(firstPos);
|
||||||
moveToFirstNonBlankOnLine();
|
moveToFirstNonBlankOnLine();
|
||||||
|
Reference in New Issue
Block a user