GitHub PullRequestReviewCommentEvent at 2014-12-12 17:12:09
Repository: brackets
Actor: redmunds
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/adobe/brackets/pulls/comments/21758102","id":21758102,"diff_hunk":"@@ -125,6 +125,137 @@ define(function (require, exports, module) {\n      */\n     var _globalKeydownHooks = [];\n \n+    \n+    /**\n+     * @private\n+     * Flags used to determine whether right Alt key is pressed. When it is pressed, \n+     * the following two keydown events are triggered in that specific order. \n+     *\n+     *    1. _ctrlDown - flag used to record { ctrlKey: true, keyIdentifier: \"Control\", ... } keydown event\n+     *    2. _altGrDown - flag used to record { ctrlKey: true, altKey: true, keyIdentifier: \"Alt\", ... } keydown event\n+     *\n+     * _ctrlDown is intentionally undefined so that we can distinguish between the actual Ctrl keydown and AltGr keydown\n+     * events.\n+     *\n+     * @type {boolean}\n+     */\n+    var _ctrlDown,\n+        _altGrDown = false;\n+    \n+    /**\n+     * @private\n+     * Used to record the timeStamp property of the last keydown event.\n+     * @type {number}\n+     */\n+    var _lastTimeStamp;\n+\n+    /**\n+     * @private\n+     * Used to record the keyIdentifier property of the last keydown event.\n+     * @type {string}\n+     */\n+    var _lastKeyIdentifier;\n+    \n+    /* \n+     * @private\n+     * Constant used for checking the interval between Control keydown event and Alt keydown event.\n+     * If the right Alt key is down we get Control keydown followed by Alt keydown within 30 ms. if \n+     * the user is pressing Control key and then Alt key, the interval will be larger than 30 ms.\n+     *\n+     * @type {number}\n+     */\n+    var MAX_INTERVAL_FOR_CTRL_ALT_KEYS = 30;\n+    \n+    /**\n+     * @private\n+     * Forward declaration for JSLint.\n+     * @type {Function}\n+     */\n+    var _onCtrlUp;\n+\n+    /**\n+     * @private\n+     * Resets all the flags and removes _onCtrlUp event listener.\n+     * \n+     */\n+    function _quitAltGrMode() {\n+        _enabled = true;\n+        _ctrlDown = undefined;\n+        _altGrDown = false;\n+        _lastTimeStamp = undefined;\n+        _lastKeyIdentifier = undefined;\n+        $(window).off(\"keyup\", _onCtrlUp);\n+    }\n+    \n+    /**\n+     * @private\n+     * Detects the release of AltGr key by checking all keyup events\n+     * until we receive one with ctrl key code. Once detected, reset \n+     * all the flags and also remove this event listener.\n+     *\n+     * @param {!KeyboardEvent} e keyboard event object\n+     */\n+    _onCtrlUp = function (e) {\n+        var key = e.keyCode || e.which;\n+        if (_altGrDown && key === KeyEvent.DOM_VK_CONTROL) {\n+            _quitAltGrMode();\n+        }\n+    };\n+    \n+    /**\n+     * @private\n+     * Detects whether AltGr key is pressed. When it is pressed, the first keydown event has \n+     * ctrlKey === true with keyIdentifier === \"Control\". The next keydown event with \n+     * altKey === true, ctrlKey === true and keyIdentifier === \"Alt\" is sent within 30 ms. Then \n+     * the next keydown event with altKey === true, ctrlKey === true and keyIdentifier === \"Control\" \n+     * is sent. If the user keep holding AltGr key down, then the second and third \n+     * keydown events are repeatedly sent out alternately. If the user is also holding down Ctrl\n+     * key, then either keyIdentifier === \"Control\" or keyIdentifier === \"Alt\" is repeatedly sent\n+     * but not alternately.\n+     *\n+     * Once we detect the AltGr key down, then disable KeyBindingManager and set up a keyup\n+     * event listener to detect the release of the altGr key so that we can re-enable KeyBindingManager.\n+     * When we detect the addition of Ctrl key besides AltGr key, we also quit AltGr mode and re-enable\n+     * KeyBindingManager.\n+     *\n+     * @param {!KeyboardEvent} e keyboard event object\n+     */\n+    function _detectAltGrKeyDown(e) {\n+        if (brackets.platform !== \"win\") {\n+            return;\n+        }\n+        \n+        if (!_altGrDown) {\n+            if (_ctrlDown === undefined && e.ctrlKey && e.keyIdentifier === \"Control\") {\n+                _ctrlDown = true;\n+            } else if (_ctrlDown && e.altKey && e.ctrlKey && e.keyIdentifier === \"Alt\" &&\n+                        (e.timeStamp - _lastTimeStamp) < MAX_INTERVAL_FOR_CTRL_ALT_KEYS) {\n+                _altGrDown = true;\n+                _lastKeyIdentifier = \"Alt\";\n+                _enabled = false;\n+                $(window).on(\"keyup\", _onCtrlUp);\n+            } else if (e.ctrlKey && e.keyIdentifier === \"Control\") {\n+                // We get here if the user is holding down left/right Control key. Set it to false \n+                // so that we don't misidentify the combination of Ctrl and Alt keys as AltGr key.\n+                _ctrlDown = false;","path":"src/command/KeyBindingManager.js","position":116,"original_position":116,"commit_id":"18d24e81911e3f976890442973e242a6ac6d579b","original_commit_id":"18d24e81911e3f976890442973e242a6ac6d579b","user":{"login":"redmunds","id":1197144,"avatar_url":"https://avatars.githubusercontent.com/u/1197144?v=3","gravatar_id":"","url":"https://api.github.com/users/redmunds","html_url":"https://github.com/redmunds","followers_url":"https://api.github.com/users/redmunds/followers","following_url":"https://api.github.com/users/redmunds/following{/other_user}","gists_url":"https://api.github.com/users/redmunds/gists{/gist_id}","starred_url":"https://api.github.com/users/redmunds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redmunds/subscriptions","organizations_url":"https://api.github.com/users/redmunds/orgs","repos_url":"https://api.github.com/users/redmunds/repos","events_url":"https://api.github.com/users/redmunds/events{/privacy}","received_events_url":"https://api.github.com/users/redmunds/received_events","type":"User","site_admin":false},"body":"I see that you are using 3 states for `_ctrlDown`. It would be more clear if an enum was used with explicit state values.","created_at":"2014-12-12T17:12:09Z","updated_at":"2014-12-12T17:12:09Z","html_url":"https://github.com/adobe/brackets/pull/10109#discussion_r21758102","pull_request_url":"https://api.github.com/repos/adobe/brackets/pulls/10109","_links":{"self":{"href":"https://api.github.com/repos/adobe/brackets/pulls/comments/21758102"},"html":{"href":"https://github.com/adobe/brackets/pull/10109#discussion_r21758102"},"pull_request":{"href":"https://api.github.com/repos/adobe/brackets/pulls/10109"}}},"pull_request":{"url":"https://api.github.com/repos/adobe/brackets/pulls/10109","id":25640760,"html_url":"https://github.com/adobe/brackets/pull/10109","diff_url":"https://github.com/adobe/brackets/pull/10109.diff","patch_url":"https://github.com/adobe/brackets/pull/10109.patch","issue_url":"https://api.github.com/repos/adobe/brackets/issues/10109","number":10109,"state":"open","locked":false,"title":"Disable KeyBindingManager on right Alt keydown.","user":{"login":"RaymondLim","id":1542488,"avatar_url":"https://avatars.githubusercontent.com/u/1542488?v=3","gravatar_id":"","url":"https://api.github.com/users/RaymondLim","html_url":"https://github.com/RaymondLim","followers_url":"https://api.github.com/users/RaymondLim/followers","following_url":"https://api.github.com/users/RaymondLim/following{/other_user}","gists_url":"https://api.github.com/users/RaymondLim/gists{/gist_id}","starred_url":"https://api.github.com/users/RaymondLim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RaymondLim/subscriptions","organizations_url":"https://api.github.com/users/RaymondLim/orgs","repos_url":"https://api.github.com/users/RaymondLim/repos","events_url":"https://api.github.com/users/RaymondLim/events{/privacy}","received_events_url":"https://api.github.com/users/RaymondLim/received_events","type":"User","site_admin":false},"body":"This fixes issue #8666.","created_at":"2014-12-08T00:59:34Z","updated_at":"2014-12-12T17:12:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7a7dfa823ffab1c8951ebd5a0dd06b228982ebbc","assignee":{"login":"redmunds","id":1197144,"avatar_url":"https://avatars.githubusercontent.com/u/1197144?v=3","gravatar_id":"","url":"https://api.github.com/users/redmunds","html_url":"https://github.com/redmunds","followers_url":"https://api.github.com/users/redmunds/followers","following_url":"https://api.github.com/users/redmunds/following{/other_user}","gists_url":"https://api.github.com/users/redmunds/gists{/gist_id}","starred_url":"https://api.github.com/users/redmunds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redmunds/subscriptions","organizations_url":"https://api.github.com/users/redmunds/orgs","repos_url":"https://api.github.com/users/redmunds/repos","events_url":"https://api.github.com/users/redmunds/events{/privacy}","received_events_url":"https://api.github.com/users/redmunds/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/adobe/brackets/pulls/10109/commits","review_comments_url":"https://api.github.com/repos/adobe/brackets/pulls/10109/comments","review_comment_url":"https://api.github.com/repos/adobe/brackets/pulls/comments/{number}","comments_url":"https://api.github.com/repos/adobe/brackets/issues/10109/comments","statuses_url":"https://api.github.com/repos/adobe/brackets/statuses/18d24e81911e3f976890442973e242a6ac6d579b","head":{"label":"adobe:rlim/altGr-key","ref":"rlim/altGr-key","sha":"18d24e81911e3f976890442973e242a6ac6d579b","user":{"login":"adobe","id":476009,"avatar_url":"https://avatars.githubusercontent.com/u/476009?v=3","gravatar_id":"","url":"https://api.github.com/users/adobe","html_url":"https://github.com/adobe","followers_url":"https://api.github.com/users/adobe/followers","following_url":"https://api.github.com/users/adobe/following{/other_user}","gists_url":"https://api.github.com/users/adobe/gists{/gist_id}","starred_url":"https://api.github.com/users/adobe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adobe/subscriptions","organizations_url":"https://api.github.com/users/adobe/orgs","repos_url":"https://api.github.com/users/adobe/repos","events_url":"https://api.github.com/users/adobe/events{/privacy}","received_events_url":"https://api.github.com/users/adobe/received_events","type":"Organization","site_admin":false},"repo":{"id":2935735,"name":"brackets","full_name":"adobe/brackets","owner":{"login":"adobe","id":476009,"avatar_url":"https://avatars.githubusercontent.com/u/476009?v=3","gravatar_id":"","url":"https://api.github.com/users/adobe","html_url":"https://github.com/adobe","followers_url":"https://api.github.com/users/adobe/followers","following_url":"https://api.github.com/users/adobe/following{/other_user}","gists_url":"https://api.github.com/users/adobe/gists{/gist_id}","starred_url":"https://api.github.com/users/adobe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adobe/subscriptions","organizations_url":"https://api.github.com/users/adobe/orgs","repos_url":"https://api.github.com/users/adobe/repos","events_url":"https://api.github.com/users/adobe/events{/privacy}","received_events_url":"https://api.github.com/users/adobe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/adobe/brackets","description":"An open source code editor for the web, written in JavaScript, HTML and CSS.","fork":false,"url":"https://api.github.com/repos/adobe/brackets","forks_url":"https://api.github.com/repos/adobe/brackets/forks","keys_url":"https://api.github.com/repos/adobe/brackets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adobe/brackets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adobe/brackets/teams","hooks_url":"https://api.github.com/repos/adobe/brackets/hooks","issue_events_url":"https://api.github.com/repos/adobe/brackets/issues/events{/number}","events_url":"https://api.github.com/repos/adobe/brackets/events","assignees_url":"https://api.github.com/repos/adobe/brackets/assignees{/user}","branches_url":"https://api.github.com/repos/adobe/brackets/branches{/branch}","tags_url":"https://api.github.com/repos/adobe/brackets/tags","blobs_url":"https://api.github.com/repos/adobe/brackets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adobe/brackets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adobe/brackets/git/refs{/sha}","trees_url":"https://api.github.com/repos/adobe/brackets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adobe/brackets/statuses/{sha}","languages_url":"https://api.github.com/repos/adobe/brackets/languages","stargazers_url":"https://api.github.com/repos/adobe/brackets/stargazers","contributors_url":"https://api.github.com/repos/adobe/brackets/contributors","subscribers_url":"https://api.github.com/repos/adobe/brackets/subscribers","subscription_url":"https://api.github.com/repos/adobe/brackets/subscription","commits_url":"https://api.github.com/repos/adobe/brackets/commits{/sha}","git_commits_url":"https://api.github.com/repos/adobe/brackets/git/commits{/sha}","comments_url":"https://api.github.com/repos/adobe/brackets/comments{/number}","issue_comment_url":"https://api.github.com/repos/adobe/brackets/issues/comments/{number}","contents_url":"https://api.github.com/repos/adobe/brackets/contents/{+path}","compare_url":"https://api.github.com/repos/adobe/brackets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adobe/brackets/merges","archive_url":"https://api.github.com/repos/adobe/brackets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adobe/brackets/downloads","issues_url":"https://api.github.com/repos/adobe/brackets/issues{/number}","pulls_url":"https://api.github.com/repos/adobe/brackets/pulls{/number}","milestones_url":"https://api.github.com/repos/adobe/brackets/milestones{/number}","notifications_url":"https://api.github.com/repos/adobe/brackets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adobe/brackets/labels{/name}","releases_url":"https://api.github.com/repos/adobe/brackets/releases{/id}","created_at":"2011-12-07T21:14:40Z","updated_at":"2014-12-12T16:35:09Z","pushed_at":"2014-12-12T05:55:31Z","git_url":"git://github.com/adobe/brackets.git","ssh_url":"git@github.com:adobe/brackets.git","clone_url":"https://github.com/adobe/brackets.git","svn_url":"https://github.com/adobe/brackets","homepage":"http://brackets.io","size":347910,"stargazers_count":20185,"watchers_count":20185,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4176,"mirror_url":null,"open_issues_count":1085,"forks":4176,"open_issues":1085,"watchers":20185,"default_branch":"master"}},"base":{"label":"adobe:master","ref":"master","sha":"774f0643847ba4f4d167192c539cfbccbeaee954","user":{"login":"adobe","id":476009,"avatar_url":"https://avatars.githubusercontent.com/u/476009?v=3","gravatar_id":"","url":"https://api.github.com/users/adobe","html_url":"https://github.com/adobe","followers_url":"https://api.github.com/users/adobe/followers","following_url":"https://api.github.com/users/adobe/following{/other_user}","gists_url":"https://api.github.com/users/adobe/gists{/gist_id}","starred_url":"https://api.github.com/users/adobe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adobe/subscriptions","organizations_url":"https://api.github.com/users/adobe/orgs","repos_url":"https://api.github.com/users/adobe/repos","events_url":"https://api.github.com/users/adobe/events{/privacy}","received_events_url":"https://api.github.com/users/adobe/received_events","type":"Organization","site_admin":false},"repo":{"id":2935735,"name":"brackets","full_name":"adobe/brackets","owner":{"login":"adobe","id":476009,"avatar_url":"https://avatars.githubusercontent.com/u/476009?v=3","gravatar_id":"","url":"https://api.github.com/users/adobe","html_url":"https://github.com/adobe","followers_url":"https://api.github.com/users/adobe/followers","following_url":"https://api.github.com/users/adobe/following{/other_user}","gists_url":"https://api.github.com/users/adobe/gists{/gist_id}","starred_url":"https://api.github.com/users/adobe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adobe/subscriptions","organizations_url":"https://api.github.com/users/adobe/orgs","repos_url":"https://api.github.com/users/adobe/repos","events_url":"https://api.github.com/users/adobe/events{/privacy}","received_events_url":"https://api.github.com/users/adobe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/adobe/brackets","description":"An open source code editor for the web, written in JavaScript, HTML and CSS.","fork":false,"url":"https://api.github.com/repos/adobe/brackets","forks_url":"https://api.github.com/repos/adobe/brackets/forks","keys_url":"https://api.github.com/repos/adobe/brackets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adobe/brackets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adobe/brackets/teams","hooks_url":"https://api.github.com/repos/adobe/brackets/hooks","issue_events_url":"https://api.github.com/repos/adobe/brackets/issues/events{/number}","events_url":"https://api.github.com/repos/adobe/brackets/events","assignees_url":"https://api.github.com/repos/adobe/brackets/assignees{/user}","branches_url":"https://api.github.com/repos/adobe/brackets/branches{/branch}","tags_url":"https://api.github.com/repos/adobe/brackets/tags","blobs_url":"https://api.github.com/repos/adobe/brackets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adobe/brackets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adobe/brackets/git/refs{/sha}","trees_url":"https://api.github.com/repos/adobe/brackets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adobe/brackets/statuses/{sha}","languages_url":"https://api.github.com/repos/adobe/brackets/languages","stargazers_url":"https://api.github.com/repos/adobe/brackets/stargazers","contributors_url":"https://api.github.com/repos/adobe/brackets/contributors","subscribers_url":"https://api.github.com/repos/adobe/brackets/subscribers","subscription_url":"https://api.github.com/repos/adobe/brackets/subscription","commits_url":"https://api.github.com/repos/adobe/brackets/commits{/sha}","git_commits_url":"https://api.github.com/repos/adobe/brackets/git/commits{/sha}","comments_url":"https://api.github.com/repos/adobe/brackets/comments{/number}","issue_comment_url":"https://api.github.com/repos/adobe/brackets/issues/comments/{number}","contents_url":"https://api.github.com/repos/adobe/brackets/contents/{+path}","compare_url":"https://api.github.com/repos/adobe/brackets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adobe/brackets/merges","archive_url":"https://api.github.com/repos/adobe/brackets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adobe/brackets/downloads","issues_url":"https://api.github.com/repos/adobe/brackets/issues{/number}","pulls_url":"https://api.github.com/repos/adobe/brackets/pulls{/number}","milestones_url":"https://api.github.com/repos/adobe/brackets/milestones{/number}","notifications_url":"https://api.github.com/repos/adobe/brackets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adobe/brackets/labels{/name}","releases_url":"https://api.github.com/repos/adobe/brackets/releases{/id}","created_at":"2011-12-07T21:14:40Z","updated_at":"2014-12-12T16:35:09Z","pushed_at":"2014-12-12T05:55:31Z","git_url":"git://github.com/adobe/brackets.git","ssh_url":"git@github.com:adobe/brackets.git","clone_url":"https://github.com/adobe/brackets.git","svn_url":"https://github.com/adobe/brackets","homepage":"http://brackets.io","size":347910,"stargazers_count":20185,"watchers_count":20185,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4176,"mirror_url":null,"open_issues_count":1085,"forks":4176,"open_issues":1085,"watchers":20185,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/adobe/brackets/pulls/10109"},"html":{"href":"https://github.com/adobe/brackets/pull/10109"},"issue":{"href":"https://api.github.com/repos/adobe/brackets/issues/10109"},"comments":{"href":"https://api.github.com/repos/adobe/brackets/issues/10109/comments"},"review_comments":{"href":"https://api.github.com/repos/adobe/brackets/pulls/10109/comments"},"review_comment":{"href":"https://api.github.com/repos/adobe/brackets/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/adobe/brackets/pulls/10109/commits"},"statuses":{"href":"https://api.github.com/repos/adobe/brackets/statuses/18d24e81911e3f976890442973e242a6ac6d579b"}}}}