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/buffer_utils.cc | |
| parent | 46f37a6050e02a958d1cafbd7da42500df88e458 (diff) | |
Respect columns when copying selection, not just bytes
Diffstat (limited to 'src/buffer_utils.cc')
| -rw-r--r-- | src/buffer_utils.cc | 20 |
1 files changed, 20 insertions, 0 deletions
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) { |
