Fix paste when focus is slow

This commit is contained in:
BarbUk 2020-07-03 14:34:06 +04:00
parent af7bfe9d6f
commit 70921a3e3f
No known key found for this signature in database
GPG Key ID: DB301C759539E9FE

13
snippy
View File

@ -54,10 +54,6 @@ readonly snippets_directory=$XDG_CONFIG_HOME/snippy
readonly rofi_args=(-dmenu -i -sort -async-pre-read 20 -theme-str 'element-icon { size: 2.35ch;}' -kb-accept-custom "" -kb-custom-1 "Ctrl+Return") readonly rofi_args=(-dmenu -i -sort -async-pre-read 20 -theme-str 'element-icon { size: 2.35ch;}' -kb-accept-custom "" -kb-custom-1 "Ctrl+Return")
readonly fzf_args=(--select-1 --reverse --inline-info --multi --preview '( bat --style auto --color always --language bash {} || highlight --force -O ansi -l {} 2> /dev/null ) | head -200' -1) readonly fzf_args=(--select-1 --reverse --inline-info --multi --preview '( bat --style auto --color always --language bash {} || highlight --force -O ansi -l {} 2> /dev/null ) | head -200' -1)
# if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v"
readonly GUIPASTE="xdotool key ctrl+v"
readonly CLIPASTE="xdotool key ctrl+shift+v"
# Placeholders # Placeholders
readonly cursor_placeholder="{cursor}" readonly cursor_placeholder="{cursor}"
readonly clipboard_placeholder="{clipboard}" readonly clipboard_placeholder="{clipboard}"
@ -377,11 +373,14 @@ run() {
# Paste into the current application. # Paste into the current application.
if is_gui; then if is_gui; then
# We need a little pause to handle the time to focus on the window # We need a little pause to handle the time to focus on the window
sleep 0.225 sleep 0.1
${GUIPASTE} # Paste
xdotool key ctrl+v
# And another pause to empty the paste buffer before anything else
sleep 0.1
move_cursor "Up" $cursor_line_position move_cursor "Up" $cursor_line_position
else else
${CLIPASTE} xdotool key ctrl+shift+v
if is_vim; then if is_vim; then
move_cursor "Up" $cursor_line_position move_cursor "Up" $cursor_line_position
fi fi