mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-08 15:32:31 +01:00
Feature: Allow cycling throw history in the autocompletion
This commit is contained in:
parent
fa5d9c0ff5
commit
47173c140c
12 changed files with 282 additions and 38 deletions
63
spec/widgets/next_spec.rb
Normal file
63
spec/widgets/next_spec.rb
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
describe 'the `autosuggest-next` widget' do
|
||||
context 'when suggestions are disabled' do
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^B autosuggest-disable').
|
||||
run_command('bindkey ^K autosuggest-next').
|
||||
send_keys('C-b')
|
||||
end
|
||||
it 'will fetch and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo h')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo h')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'invoked on a populated history' do
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^K autosuggest-next')
|
||||
end
|
||||
it 'will cycle, fetch, and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo joe')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when async mode is enabled' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=history'] }
|
||||
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^K autosuggest-next')
|
||||
end
|
||||
it 'will cycle, fetch, and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo joe')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
77
spec/widgets/previous_spec.rb
Normal file
77
spec/widgets/previous_spec.rb
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
describe 'the `autosuggest-previous` widget' do
|
||||
context 'when suggestions are disabled' do
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^B autosuggest-disable').
|
||||
run_command('bindkey ^J autosuggest-previous').
|
||||
send_keys('C-b')
|
||||
end
|
||||
it 'will fetch and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo h')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo h')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'invoked on a populated history' do
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^K autosuggest-next').
|
||||
run_command('bindkey ^J autosuggest-previous')
|
||||
end
|
||||
it 'will cycle, fetch, and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo joe')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo joe')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo joe')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when async mode is enabled' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=history'] }
|
||||
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^K autosuggest-next').
|
||||
run_command('bindkey ^J autosuggest-previous')
|
||||
end
|
||||
it 'will cycle, fetch, and display a suggestion' do
|
||||
with_history('echo hello', 'echo world', 'echo joe') do
|
||||
session.send_string('echo')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo joe')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-k')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo joe')
|
||||
session.send_keys('C-j')
|
||||
wait_for { session.content }.to eq('echo joe')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue