lib/ruco/window.rb in ruco-0.2.0.beta2 vs lib/ruco/window.rb in ruco-0.2.0.beta3

- old
+ new

@@ -48,26 +48,31 @@ result = adjustment(column, visible_columns, @options[:column_scroll_threshold], @options[:column_scroll_offset]) self.left = result if result end def style_map(selection) - mask = StyleMap.new(lines) - return mask unless selection + map = StyleMap.new(lines) + if selection + add_selection_styles(map, selection) + else + map + end + end + def add_selection_styles(map, selection) lines.times do |line| visible = visible_area(line) next unless selection.overlap?(visible) first = [selection.first, visible.first].max first = first[1] - left last = [selection.last, visible.last].min last = last[1] - left - mask.add(:reverse, line, first...last) + map.add(:reverse, line, first...last) end - - mask + map end def left=(x) @left = [x,0].max end @@ -75,10 +80,18 @@ def set_top(line, total_lines) max_top = total_lines - lines + 1 + @options[:line_scroll_offset] @top = [[line, max_top].min, 0].max end + def visible_lines + @top..(@top+@lines-1) + end + + def visible_columns + @left..(@left+@columns-1) + end + private def adjustment(current, allowed, threshold, offset) if current < (allowed.first + threshold) current - offset @@ -93,15 +106,7 @@ start_of_line = [line, @left] last_visible_column = @left + @columns end_of_line = [line, last_visible_column] start_of_line..end_of_line end - - def visible_lines - @top..(@top+@lines-1) - end - - def visible_columns - @left..(@left+@columns-1) - end end -end \ No newline at end of file +end