{"action":"created","comment":{"url":"https://api.github.com/repos/neovim/neovim/pulls/comments/56035929","id":56035929,"diff_hunk":"@@ -282,27 +289,56 @@ static bool handle_focus_event(TermInput *input)\n \n static bool handle_bracketed_paste(TermInput *input)\n {\n-  if (rbuffer_size(input->read_stream.buffer) > 5 &&\n-      (!rbuffer_cmp(input->read_stream.buffer, \"\\x1b[200~\", 6) ||\n-       !rbuffer_cmp(input->read_stream.buffer, \"\\x1b[201~\", 6))) {\n-    bool enable = *rbuffer_get(input->read_stream.buffer, 4) == '0';\n-    // Advance past the sequence\n-    rbuffer_consumed(input->read_stream.buffer, 6);\n-    if (input->paste_enabled == enable) {\n-      return true;\n+  RBuffer *rbuf = input->read_stream.buffer;\n+  if (rbuffer_size(rbuf) > 5\n+      && (!rbuffer_cmp(rbuf, \"\\x1b[200~\", 6)\n+          || !rbuffer_cmp(rbuf, \"\\x1b[201~\", 6))) {\n+    bool enable = *rbuffer_get(rbuf, 4) == '0';\n+\n+    if (enable && input->paste_started) {\n+      // Received a bogus \"paste start\" after paste was already started.\n+      return false;\n+    }\n+\n+    rbuffer_consumed(rbuf, 6);  // Advance past the sequence\n+    input->paste_started = enable;\n+    if (enable) {\n+      loop_schedule(&loop, event_create(1, apply_pastepre, 0));\n+    } else {\n+      enqueue_input(input, PASTEPOST_KEY, sizeof(PASTEPOST_KEY) - 1);","path":"src/nvim/tui/input.c","position":94,"original_position":99,"commit_id":"eab67f8788aba25ce055bc105f58aee6cec830ea","original_commit_id":"4c40891dae03200323a81523481881be91c4b473","user":{"login":"tarruda","id":842846,"avatar_url":"https://avatars.githubusercontent.com/u/842846?v=3","gravatar_id":"","url":"https://api.github.com/users/tarruda","html_url":"https://github.com/tarruda","followers_url":"https://api.github.com/users/tarruda/followers","following_url":"https://api.github.com/users/tarruda/following{/other_user}","gists_url":"https://api.github.com/users/tarruda/gists{/gist_id}","starred_url":"https://api.github.com/users/tarruda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarruda/subscriptions","organizations_url":"https://api.github.com/users/tarruda/orgs","repos_url":"https://api.github.com/users/tarruda/repos","events_url":"https://api.github.com/users/tarruda/events{/privacy}","received_events_url":"https://api.github.com/users/tarruda/received_events","type":"User","site_admin":false},"body":"> @tarruda So does that mean we can safely use loop_schedule() to schedule FocusGained/FocusLost instead of the K_FOCUSGAINED/K_FOCUSLOST?\r\n\r\nPossibly yes. I may be missing something, but FocusGained/FocusLost doesn't seem to be events that needs to be handled at an exact point during input processing.","created_at":"2016-03-14T17:04:16Z","updated_at":"2016-03-14T17:04:16Z","html_url":"https://github.com/neovim/neovim/pull/4448#discussion_r56035929","pull_request_url":"https://api.github.com/repos/neovim/neovim/pulls/4448","_links":{"self":{"href":"https://api.github.com/repos/neovim/neovim/pulls/comments/56035929"},"html":{"href":"https://github.com/neovim/neovim/pull/4448#discussion_r56035929"},"pull_request":{"href":"https://api.github.com/repos/neovim/neovim/pulls/4448"}}},"pull_request":{"url":"https://api.github.com/repos/neovim/neovim/pulls/4448","id":62689821,"html_url":"https://github.com/neovim/neovim/pull/4448","diff_url":"https://github.com/neovim/neovim/pull/4448.diff","patch_url":"https://github.com/neovim/neovim/pull/4448.patch","issue_url":"https://api.github.com/repos/neovim/neovim/issues/4448","number":4448,"state":"open","locked":false,"title":"[WIP] Implement PastePre, PastePost","user":{"login":"justinmk","id":1359421,"avatar_url":"https://avatars.githubusercontent.com/u/1359421?v=3","gravatar_id":"","url":"https://api.github.com/users/justinmk","html_url":"https://github.com/justinmk","followers_url":"https://api.github.com/users/justinmk/followers","following_url":"https://api.github.com/users/justinmk/following{/other_user}","gists_url":"https://api.github.com/users/justinmk/gists{/gist_id}","starred_url":"https://api.github.com/users/justinmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinmk/subscriptions","organizations_url":"https://api.github.com/users/justinmk/orgs","repos_url":"https://api.github.com/users/justinmk/repos","events_url":"https://api.github.com/users/justinmk/events{/privacy}","received_events_url":"https://api.github.com/users/justinmk/received_events","type":"User","site_admin":false},"body":"Closes https://github.com/neovim/neovim/issues/3476\r\nCloses https://github.com/neovim/neovim/issues/3566\r\nCloses https://github.com/neovim/neovim/issues/2523\r\n\r\nTODO (this PR):\r\n\r\n- [ ] documentation\r\n\r\nTODO (separate PR):\r\n\r\n- Provide register name in the autocmd \"pattern\" (and `v:event`), so `au PastePre a` listens for pastes from register `@a`.\r\n    - For clipboard paste (bracketed paste), register is the blackhole (`@_`). \r\n    - This makes PastePre/PastePost \"generalized\" so that it can be used for handling any paste, not just clipboard.\r\n- Send paste sequences to `:terminal`\r\n    - This can wait for another PR; this PR at least fixes #3476\r\n    - As @ZyX-I [mentioned](https://github.com/neovim/neovim/issues/3476#issuecomment-149519446) this would also be warranted for `p`, `:put`, etc.\r\n\r\nNote to reviewers: I do have some questions (which I will annotate below), but this is still WIP so the code is at proof-of-concept stage.","created_at":"2016-03-14T00:48:42Z","updated_at":"2016-03-14T17:04:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cac0beabe79502e0f15d99b883608366380a1e4c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/neovim/neovim/pulls/4448/commits","review_comments_url":"https://api.github.com/repos/neovim/neovim/pulls/4448/comments","review_comment_url":"https://api.github.com/repos/neovim/neovim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neovim/neovim/issues/4448/comments","statuses_url":"https://api.github.com/repos/neovim/neovim/statuses/eab67f8788aba25ce055bc105f58aee6cec830ea","head":{"label":"justinmk:paste","ref":"paste","sha":"eab67f8788aba25ce055bc105f58aee6cec830ea","user":{"login":"justinmk","id":1359421,"avatar_url":"https://avatars.githubusercontent.com/u/1359421?v=3","gravatar_id":"","url":"https://api.github.com/users/justinmk","html_url":"https://github.com/justinmk","followers_url":"https://api.github.com/users/justinmk/followers","following_url":"https://api.github.com/users/justinmk/following{/other_user}","gists_url":"https://api.github.com/users/justinmk/gists{/gist_id}","starred_url":"https://api.github.com/users/justinmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinmk/subscriptions","organizations_url":"https://api.github.com/users/justinmk/orgs","repos_url":"https://api.github.com/users/justinmk/repos","events_url":"https://api.github.com/users/justinmk/events{/privacy}","received_events_url":"https://api.github.com/users/justinmk/received_events","type":"User","site_admin":false},"repo":{"id":17302877,"name":"neovim","full_name":"justinmk/neovim","owner":{"login":"justinmk","id":1359421,"avatar_url":"https://avatars.githubusercontent.com/u/1359421?v=3","gravatar_id":"","url":"https://api.github.com/users/justinmk","html_url":"https://github.com/justinmk","followers_url":"https://api.github.com/users/justinmk/followers","following_url":"https://api.github.com/users/justinmk/following{/other_user}","gists_url":"https://api.github.com/users/justinmk/gists{/gist_id}","starred_url":"https://api.github.com/users/justinmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinmk/subscriptions","organizations_url":"https://api.github.com/users/justinmk/orgs","repos_url":"https://api.github.com/users/justinmk/repos","events_url":"https://api.github.com/users/justinmk/events{/privacy}","received_events_url":"https://api.github.com/users/justinmk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/justinmk/neovim","description":"vim's rebirth for the 21st century","fork":true,"url":"https://api.github.com/repos/justinmk/neovim","forks_url":"https://api.github.com/repos/justinmk/neovim/forks","keys_url":"https://api.github.com/repos/justinmk/neovim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/justinmk/neovim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/justinmk/neovim/teams","hooks_url":"https://api.github.com/repos/justinmk/neovim/hooks","issue_events_url":"https://api.github.com/repos/justinmk/neovim/issues/events{/number}","events_url":"https://api.github.com/repos/justinmk/neovim/events","assignees_url":"https://api.github.com/repos/justinmk/neovim/assignees{/user}","branches_url":"https://api.github.com/repos/justinmk/neovim/branches{/branch}","tags_url":"https://api.github.com/repos/justinmk/neovim/tags","blobs_url":"https://api.github.com/repos/justinmk/neovim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/justinmk/neovim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/justinmk/neovim/git/refs{/sha}","trees_url":"https://api.github.com/repos/justinmk/neovim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/justinmk/neovim/statuses/{sha}","languages_url":"https://api.github.com/repos/justinmk/neovim/languages","stargazers_url":"https://api.github.com/repos/justinmk/neovim/stargazers","contributors_url":"https://api.github.com/repos/justinmk/neovim/contributors","subscribers_url":"https://api.github.com/repos/justinmk/neovim/subscribers","subscription_url":"https://api.github.com/repos/justinmk/neovim/subscription","commits_url":"https://api.github.com/repos/justinmk/neovim/commits{/sha}","git_commits_url":"https://api.github.com/repos/justinmk/neovim/git/commits{/sha}","comments_url":"https://api.github.com/repos/justinmk/neovim/comments{/number}","issue_comment_url":"https://api.github.com/repos/justinmk/neovim/issues/comments{/number}","contents_url":"https://api.github.com/repos/justinmk/neovim/contents/{+path}","compare_url":"https://api.github.com/repos/justinmk/neovim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/justinmk/neovim/merges","archive_url":"https://api.github.com/repos/justinmk/neovim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/justinmk/neovim/downloads","issues_url":"https://api.github.com/repos/justinmk/neovim/issues{/number}","pulls_url":"https://api.github.com/repos/justinmk/neovim/pulls{/number}","milestones_url":"https://api.github.com/repos/justinmk/neovim/milestones{/number}","notifications_url":"https://api.github.com/repos/justinmk/neovim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/justinmk/neovim/labels{/name}","releases_url":"https://api.github.com/repos/justinmk/neovim/releases{/id}","deployments_url":"https://api.github.com/repos/justinmk/neovim/deployments","created_at":"2014-02-28T23:17:54Z","updated_at":"2014-12-29T18:58:05Z","pushed_at":"2016-03-14T07:31:37Z","git_url":"git://github.com/justinmk/neovim.git","ssh_url":"git@github.com:justinmk/neovim.git","clone_url":"https://github.com/justinmk/neovim.git","svn_url":"https://github.com/justinmk/neovim","homepage":"http://neovim.org/","size":38539,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"neovim:master","ref":"master","sha":"e7a9c006e15d99b4a276822d5f0f50b8cc2f6fb5","user":{"login":"neovim","id":6471485,"avatar_url":"https://avatars.githubusercontent.com/u/6471485?v=3","gravatar_id":"","url":"https://api.github.com/users/neovim","html_url":"https://github.com/neovim","followers_url":"https://api.github.com/users/neovim/followers","following_url":"https://api.github.com/users/neovim/following{/other_user}","gists_url":"https://api.github.com/users/neovim/gists{/gist_id}","starred_url":"https://api.github.com/users/neovim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neovim/subscriptions","organizations_url":"https://api.github.com/users/neovim/orgs","repos_url":"https://api.github.com/users/neovim/repos","events_url":"https://api.github.com/users/neovim/events{/privacy}","received_events_url":"https://api.github.com/users/neovim/received_events","type":"Organization","site_admin":false},"repo":{"id":16408992,"name":"neovim","full_name":"neovim/neovim","owner":{"login":"neovim","id":6471485,"avatar_url":"https://avatars.githubusercontent.com/u/6471485?v=3","gravatar_id":"","url":"https://api.github.com/users/neovim","html_url":"https://github.com/neovim","followers_url":"https://api.github.com/users/neovim/followers","following_url":"https://api.github.com/users/neovim/following{/other_user}","gists_url":"https://api.github.com/users/neovim/gists{/gist_id}","starred_url":"https://api.github.com/users/neovim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neovim/subscriptions","organizations_url":"https://api.github.com/users/neovim/orgs","repos_url":"https://api.github.com/users/neovim/repos","events_url":"https://api.github.com/users/neovim/events{/privacy}","received_events_url":"https://api.github.com/users/neovim/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/neovim/neovim","description":"Vim-fork focused on extensibility and agility. Consider helping sustain Neovim development! ","fork":false,"url":"https://api.github.com/repos/neovim/neovim","forks_url":"https://api.github.com/repos/neovim/neovim/forks","keys_url":"https://api.github.com/repos/neovim/neovim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neovim/neovim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neovim/neovim/teams","hooks_url":"https://api.github.com/repos/neovim/neovim/hooks","issue_events_url":"https://api.github.com/repos/neovim/neovim/issues/events{/number}","events_url":"https://api.github.com/repos/neovim/neovim/events","assignees_url":"https://api.github.com/repos/neovim/neovim/assignees{/user}","branches_url":"https://api.github.com/repos/neovim/neovim/branches{/branch}","tags_url":"https://api.github.com/repos/neovim/neovim/tags","blobs_url":"https://api.github.com/repos/neovim/neovim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neovim/neovim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neovim/neovim/git/refs{/sha}","trees_url":"https://api.github.com/repos/neovim/neovim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neovim/neovim/statuses/{sha}","languages_url":"https://api.github.com/repos/neovim/neovim/languages","stargazers_url":"https://api.github.com/repos/neovim/neovim/stargazers","contributors_url":"https://api.github.com/repos/neovim/neovim/contributors","subscribers_url":"https://api.github.com/repos/neovim/neovim/subscribers","subscription_url":"https://api.github.com/repos/neovim/neovim/subscription","commits_url":"https://api.github.com/repos/neovim/neovim/commits{/sha}","git_commits_url":"https://api.github.com/repos/neovim/neovim/git/commits{/sha}","comments_url":"https://api.github.com/repos/neovim/neovim/comments{/number}","issue_comment_url":"https://api.github.com/repos/neovim/neovim/issues/comments{/number}","contents_url":"https://api.github.com/repos/neovim/neovim/contents/{+path}","compare_url":"https://api.github.com/repos/neovim/neovim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neovim/neovim/merges","archive_url":"https://api.github.com/repos/neovim/neovim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neovim/neovim/downloads","issues_url":"https://api.github.com/repos/neovim/neovim/issues{/number}","pulls_url":"https://api.github.com/repos/neovim/neovim/pulls{/number}","milestones_url":"https://api.github.com/repos/neovim/neovim/milestones{/number}","notifications_url":"https://api.github.com/repos/neovim/neovim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neovim/neovim/labels{/name}","releases_url":"https://api.github.com/repos/neovim/neovim/releases{/id}","deployments_url":"https://api.github.com/repos/neovim/neovim/deployments","created_at":"2014-01-31T13:39:22Z","updated_at":"2016-03-14T16:56:51Z","pushed_at":"2016-03-14T12:38:15Z","git_url":"git://github.com/neovim/neovim.git","ssh_url":"git@github.com:neovim/neovim.git","clone_url":"https://github.com/neovim/neovim.git","svn_url":"https://github.com/neovim/neovim","homepage":"https://salt.bountysource.com/teams/neovim","size":60133,"stargazers_count":17692,"watchers_count":17692,"language":"VimL","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1261,"mirror_url":null,"open_issues_count":643,"forks":1261,"open_issues":643,"watchers":17692,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/neovim/neovim/pulls/4448"},"html":{"href":"https://github.com/neovim/neovim/pull/4448"},"issue":{"href":"https://api.github.com/repos/neovim/neovim/issues/4448"},"comments":{"href":"https://api.github.com/repos/neovim/neovim/issues/4448/comments"},"review_comments":{"href":"https://api.github.com/repos/neovim/neovim/pulls/4448/comments"},"review_comment":{"href":"https://api.github.com/repos/neovim/neovim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neovim/neovim/pulls/4448/commits"},"statuses":{"href":"https://api.github.com/repos/neovim/neovim/statuses/eab67f8788aba25ce055bc105f58aee6cec830ea"}}}}