diff --git a/lib/base/list_view.rb b/lib/base/list_view.rb index b414d61..6f81854 100644 --- a/lib/base/list_view.rb +++ b/lib/base/list_view.rb @@ -30,7 +30,23 @@ class ListView < ElementView old.replace_with rendered end - def append view + # remove the first child and element (from view) + def remove_first + remove_at 0 + end + + # remove both child and element at given position + def remove_at index + raise "insex out of bounds #{index} => #{@children.length}" if(index >= @children.length or index < 0) + @children.delete_at( index ) + element = @elements.delete_at(index) + element.remove + end + + # append a View instnace to the children array + # render it and append it to the html element + # and keep a copy in @elements + def append_view view @children << view rendered = view.draw @elements << rendered # add to internal array diff --git a/lib/blocks_view.rb b/lib/blocks_view.rb index 444c5f9..33f0875 100644 --- a/lib/blocks_view.rb +++ b/lib/blocks_view.rb @@ -17,8 +17,8 @@ class BlocksView < ListView def instruction_changed return if @interpreter.block.name == active_block_name @elements.last.at_css(".bright").remove_class("bright") - append( BlockView.new(@interpreter.block) ) - remove_first if( @elements.length > 5) + append_view( BlockView.new(@interpreter.block) ) + remove_first if( @elements.length > 6) new_name = method_name return if new_name == @method_name @method_name = new_name diff --git a/lib/instruction_view.rb b/lib/instruction_view.rb index ac48bb6..ed30aff 100644 --- a/lib/instruction_view.rb +++ b/lib/instruction_view.rb @@ -11,9 +11,9 @@ class InstructionView < ListView def instruction_changed @element.at_css(".bright").remove_class("bright") - instruction = append( ConstantView.new( "span.bright" , instruction_text ) ) + instruction = append_view( ConstantView.new( "span.bright" , instruction_text ) ) wrap_node_with instruction , div - remove_first if( @elements.length > 5) + remove_first if( @elements.length > 6) end def draw diff --git a/lib/ref_view.rb b/lib/ref_view.rb index 613d662..c403355 100644 --- a/lib/ref_view.rb +++ b/lib/ref_view.rb @@ -31,7 +31,7 @@ class RefView < ListView def hover puts "hovering #{@name}" - append ObjectView.new(@value) + append_view ObjectView.new(@value) @element.off("hover") end