mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
suspend suggestions on fast changes
This commit is contained in:
parent
87facd9b85
commit
7d41cf90c8
3 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
zmodload zsh/datetime
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
# Global Configuration Variables #
|
# Global Configuration Variables #
|
||||||
|
@ -46,3 +47,10 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||||
vi-forward-blank-word
|
vi-forward-blank-word
|
||||||
vi-forward-blank-word-end
|
vi-forward-blank-word-end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# EPOCH of the last changed widget call
|
||||||
|
ZSH_AUTOSUGGEST_LAST_MODIFY_TIME=$EPOCHREALTIME
|
||||||
|
|
||||||
|
# Lower bound for the time between changes that will cause autosuggest
|
||||||
|
# to suspend suggestions for the current edit.
|
||||||
|
ZSH_AUTOSUGGEST_CUTOFF_PERIOD=0.05
|
||||||
|
|
|
@ -16,6 +16,14 @@ _zsh_autosuggest_modify() {
|
||||||
# Original widget modifies the buffer
|
# Original widget modifies the buffer
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
|
||||||
|
local time_passed=$(($EPOCHREALTIME - $ZSH_AUTOSUGGEST_LAST_MODIFY_TIME))
|
||||||
|
|
||||||
|
if (( $time_passed < $ZSH_AUTOSUGGEST_CUTOFF_PERIOD )); then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ZSH_AUTOSUGGEST_LAST_MODIFY_TIME=$EPOCHREALTIME
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
local suggestion
|
local suggestion
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
# OTHER DEALINGS IN THE SOFTWARE.
|
# OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
zmodload zsh/datetime
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
# Global Configuration Variables #
|
# Global Configuration Variables #
|
||||||
|
@ -73,6 +74,13 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||||
vi-forward-blank-word-end
|
vi-forward-blank-word-end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# EPOCH of the last changed widget call
|
||||||
|
ZSH_AUTOSUGGEST_LAST_MODIFY_TIME=$EPOCHREALTIME
|
||||||
|
|
||||||
|
# Lower bound for the time between changes that will cause autosuggest
|
||||||
|
# to suspend suggestions for the current edit.
|
||||||
|
ZSH_AUTOSUGGEST_CUTOFF_PERIOD=0.05
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
# Handle Deprecated Variables/Widgets #
|
# Handle Deprecated Variables/Widgets #
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
@ -233,6 +241,14 @@ _zsh_autosuggest_modify() {
|
||||||
# Original widget modifies the buffer
|
# Original widget modifies the buffer
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
|
||||||
|
local time_passed=$(($EPOCHREALTIME - $ZSH_AUTOSUGGEST_LAST_MODIFY_TIME))
|
||||||
|
|
||||||
|
if (( $time_passed < $ZSH_AUTOSUGGEST_CUTOFF_PERIOD )); then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ZSH_AUTOSUGGEST_LAST_MODIFY_TIME=$EPOCHREALTIME
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
local suggestion
|
local suggestion
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if [ $#BUFFER -gt 0 ]; then
|
||||||
|
|
Loading…
Reference in a new issue