diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-02-25 13:40:19 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-02-25 13:41:00 +0000 |
| commit | 00bde4ef483b11cdea59e2d693c2afee2e1576f0 (patch) | |
| tree | 4bd916948c5a61ce9ec323681795a37c64a3c467 /src/normal.cc | |
| parent | 46f37a6050e02a958d1cafbd7da42500df88e458 (diff) | |
Respect columns when copying selection, not just bytes
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/normal.cc b/src/normal.cc index 611698e7..f587a513 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -976,20 +976,32 @@ void copy_selections_on_next_lines(Context& context, NormalParams params) { auto& selections = context.selections(); auto& buffer = context.buffer(); + const CharCount tabstop = context.options()["tabstop"].get<int>(); Vector<Selection> result; for (auto& sel : selections) { auto anchor = sel.anchor(); auto cursor = sel.cursor(); + CharCount cursor_col = get_column(buffer, tabstop, cursor); + CharCount anchor_col = get_column(buffer, tabstop, anchor); result.push_back(std::move(sel)); for (int i = 0; i < std::max(params.count, 1); ++i) { LineCount offset = (direction == Forward ? 1 : -1) * (i + 1); - ByteCoord new_anchor{anchor.line + offset, anchor.column}; - ByteCoordAndTarget new_cursor{cursor.line + offset, cursor.column, cursor.target}; - if (buffer.is_valid(new_anchor) and not buffer.is_end(new_anchor) and - buffer.is_valid(new_cursor) and not buffer.is_end(new_cursor)) - result.emplace_back(new_anchor, new_cursor); + + const LineCount anchor_line = anchor.line + offset; + const LineCount cursor_line = cursor.line + offset; + + if (anchor_line >= buffer.line_count() or cursor_line >= buffer.line_count()) + continue; + + ByteCount anchor_byte = get_byte_to_column(buffer, tabstop, {anchor_line, anchor_col}); + ByteCount cursor_byte = get_byte_to_column(buffer, tabstop, {cursor_line, cursor_col}); + + if (anchor_byte != buffer[anchor_line].length() and + cursor_byte != buffer[cursor_line].length()) + result.emplace_back(ByteCoord{anchor_line, anchor_byte}, + ByteCoordAndTarget{cursor_line, cursor_byte, cursor.target}); } } selections = std::move(result); |
