mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Remove extra items because Reline::HISTORY is a sized queue
This commit is contained in:
		
							parent
							
								
									3b7862c8e8
								
							
						
					
					
						commit
						c67934b1c3
					
				
					 2 changed files with 42 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -45,9 +45,23 @@ module Reline
 | 
			
		|||
      super(index, String.new(val, encoding: Encoding::default_external))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def concat(*val)
 | 
			
		||||
      val.each do |v|
 | 
			
		||||
        push(*v)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def push(*val)
 | 
			
		||||
      diff = size + val.size - @@config.history_size
 | 
			
		||||
      shift(diff) if diff > 0
 | 
			
		||||
      if diff > 0
 | 
			
		||||
        if diff <= size
 | 
			
		||||
          shift(diff)
 | 
			
		||||
        else
 | 
			
		||||
          diff -= size
 | 
			
		||||
          clear
 | 
			
		||||
          val.shift(diff)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      super(*(val.map{ |v| String.new(v, encoding: Encoding::default_external) }))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1181,6 +1181,33 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
 | 
			
		|||
    assert_cursor_max(3)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_larger_histories_than_history_size
 | 
			
		||||
    history_size = @config.history_size
 | 
			
		||||
    @config.history_size = 2
 | 
			
		||||
    Reline::HISTORY.concat(%w{abc 123 AAA})
 | 
			
		||||
    assert_line('')
 | 
			
		||||
    assert_byte_pointer_size('')
 | 
			
		||||
    assert_cursor(0)
 | 
			
		||||
    assert_cursor_max(0)
 | 
			
		||||
    input_keys("\C-p")
 | 
			
		||||
    assert_line('AAA')
 | 
			
		||||
    assert_byte_pointer_size('AAA')
 | 
			
		||||
    assert_cursor(3)
 | 
			
		||||
    assert_cursor_max(3)
 | 
			
		||||
    input_keys("\C-p")
 | 
			
		||||
    assert_line('123')
 | 
			
		||||
    assert_byte_pointer_size('123')
 | 
			
		||||
    assert_cursor(3)
 | 
			
		||||
    assert_cursor_max(3)
 | 
			
		||||
    input_keys("\C-p")
 | 
			
		||||
    assert_line('123')
 | 
			
		||||
    assert_byte_pointer_size('123')
 | 
			
		||||
    assert_cursor(3)
 | 
			
		||||
    assert_cursor_max(3)
 | 
			
		||||
  ensure
 | 
			
		||||
    @config.history_size = history_size
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
=begin # TODO: move KeyStroke instance from Reline to LineEditor
 | 
			
		||||
  def test_key_delete
 | 
			
		||||
    input_keys('ab')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue