Respect tabstop in Buffer::offset_coord
This commit is contained in:
parent
57c2b32d20
commit
5ee21ec932
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "assert.hh"
|
||||
#include "buffer_manager.hh"
|
||||
#include "buffer_utils.hh"
|
||||
#include "client.hh"
|
||||
#include "containers.hh"
|
||||
#include "context.hh"
|
||||
|
@ -176,21 +177,21 @@ BufferCoord Buffer::clamp(BufferCoord coord) const
|
|||
return coord;
|
||||
}
|
||||
|
||||
BufferCoord Buffer::offset_coord(BufferCoord coord, CharCount offset)
|
||||
BufferCoord Buffer::offset_coord(BufferCoord coord, CharCount offset, ColumnCount)
|
||||
{
|
||||
StringView line = m_lines[coord.line];
|
||||
auto target = utf8::advance(&line[coord.column], offset < 0 ? line.begin() : line.end()-1, offset);
|
||||
return {coord.line, (int)(target - line.begin())};
|
||||
}
|
||||
|
||||
BufferCoordAndTarget Buffer::offset_coord(BufferCoordAndTarget coord, LineCount offset)
|
||||
BufferCoordAndTarget Buffer::offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop)
|
||||
{
|
||||
auto column = coord.target == -1 ? m_lines[coord.line].column_count_to(coord.column) : coord.target;
|
||||
auto column = coord.target == -1 ? get_column(*this, tabstop, coord) : coord.target;
|
||||
auto line = Kakoune::clamp(coord.line + offset, 0_line, line_count()-1);
|
||||
StringView content = m_lines[line];
|
||||
|
||||
auto final_column = std::max(0_col, std::min(column, content.column_length() - 2));
|
||||
return {line, content.byte_count_to(final_column), column};
|
||||
return {line, get_byte_to_column(*this, tabstop, {line, final_column}), column};
|
||||
}
|
||||
|
||||
String Buffer::string(BufferCoord begin, BufferCoord end) const
|
||||
|
|
|
@ -179,8 +179,8 @@ public:
|
|||
// returns nearest valid coordinates from given ones
|
||||
BufferCoord clamp(BufferCoord coord) const;
|
||||
|
||||
BufferCoord offset_coord(BufferCoord coord, CharCount offset);
|
||||
BufferCoordAndTarget offset_coord(BufferCoordAndTarget coord, LineCount offset);
|
||||
BufferCoord offset_coord(BufferCoord coord, CharCount offset, ColumnCount tabstop);
|
||||
BufferCoordAndTarget offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop);
|
||||
|
||||
const String& name() const { return m_name; }
|
||||
const String& display_name() const { return m_display_name; }
|
||||
|
|
|
@ -1240,9 +1240,10 @@ private:
|
|||
void move(Type offset)
|
||||
{
|
||||
auto& selections = context().selections();
|
||||
const ColumnCount tabstop = context().options()["tabstop"].get<int>();
|
||||
for (auto& sel : selections)
|
||||
{
|
||||
auto cursor = context().buffer().offset_coord(sel.cursor(), offset);
|
||||
auto cursor = context().buffer().offset_coord(sel.cursor(), offset, tabstop);
|
||||
sel.anchor() = sel.cursor() = cursor;
|
||||
}
|
||||
selections.sort_and_merge_overlapping();
|
||||
|
|
|
@ -1693,10 +1693,11 @@ void move(Context& context, NormalParams params)
|
|||
Type offset(std::max(params.count,1));
|
||||
if (direction == Backward)
|
||||
offset = -offset;
|
||||
const ColumnCount tabstop = context.options()["tabstop"].get<int>();
|
||||
auto& selections = context.selections();
|
||||
for (auto& sel : selections)
|
||||
{
|
||||
auto cursor = context.buffer().offset_coord(sel.cursor(), offset);
|
||||
auto cursor = context.buffer().offset_coord(sel.cursor(), offset, tabstop);
|
||||
sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor;
|
||||
sel.cursor() = cursor;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user