fakevim: fix backspace in the presence of physical tabs

(cherry picked from commit 2b40e2906fc070c6253a84c0ca507ff0db912f73)
This commit is contained in:
hjk
2010-07-06 16:17:27 +02:00
parent cd433a52de
commit 312509fcdb

View File

@@ -232,6 +232,11 @@ struct Column
int logical; // Column on screen. int logical; // Column on screen.
}; };
QDebug operator<<(QDebug ts, const Column &col)
{
return ts << "(p: " << col.physical << ", l: " << col.logical << ")";
}
struct CursorPosition struct CursorPosition
{ {
// for jump history // for jump history
@@ -2619,11 +2624,11 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
if (col.logical <= ind.logical && col.logical if (col.logical <= ind.logical && col.logical
&& startsWithWhitespace(data, col.physical)) { && startsWithWhitespace(data, col.physical)) {
const int ts = config(ConfigTabStop).toInt(); const int ts = config(ConfigTabStop).toInt();
const int newcol = col.logical - 1 - (col.logical - 1) % ts; const int newl = col.logical - 1 - (col.logical - 1) % ts;
data.remove(0, col.physical); const QString prefix = tabExpand(newl);
setLineContents(line, tabExpand(newcol).append(data)); setLineContents(line, prefix + data.mid(col.physical));
moveToStartOfLine(); moveToStartOfLine();
moveRight(newcol); moveRight(prefix.size());
m_lastInsertion.clear(); // FIXME m_lastInsertion.clear(); // FIXME
} else { } else {
m_tc.deletePreviousChar(); m_tc.deletePreviousChar();
@@ -4303,10 +4308,12 @@ void FakeVimHandler::Private::setLineContents(int line, const QString &contents)
{ {
QTextBlock block = m_tc.document()->findBlockByNumber(line - 1); QTextBlock block = m_tc.document()->findBlockByNumber(line - 1);
QTextCursor tc = m_tc; QTextCursor tc = m_tc;
tc.setPosition(block.position()); const int begin = block.position();
tc.setPosition(block.position() + block.length() - 1, KeepAnchor); const int len = block.length();
tc.setPosition(begin);
tc.setPosition(begin + len - 1, KeepAnchor);
tc.removeSelectedText(); tc.removeSelectedText();
fixMarks(block.position(), block.length() - contents.size()); fixMarks(begin, contents.size() + 1 - len);
tc.insertText(contents); tc.insertText(contents);
} }