From 3a0ad239db613c3eac4c1bb643b90562dd577d5c Mon Sep 17 00:00:00 2001 From: Dawid Ferenczy Date: Sat, 13 Dec 2014 05:42:56 +0100 Subject: [PATCH] Proposal of text pasting performance issue solution --- zsh-syntax-highlighting.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 937e426..cc8f7ee 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -33,6 +33,9 @@ # Core highlighting update system # ------------------------------------------------------------------------------------------------- +# Load datetime Zsh module for measuring time delta between keystrokes +zmodload zsh/datetime + # Array declaring active highlighters names. typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS @@ -54,6 +57,11 @@ _zsh_highlight() # Do not highlight if there are pending inputs (copy/paste). [[ $PENDING -gt 0 ]] && return $ret + # Do not highlight if the time delta from previous keystroke is less than 200 ms + [[ -z "$LAST_INVOKE_EPOCH" ]] && typeset -g LAST_INVOKE_EPOCH=$EPOCHREALTIME + [[ $(( $EPOCHREALTIME - $LAST_INVOKE_EPOCH )) -lt 0.2 ]] && return $ret + typeset -g LAST_INVOKE_EPOCH=$EPOCHREALTIME + # Reset region highlight to build it from scratch region_highlight=();