Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fail to emulate user's input when focused element changed in middle of replaying keystroke. #130

@t9md

Description

@t9md

This is feature enhancement request to solve following problem, limitation.

Problem scenario

Following keymap is not actual scenario I'm facing. But for clarity.

When I have following keymap, keystroke cmd-t a don't put a character to fuzzy-finder's mini-editor.
Without this keymap(default), cmd-t a keystroke put a char to fuzz-finder's mini-editor.
I want put a on mini-editor even if I set following keymap.

'atom-workspace:not([mini])':
  'cmd-t': 'fuzzy-finder:toggle-file-finder' # default for mac 
  'cmd-t t': 'tree-view:toggle'

Reason

When atom-keymap replaying keystroke, it replaying against original event.target, not aware of focused element change.

Proposal to fix

idea-1

Change this line.

From

target = event.target

To

target = if replay then document.activeElement else event.target

idea-2

Provides public API to manually inform focus change to atom.keymap.

# change focus to read input from user
miniEditorElement.focus()
if atom.keymap.isReplaying()
  # explicitly inform focus change to replayed keystroke goes this element.
  atom.keymap.updateTarget(newFocusedElement)

Background

I'm developing vim-mode-plus(this issue is also affect official vim-mode).

t9md/atom-vim-mode-plus#260
t9md/atom-vim-mode-plus#254

For example, vim-mode has m command to mark current cursor position.
m take single a to z char from user via mini-editor.
So user can save cursor position to a mark by ma, to b mark by mb.
Since I don't need such big number of mark, I want to map mm to different command.
But after I set "m m": "different-command" keymap, original m breaks.

E.g. The keystroke md to save position to d mark will throw error(in vim-mode, vim-mode-plus case).

Why? replayed d is handled by oringal event.target(=editorElement) and d matches vim-mode-plus:delete command.
But this is unexpected scenario where another operation command is pushed to vim-mode-plus's operationStack while previous command m(mark) command have not yet finished(in this timing vim-mode is just waiting mark char through mini-editor).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions