From 00bde4ef483b11cdea59e2d693c2afee2e1576f0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 25 Feb 2015 13:40:19 +0000 Subject: Respect columns when copying selection, not just bytes --- src/buffer_utils.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/buffer_utils.cc') diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index 0b5941b9..c768a9eb 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -26,6 +26,26 @@ CharCount get_column(const Buffer& buffer, return col; } +ByteCount get_byte_to_column(const Buffer& buffer, CharCount tabstop, CharCoord coord) +{ + auto line = buffer[coord.line]; + auto col = 0_char; + auto it = line.begin(); + while (it != line.end() and coord.column > col) + { + if (*it == '\t') + { + col = (col / tabstop + 1) * tabstop; + if (col > coord.column) // the target column was in the tab + break; + } + else + ++col; + it = utf8::next(it, line.end()); + } + return (int)(it - line.begin()); +} + Buffer* create_buffer_from_data(StringView data, StringView name, Buffer::Flags flags, time_t fs_timestamp) { -- cgit v1.2.3