diff --git a/src/buffer.cc b/src/buffer.cc index cefc8f9f..49ef596a 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -86,10 +86,9 @@ bool Buffer::set_name(String name) return false; } -BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column, - bool avoid_eol) const +BufferIterator Buffer::iterator_at(const BufferCoord& coord) const { - return BufferIterator(*this, clamp(line_and_column, avoid_eol)); + return BufferIterator(*this, clamp(coord)); } ByteCount Buffer::line_length(LineCount line) const @@ -98,17 +97,15 @@ ByteCount Buffer::line_length(LineCount line) const return m_lines[line].length(); } -BufferCoord Buffer::clamp(const BufferCoord& line_and_column, - bool avoid_eol) const +BufferCoord Buffer::clamp(BufferCoord coord) const { if (m_lines.empty()) - return BufferCoord(); + return BufferCoord{}; - BufferCoord result(line_and_column.line, line_and_column.column); - result.line = Kakoune::clamp(result.line, 0_line, line_count() - 1); - ByteCount max_col = std::max(0_byte, line_length(result.line) - (avoid_eol ? 2 : 1)); - result.column = Kakoune::clamp(result.column, 0_byte, max_col); - return result; + coord.line = Kakoune::clamp(coord.line, 0_line, line_count() - 1); + ByteCount max_col = std::max(0_byte, line_length(coord.line) - 1); + coord.column = Kakoune::clamp(coord.column, 0_byte, max_col); + return coord; } BufferIterator Buffer::iterator_at_line_begin(LineCount line) const diff --git a/src/buffer.hh b/src/buffer.hh index 8f3121e5..0f8a9602 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -119,12 +119,10 @@ public: bool undo(); bool redo(); - String string(const BufferCoord& begin, - const BufferCoord& end) const; + String string(const BufferCoord& begin, const BufferCoord& end) const; char at(const BufferCoord& c) const; ByteCount offset(const BufferCoord& c) const; - ByteCount distance(const BufferCoord& begin, - const BufferCoord& end) const; + ByteCount distance(const BufferCoord& begin, const BufferCoord& end) const; BufferCoord advance(BufferCoord coord, ByteCount count) const; BufferCoord next(BufferCoord coord) const; BufferCoord prev(BufferCoord coord) const; @@ -139,15 +137,11 @@ public: const String& line_content(LineCount line) const { return m_lines[line].content; } - // returns an iterator at given coordinates. line_and_column is - // clamped according to avoid_eol. - BufferIterator iterator_at(const BufferCoord& line_and_column, - bool avoid_eol = false) const; + // returns an iterator at given coordinates. clamp line_and_column + BufferIterator iterator_at(const BufferCoord& coord) const; // returns nearest valid coordinates from given ones - // if avoid_eol, clamp to character before eol if line is not empty - BufferCoord clamp(const BufferCoord& line_and_column, - bool avoid_eol = false) const; + BufferCoord clamp(BufferCoord coord) const; // returns an iterator pointing to the first character of the line // iterator is on