Fix capture group handling

Fixes #1129
This commit is contained in:
Maxime Coste 2017-01-13 00:17:31 +00:00
parent b157a481e1
commit 4916ea1766
5 changed files with 18 additions and 7 deletions

View File

@ -1240,7 +1240,7 @@ private:
{ {
case InsertMode::Insert: case InsertMode::Insert:
for (auto& sel : selections) for (auto& sel : selections)
sel = Selection{sel.max(), sel.min()}; sel.set(sel.max(), sel.min());
break; break;
case InsertMode::Replace: case InsertMode::Replace:
selections.erase(); selections.erase();
@ -1248,7 +1248,7 @@ private:
case InsertMode::Append: case InsertMode::Append:
for (auto& sel : selections) for (auto& sel : selections)
{ {
sel = Selection{sel.min(), sel.max()}; sel.set(sel.min(), sel.max());
auto& cursor = sel.cursor(); auto& cursor = sel.cursor();
// special case for end of lines, append to current line instead // special case for end of lines, append to current line instead
if (cursor.column != buffer[cursor.line].length() - 1) if (cursor.column != buffer[cursor.line].length() - 1)
@ -1257,23 +1257,23 @@ private:
break; break;
case InsertMode::AppendAtLineEnd: case InsertMode::AppendAtLineEnd:
for (auto& sel : selections) for (auto& sel : selections)
sel = BufferCoord{sel.max().line, buffer[sel.max().line].length() - 1}; sel.set({sel.max().line, buffer[sel.max().line].length() - 1});
break; break;
case InsertMode::OpenLineBelow: case InsertMode::OpenLineBelow:
for (auto& sel : selections) for (auto& sel : selections)
sel = BufferCoord{sel.max().line, buffer[sel.max().line].length() - 1}; sel.set({sel.max().line, buffer[sel.max().line].length() - 1});
duplicate_selections(selections, count); duplicate_selections(selections, count);
insert('\n'); insert('\n');
break; break;
case InsertMode::OpenLineAbove: case InsertMode::OpenLineAbove:
for (auto& sel : selections) for (auto& sel : selections)
sel = BufferCoord{sel.min().line}; sel.set({sel.min().line});
duplicate_selections(selections, count); duplicate_selections(selections, count);
// Do not use insert method here as we need to fixup selection // Do not use insert method here as we need to fixup selection
// before running the InsertChar hook. // before running the InsertChar hook.
selections.insert("\n"_str, InsertMode::InsertCursor); selections.insert("\n"_str, InsertMode::InsertCursor);
for (auto& sel : selections) // fixup selection positions for (auto& sel : selections) // fixup selection positions
sel = BufferCoord{sel.cursor().line - 1}; sel.set({sel.cursor().line - 1});
context().hooks().run_hook("InsertChar", "\n", context()); context().hooks().run_hook("InsertChar", "\n", context());
break; break;
case InsertMode::InsertAtLineBegin: case InsertMode::InsertAtLineBegin:
@ -1285,7 +1285,7 @@ private:
++pos_non_blank; ++pos_non_blank;
if (*pos_non_blank != '\n') if (*pos_non_blank != '\n')
pos = pos_non_blank.coord(); pos = pos_non_blank.coord();
sel = pos; sel.set(pos);
} }
break; break;
case InsertMode::InsertAtNextLineBegin: case InsertMode::InsertAtNextLineBegin:

View File

@ -28,6 +28,14 @@ struct Selection
const BufferCoord& anchor() const { return m_anchor; } const BufferCoord& anchor() const { return m_anchor; }
const BufferCoordAndTarget& cursor() const { return m_cursor; } const BufferCoordAndTarget& cursor() const { return m_cursor; }
void set(BufferCoord anchor, BufferCoord cursor)
{
m_anchor = anchor;
m_cursor = cursor;
}
void set(BufferCoord coord) { set(coord, coord); }
CaptureList& captures() { return m_captures; } CaptureList& captures() { return m_captures; }
const CaptureList& captures() const { return m_captures; } const CaptureList& captures() const { return m_captures; }

View File

@ -0,0 +1 @@
xs(\w+)<ret>i<c-r>1<esc>

View File

@ -0,0 +1 @@
foo bar

View File

@ -0,0 +1 @@
foofoo barbar