From fbbe4ddac74915fb99bf221c60d76cc40c9ff9db Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 21 Sep 2012 15:16:31 +0200 Subject: [PATCH] Cap line number when requesting info from layout With the new constraint based layout, the gutter can issue line record requests before the layout has been updated to hold the new document buffer. --- Frameworks/layout/src/layout.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Frameworks/layout/src/layout.cc b/Frameworks/layout/src/layout.cc index 3c26e96e..1632ffbb 100644 --- a/Frameworks/layout/src/layout.cc +++ b/Frameworks/layout/src/layout.cc @@ -349,10 +349,11 @@ namespace ng ng::line_record_t layout_t::line_record_for (text::pos_t const& pos) const { - size_t index = _buffer.convert(text::pos_t(pos.line, 0)) + pos.column; + size_t n = std::min(pos.line, _buffer.lines()-1); + size_t index = _buffer.convert(text::pos_t(n, 0)) + std::min(pos.column, _buffer.end(n) - _buffer.begin(n)); auto row = row_for_offset(index); if(row != _rows.end()) - return row->value.line_record_for(pos.line, index, *_metrics, _buffer, row->offset._length, CGPointMake(_margin.left, _margin.top + row->offset._height)); + return row->value.line_record_for(n, index, *_metrics, _buffer, row->offset._length, CGPointMake(_margin.left, _margin.top + row->offset._height)); return ng::line_record_t(0, 0, 0, 0, 0); }