{"action":"created","issue":{"url":"https://api.github.com/repos/philc/vimium/issues/1413","labels_url":"https://api.github.com/repos/philc/vimium/issues/1413/labels{/name}","comments_url":"https://api.github.com/repos/philc/vimium/issues/1413/comments","events_url":"https://api.github.com/repos/philc/vimium/issues/1413/events","html_url":"https://github.com/philc/vimium/pull/1413","id":53485516,"number":1413,"title":"A modal-browsing framework","user":{"login":"smblott-github","id":2641335,"avatar_url":"https://avatars.githubusercontent.com/u/2641335?v=3","gravatar_id":"","url":"https://api.github.com/users/smblott-github","html_url":"https://github.com/smblott-github","followers_url":"https://api.github.com/users/smblott-github/followers","following_url":"https://api.github.com/users/smblott-github/following{/other_user}","gists_url":"https://api.github.com/users/smblott-github/gists{/gist_id}","starred_url":"https://api.github.com/users/smblott-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smblott-github/subscriptions","organizations_url":"https://api.github.com/users/smblott-github/orgs","repos_url":"https://api.github.com/users/smblott-github/repos","events_url":"https://api.github.com/users/smblott-github/events{/privacy}","received_events_url":"https://api.github.com/users/smblott-github/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-01-06T06:27:44Z","updated_at":"2015-01-14T17:40:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/philc/vimium/pulls/1413","html_url":"https://github.com/philc/vimium/pull/1413","diff_url":"https://github.com/philc/vimium/pull/1413.diff","patch_url":"https://github.com/philc/vimium/pull/1413.patch"},"body":"Following on from #1406,  this is a more fleshed-out reworking of Vimium's keyboard handling into a system of (more or less orthogonal) modes.  The goal is to create a framework, based on which we can implement visual mode (and others).\r\n\r\nWhat this does:\r\n- Handles modes as a stack of `Mode` handlers on the `handlerStack`.\r\n- Implements modes: `normal`, `passkeys`, `insert`, `find`, `focus-input` and a `visual` mode template (plus a couple of utility modes).\r\n- Uses badges to provide visual feedback as to the current mode.  (This works surprisingly well.  I miss it already when I move back to `master`.) \r\n- Fixes a number of small bugs along the way (#1410, #1412 and a couple of others).\r\n\r\nHow does it work:\r\n- `normal` and `passkeys` modes are always an the stack.\r\n- A trigger mode for `insert` mode is also always on the stack.  If the focus drops into an editable element, this pushes `insert` mode onto the stack).\r\n- Other modes (`insert`, `find`, etc) are pushed and popped as needed.\r\n- In addition to `keydown`, `keypress` and `keyup`, `focus` and `blur` events are also bubbled down the mode stack.  This means we can handle modes/events in a single, unified way.  And there's a stack logic as to how they are distributed to active modes.\r\n- A number of pseudo events are also bubbled down the handler stack.  Also, some `extra` information is attached to each event bubbling down the handler stack.  This allows active modes to communicate (by attaching \"extra\" information to events).\r\n\r\nWhat does this facilitate:\r\n- The immediate priority is visual mode.\r\n  - So, a new command `v`.\r\n- Thereafter, we could consider a vim-like editing mode (which would be super convenient for longer text areas such as this one).\r\n  - So, a new command `gv`, like `gi`, but drops you into a vim-like editing mode.\r\n  - Within that mode, `v` drops you into visual mode, and `Ctrl-O` drops you (briefly) into a new `normal` mode.\r\n\r\nWhere to start:\r\n- Start by looking in `mode.coffee`, [here](https://github.com/smblott-github/vimium/blob/modes/content_scripts/mode.coffee).\r\n- Edit: No! Start by running it, and observe how surprisingly cool the badge looks.\r\n- Then perhaps take a look at `passkeys` mode [here](https://github.com/smblott-github/vimium/blob/modes/content_scripts/mode_passkeys.coffee), then perhaps `insert` mode [here](https://github.com/smblott-github/vimium/blob/modes/content_scripts/mode_insert.coffee). \r\n- Then.... well, the diff?  Post here if you need more information.\r\n\r\nMy experience is that modes are *considerably* easier to think about and work with.\r\n\r\nThe hideous, flat, tangle of logic we currently have in `vimium_frontend.coffee` remains, but much of that code can be culled.\r\n\r\nThis is not quite ready for prime time, but it's pretty close.  I'm still considering whether to flatten out the mode class hierarchy. The OO style can make it difficult to track down bugs.  So, while the hierarchy may be neat, it may not be helpful long term."},"comment":{"url":"https://api.github.com/repos/philc/vimium/issues/comments/69957301","html_url":"https://github.com/philc/vimium/pull/1413#issuecomment-69957301","issue_url":"https://api.github.com/repos/philc/vimium/issues/1413","id":69957301,"user":{"login":"mrmr1993","id":1847343,"avatar_url":"https://avatars.githubusercontent.com/u/1847343?v=3","gravatar_id":"","url":"https://api.github.com/users/mrmr1993","html_url":"https://github.com/mrmr1993","followers_url":"https://api.github.com/users/mrmr1993/followers","following_url":"https://api.github.com/users/mrmr1993/following{/other_user}","gists_url":"https://api.github.com/users/mrmr1993/gists{/gist_id}","starred_url":"https://api.github.com/users/mrmr1993/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrmr1993/subscriptions","organizations_url":"https://api.github.com/users/mrmr1993/orgs","repos_url":"https://api.github.com/users/mrmr1993/repos","events_url":"https://api.github.com/users/mrmr1993/events{/privacy}","received_events_url":"https://api.github.com/users/mrmr1993/received_events","type":"User","site_admin":false},"created_at":"2015-01-14T17:40:33Z","updated_at":"2015-01-14T17:40:33Z","body":"> No no, I mean \"mentally consider\" :smile:\r\n\r\nSorry, I misunderstood.\r\n\r\n> ... we would need to teach users to treat Vimium icon as an indicator of the current mode ...\r\n\r\nThe issue is, it's hard to achieve this when users have already hidden the icon, since we need them to explicitly re-enable it to show them the new UI. Otherwise we're just penalising them for hiding the icon back when it held little value."}}