From 4916ea17661492da1af08eebb7fabd662c7e8390 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 13 Jan 2017 00:17:31 +0000 Subject: [PATCH] Fix capture group handling Fixes #1129 --- src/input_handler.cc | 14 +++++++------- src/selection.hh | 8 ++++++++ test/regression/1129-capture-groups-are-broken/cmd | 1 + test/regression/1129-capture-groups-are-broken/in | 1 + test/regression/1129-capture-groups-are-broken/out | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 test/regression/1129-capture-groups-are-broken/cmd create mode 100644 test/regression/1129-capture-groups-are-broken/in create mode 100644 test/regression/1129-capture-groups-are-broken/out diff --git a/src/input_handler.cc b/src/input_handler.cc index 37503abb..5347da44 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1240,7 +1240,7 @@ private: { case InsertMode::Insert: for (auto& sel : selections) - sel = Selection{sel.max(), sel.min()}; + sel.set(sel.max(), sel.min()); break; case InsertMode::Replace: selections.erase(); @@ -1248,7 +1248,7 @@ private: case InsertMode::Append: for (auto& sel : selections) { - sel = Selection{sel.min(), sel.max()}; + sel.set(sel.min(), sel.max()); auto& cursor = sel.cursor(); // special case for end of lines, append to current line instead if (cursor.column != buffer[cursor.line].length() - 1) @@ -1257,23 +1257,23 @@ private: break; case InsertMode::AppendAtLineEnd: 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; case InsertMode::OpenLineBelow: 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); insert('\n'); break; case InsertMode::OpenLineAbove: for (auto& sel : selections) - sel = BufferCoord{sel.min().line}; + sel.set({sel.min().line}); duplicate_selections(selections, count); // Do not use insert method here as we need to fixup selection // before running the InsertChar hook. selections.insert("\n"_str, InsertMode::InsertCursor); 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()); break; case InsertMode::InsertAtLineBegin: @@ -1285,7 +1285,7 @@ private: ++pos_non_blank; if (*pos_non_blank != '\n') pos = pos_non_blank.coord(); - sel = pos; + sel.set(pos); } break; case InsertMode::InsertAtNextLineBegin: diff --git a/src/selection.hh b/src/selection.hh index fa0da47a..7772f72c 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -28,6 +28,14 @@ struct Selection const BufferCoord& anchor() const { return m_anchor; } 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; } const CaptureList& captures() const { return m_captures; } diff --git a/test/regression/1129-capture-groups-are-broken/cmd b/test/regression/1129-capture-groups-are-broken/cmd new file mode 100644 index 00000000..00d5ec0c --- /dev/null +++ b/test/regression/1129-capture-groups-are-broken/cmd @@ -0,0 +1 @@ +xs(\w+)i1 diff --git a/test/regression/1129-capture-groups-are-broken/in b/test/regression/1129-capture-groups-are-broken/in new file mode 100644 index 00000000..d675fa44 --- /dev/null +++ b/test/regression/1129-capture-groups-are-broken/in @@ -0,0 +1 @@ +foo bar diff --git a/test/regression/1129-capture-groups-are-broken/out b/test/regression/1129-capture-groups-are-broken/out new file mode 100644 index 00000000..274b538a --- /dev/null +++ b/test/regression/1129-capture-groups-are-broken/out @@ -0,0 +1 @@ +foofoo barbar