How to gain "keyboard focus" back to Ace editor?

290 views
Skip to first unread message

Linfeng Li

unread,
Oct 21, 2021, 9:27:47 AM10/21/21
to Ajax.org Cloud9 Editor (Ace)
Hi,

Is there a way to emulate mouse-clicking on the Ace editor? The simple .click() method does not seem to work with elements "found" as part of the Ace editor. Actually, for my use case, it helps to map, say, <esc><esc> to directly regain "focus" back to the Ace editor. (Or, <c-[><c-[> if one is used to replace ESC with Ctrl+[.)

I am having trouble returning the focus of the "text cursor" to the Ace editor after interacting with a writefull-suggestion-card object generated by Writefull, a spell-checker tool on Overleaf. Writefull is installed as a Chrome extension.

Is there a specific event to trigger that will regain the "keyboard focus" back to the Ace editor? Physically clicking anywhere in the editor with a mouse gets the job done.

Below is the status of the cursor when I cannot do anything with Vim key-bindings and with on key-bindings, respectively.
  • With Vim key-bindings:
    • Right after accepting the Wrifefull suggestion, the cursor changes to be an empty box: vim_cannot_type.png
    • I need to click somewhere with mouse to get the normal cursor back: vim_after_clicking.png
  • Without key-bindings
    • Right after dismissing the Wrifefull thing, the cursor is gray, and I cannot type anything ==> no_binding_cannot_type.png
    • After a mouse click somewhere on the editor window, the cursor restores to be solid color, and I can continue typingno_binding_after_mouse_click.png
All the best,

-Linfeng

Harutyun Amirjanyan

unread,
Oct 21, 2021, 11:39:32 AM10/21/21
to ace-d...@googlegroups.com
Hi calling editor.focus() or focusing the invisible textarea inside the editor should work

Linfeng Li

unread,
Oct 21, 2021, 4:48:30 PM10/21/21
to ace-d...@googlegroups.com
Indeed, editor.focus() gets the job done.

To get my hands on the "editor" object, I end up using the following
var editor = window._debug_editors[window._debug_editors.length -1]
editor.focus()

Thanks a lot!

All the best,

-Linfeng
Reply all
Reply to author
Forward
0 new messages