Do not avoid eol in insert mode vertical movement
This commit is contained in:
parent
28bcb45b92
commit
7ee3039a79
|
@ -177,19 +177,19 @@ BufferCoord Buffer::clamp(BufferCoord coord) const
|
||||||
return coord;
|
return coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferCoord Buffer::offset_coord(BufferCoord coord, CharCount offset, ColumnCount)
|
BufferCoord Buffer::offset_coord(BufferCoord coord, CharCount offset, ColumnCount, bool)
|
||||||
{
|
{
|
||||||
StringView line = m_lines[coord.line];
|
StringView line = m_lines[coord.line];
|
||||||
auto target = utf8::advance(&line[coord.column], offset < 0 ? line.begin() : line.end()-1, offset);
|
auto target = utf8::advance(&line[coord.column], offset < 0 ? line.begin() : line.end()-1, offset);
|
||||||
return {coord.line, (int)(target - line.begin())};
|
return {coord.line, (int)(target - line.begin())};
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferCoordAndTarget Buffer::offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop)
|
BufferCoordAndTarget Buffer::offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop, bool avoid_eol)
|
||||||
{
|
{
|
||||||
const auto column = coord.target == -1 ? get_column(*this, tabstop, coord) : coord.target;
|
const auto column = coord.target == -1 ? get_column(*this, tabstop, coord) : coord.target;
|
||||||
const auto line = Kakoune::clamp(coord.line + offset, 0_line, line_count()-1);
|
const auto line = Kakoune::clamp(coord.line + offset, 0_line, line_count()-1);
|
||||||
const auto max_column = get_column(*this, tabstop, {line, m_lines[line].length()-1});
|
const auto max_column = get_column(*this, tabstop, {line, m_lines[line].length()-1});
|
||||||
const auto final_column = std::max(0_col, std::min(column, max_column - 1));
|
const auto final_column = std::max(0_col, std::min(column, max_column - (avoid_eol ? 1 : 0)));
|
||||||
return {line, get_byte_to_column(*this, tabstop, {line, final_column}), column};
|
return {line, get_byte_to_column(*this, tabstop, {line, final_column}), column};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,8 +179,8 @@ public:
|
||||||
// returns nearest valid coordinates from given ones
|
// returns nearest valid coordinates from given ones
|
||||||
BufferCoord clamp(BufferCoord coord) const;
|
BufferCoord clamp(BufferCoord coord) const;
|
||||||
|
|
||||||
BufferCoord offset_coord(BufferCoord coord, CharCount offset, ColumnCount tabstop);
|
BufferCoord offset_coord(BufferCoord coord, CharCount offset, ColumnCount, bool);
|
||||||
BufferCoordAndTarget offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop);
|
BufferCoordAndTarget offset_coord(BufferCoordAndTarget coord, LineCount offset, ColumnCount tabstop, bool avoid_eol);
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
const String& display_name() const { return m_display_name; }
|
const String& display_name() const { return m_display_name; }
|
||||||
|
|
|
@ -1240,7 +1240,7 @@ private:
|
||||||
const ColumnCount tabstop = context().options()["tabstop"].get<int>();
|
const ColumnCount tabstop = context().options()["tabstop"].get<int>();
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
auto cursor = context().buffer().offset_coord(sel.cursor(), offset, tabstop);
|
auto cursor = context().buffer().offset_coord(sel.cursor(), offset, tabstop, false);
|
||||||
sel.anchor() = sel.cursor() = cursor;
|
sel.anchor() = sel.cursor() = cursor;
|
||||||
}
|
}
|
||||||
selections.sort_and_merge_overlapping();
|
selections.sort_and_merge_overlapping();
|
||||||
|
|
|
@ -1741,7 +1741,7 @@ void move(Context& context, NormalParams params)
|
||||||
auto& selections = context.selections();
|
auto& selections = context.selections();
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
auto cursor = context.buffer().offset_coord(sel.cursor(), offset, tabstop);
|
auto cursor = context.buffer().offset_coord(sel.cursor(), offset, tabstop, true);
|
||||||
sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor;
|
sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor;
|
||||||
sel.cursor() = cursor;
|
sel.cursor() = cursor;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user