mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Fix cr/lf handling in completion strategy
This commit is contained in:
parent
68343c8de4
commit
f543ba08c3
3 changed files with 32 additions and 0 deletions
|
@ -14,6 +14,12 @@ describe 'the `completion` suggestion strategy' do
|
||||||
wait_for { session.content }.to eq('baz bar')
|
wait_for { session.content }.to eq('baz bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||||
|
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||||
|
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||||
|
wait_for { session.content }.to eq("baz \\\nbar")
|
||||||
|
end
|
||||||
|
|
||||||
context 'when async mode is enabled' do
|
context 'when async mode is enabled' do
|
||||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
||||||
|
|
||||||
|
@ -21,6 +27,12 @@ describe 'the `completion` suggestion strategy' do
|
||||||
session.send_string('baz ')
|
session.send_string('baz ')
|
||||||
wait_for { session.content }.to eq('baz bar')
|
wait_for { session.content }.to eq('baz bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||||
|
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||||
|
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||||
|
wait_for { session.content }.to eq("baz \\\nbar")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,16 @@ _zsh_autosuggest_capture_completion_widget() {
|
||||||
# after autosuggestions is initialized.
|
# after autosuggestions is initialized.
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||||
|
|
||||||
|
if is-at-least 5.0.3; then
|
||||||
|
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||||
|
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||||
|
# vared in the async code path. There is a bug in zpty module in older versions
|
||||||
|
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||||
|
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||||
|
# commit f75904a38
|
||||||
|
stty -onlcr -ocrnl -F /dev/tty
|
||||||
|
fi
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
# The completion has been added, print the buffer as the suggestion
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
echo -nE - $'\0'$BUFFER$'\0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,6 +510,16 @@ _zsh_autosuggest_capture_completion_widget() {
|
||||||
# after autosuggestions is initialized.
|
# after autosuggestions is initialized.
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||||
|
|
||||||
|
if is-at-least 5.0.3; then
|
||||||
|
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||||
|
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||||
|
# vared in the async code path. There is a bug in zpty module in older versions
|
||||||
|
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||||
|
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||||
|
# commit f75904a38
|
||||||
|
stty -onlcr -ocrnl -F /dev/tty
|
||||||
|
fi
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
# The completion has been added, print the buffer as the suggestion
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
echo -nE - $'\0'$BUFFER$'\0'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue