Commit 08a1171e authored by hjk's avatar hjk
Browse files

fakevim: fix two backspace-with-autoindent issues

Backspacing across start of line was broken, and it always removed all
automatically indented whitespace.
parent 8bb90d47
...@@ -265,6 +265,17 @@ QString quoteUnprintable(const QString &ba) ...@@ -265,6 +265,17 @@ QString quoteUnprintable(const QString &ba)
return res; return res;
} }
static bool startsWithWhitespace(const QString &str, int col)
{
QTC_ASSERT(str.size() >= col, return false);
for (int i = 0; i < col; ++i) {
uint u = str.at(i).unicode();
if (u != ' ' && u != '\t')
return false;
}
return true;
}
inline QString msgE20MarkNotSet(const QString &text) inline QString msgE20MarkNotSet(const QString &text)
{ {
return FakeVimHandler::tr("E20: Mark '%1' not set").arg(text); return FakeVimHandler::tr("E20: Mark '%1' not set").arg(text);
...@@ -1996,26 +2007,23 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, ...@@ -1996,26 +2007,23 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
setTargetColumn(); setTargetColumn();
} else if (key == Key_Backspace || key == control('h')) { } else if (key == Key_Backspace || key == control('h')) {
joinPreviousEditBlock(); joinPreviousEditBlock();
if (!removeAutomaticIndentation() m_justAutoIndented = 0;
&& (!m_lastInsertion.isEmpty() if (!m_lastInsertion.isEmpty() || hasConfig(ConfigBackspace, "start")) {
|| hasConfig(ConfigBackspace, "start"))) const int line = cursorLineInDocument() + 1;
{ const int col = cursorColumnInDocument();
int line = cursorLineInDocument() + 1; const QString data = lineContents(line);
int col = cursorColumnInDocument(); const Indentation ind = indentation(data);
QString data = lineContents(line); if (col <= ind.logical && col && startsWithWhitespace(data, col)) {
Indentation ind = indentation(data); const int ts = config(ConfigTabStop).toInt();
if (col <= ind.logical) { const int newcol = col - 1 - (col - 1) % ts;
int ts = config(ConfigTabStop).toInt(); setLineContents(line, tabExpand(newcol) + data.midRef(col));
int newcol = col - 1 - (col - 1) % ts; m_lastInsertion.clear(); // FIXME
data = tabExpand(newcol) + data.mid(col); } else {
setLineContents(line, data); m_tc.deletePreviousChar();
m_lastInsertion.clear(); // FIXME m_lastInsertion.chop(1);
} else {
m_tc.deletePreviousChar();
m_lastInsertion.chop(1);
}
setTargetColumn();
} }
setTargetColumn();
}
endEditBlock(); endEditBlock();
} else if (key == Key_Delete) { } else if (key == Key_Delete) {
m_tc.deleteChar(); m_tc.deleteChar();
......
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