11findMode = null
22
3+ # Chrome creates a unique port for each MessageChannel,
4+ # so there's a race condition between JavaScript messages of Vimium and browser messages during style recomputation.
5+ # This constant is to ensure all messages have been received and handled
6+ # See more in https://github.com/philc/vimium/pull/3277#discussion_r283080348
7+ TIME_TO_WAIT_FOR_IPC_MESSAGES = 17
8+
39# Set the input element's text, and move the cursor to the end.
410setTextInInputElement = (inputElement , text ) ->
511 inputElement .textContent = text
@@ -86,7 +92,7 @@ handlers =
8692 countElement .id = " hud-match-count"
8793 countElement .style .float = " right"
8894 hud .appendChild countElement
89- inputElement .focus ()
95+ Utils . setTimeout TIME_TO_WAIT_FOR_IPC_MESSAGES, -> inputElement .focus ()
9096
9197 findMode =
9298 historyIndex : - 1
@@ -104,14 +110,14 @@ handlers =
104110 " (No matches)"
105111 countElement .textContent = if showMatchText then countText else " "
106112
107- copyToClipboard : (data ) ->
113+ copyToClipboard : (data ) -> Utils . setTimeout TIME_TO_WAIT_FOR_IPC_MESSAGES, ->
108114 focusedElement = document .activeElement
109115 Clipboard .copy data
110116 focusedElement ? .focus ()
111117 window .parent .focus ()
112118 UIComponentServer .postMessage {name : " unfocusIfFocused" }
113119
114- pasteFromClipboard : ->
120+ pasteFromClipboard : -> Utils . setTimeout TIME_TO_WAIT_FOR_IPC_MESSAGES, ->
115121 focusedElement = document .activeElement
116122 data = Clipboard .paste ()
117123 focusedElement ? .focus ()
0 commit comments