mirror of
				https://github.com/zsh-users/zsh-autosuggestions.git
				synced 2025-10-23 15:16:27 +08:00 
			
		
		
		
	Merge d6334ded0b into 11d17e7fea
				
					
				
			This commit is contained in:
		
						commit
						cc730fe4ad
					
				| @ -74,10 +74,10 @@ Widgets that modify the buffer and are not found in any of these arrays will fet | ||||
| **Note:** A widget shouldn't belong to more than one of the above arrays. | ||||
| 
 | ||||
| 
 | ||||
| ### Disabling suggestion for large buffers | ||||
| ### Disabling suggestion for small or large buffers | ||||
| 
 | ||||
| Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20. | ||||
| This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long. | ||||
| Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` or `ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE` to an integer value to disable autosuggestion for small or larger buffers. The default for both is unset, which means that autosuggestion will be tried for any buffer size. Recommended range is [5, 20]. | ||||
| This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long, or for irrelevant suggestions on smaller buffers. | ||||
| 
 | ||||
| ### Asynchronous Mode | ||||
| 
 | ||||
|  | ||||
| @ -25,6 +25,9 @@ describe 'a suggestion' do | ||||
|       wait_for { session.content }.to eq(long_command) | ||||
|     end | ||||
| 
 | ||||
|     it 'is not provided when the buffer is longer than the specified length' | ||||
|     it 'is not provided when the buffer is longer than the specified length' do | ||||
|       session.send_string(long_command[0...(buffer_max_size + 1)]) | ||||
|       wait_for { session.content }.to eq(long_command[0...(buffer_max_size + 1)]) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  | ||||
							
								
								
									
										33
									
								
								spec/options/buffer_min_size_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								spec/options/buffer_min_size_spec.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| describe 'a suggestion' do | ||||
|   let(:term_opts) { { width: 200 } } | ||||
|   let(:command) { "echo foobar" } | ||||
| 
 | ||||
|   around do |example| | ||||
|     with_history(command) { example.run } | ||||
|   end | ||||
| 
 | ||||
|   it 'is provided for any buffer length' do | ||||
|     session.send_string(command[0...-1]) | ||||
|     wait_for { session.content }.to eq(command) | ||||
|   end | ||||
| 
 | ||||
|   context 'when ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE is specified' do | ||||
|     let(:buffer_min_size) { 5 } | ||||
|     let(:options) { ["ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE=#{buffer_min_size}"] } | ||||
| 
 | ||||
|     it 'is provided when the buffer is longer than the specified length' do | ||||
|       session.send_string(command[0...(buffer_min_size + 1)]) | ||||
|       wait_for { session.content }.to eq(command) | ||||
|     end | ||||
| 
 | ||||
|     it 'is provided when the buffer is equal to the specified length' do | ||||
|       session.send_string(command[0...(buffer_min_size)]) | ||||
|       wait_for { session.content }.to eq(command) | ||||
|     end | ||||
| 
 | ||||
|     it 'is not provided when the buffer is shorter than the specified length' do | ||||
|       session.send_string(command[0...(buffer_min_size - 1)]) | ||||
|       wait_for { session.content }.to eq(command[0...(buffer_min_size - 1)]) | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @ -73,10 +73,9 @@ _zsh_autosuggest_modify() { | ||||
| 	fi | ||||
| 
 | ||||
| 	# Get a new suggestion if the buffer is not empty after modification | ||||
| 	if (( $#BUFFER > 0 )); then | ||||
| 		if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then | ||||
| 	if ([[ -z "$ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE" ]] || (( $#BUFFER >= $ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE ))) && \ | ||||
| 		 ([[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE ))); then | ||||
| 			_zsh_autosuggest_fetch | ||||
| 		fi | ||||
| 	fi | ||||
| 
 | ||||
| 	return $retval | ||||
|  | ||||
| @ -3,7 +3,7 @@ | ||||
| # v0.7.0 | ||||
| # Copyright (c) 2013 Thiago de Arruda | ||||
| # Copyright (c) 2016-2021 Eric Freese | ||||
| #  | ||||
| # | ||||
| # Permission is hereby granted, free of charge, to any person | ||||
| # obtaining a copy of this software and associated documentation | ||||
| # files (the "Software"), to deal in the Software without | ||||
| @ -12,10 +12,10 @@ | ||||
| # copies of the Software, and to permit persons to whom the | ||||
| # Software is furnished to do so, subject to the following | ||||
| # conditions: | ||||
| #  | ||||
| # | ||||
| # The above copyright notice and this permission notice shall be | ||||
| # included in all copies or substantial portions of the Software. | ||||
| #  | ||||
| # | ||||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||
| # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||||
| # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||||
| @ -337,10 +337,9 @@ _zsh_autosuggest_modify() { | ||||
| 	fi | ||||
| 
 | ||||
| 	# Get a new suggestion if the buffer is not empty after modification | ||||
| 	if (( $#BUFFER > 0 )); then | ||||
| 		if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then | ||||
| 	if ([[ -z "$ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE" ]] || (( $#BUFFER >= $ZSH_AUTOSUGGEST_BUFFER_MIN_SIZE ))) && \ | ||||
| 		 ([[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE ))); then | ||||
| 			_zsh_autosuggest_fetch | ||||
| 		fi | ||||
| 	fi | ||||
| 
 | ||||
| 	return $retval | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Muhammad Sohail
						Muhammad Sohail