Henry Dowling's Blog

Autocomplete everywhere that reads your mind

September 26, 2025

Codeswitch autocomplete system overview

To explore uses for our personal AI memory store at Fergana Labs, we built a system-wide contextual autocomplete for MacOS. To hydrate it with context, we built a tool to grab text from input fields via a11y APIs, screen OCR and in some cases a Chrome extension. We named it Codeswitch, and you can try it here![1]. For a demo of how it works, see here.

To build this so that it works well on MacOS, we had to make some interesting / unconventional design decisions. In this blog post, I'll walk through these decisions.

Using Accessibility tools to mock grey "ghost" text + replace text

Most of the standard autocomplete operations (suggested text, replacing text for "rephrase feature") are not possible without MacOS a11y APIs.

Screenshot showing ghost text appearing in a text field
We create ghost text EVERYWHERE that a user can type

Hijacking the system clipboard to actually add the suggestion on "tab"

Reverse engineering Google Docs' canvas-based rendering

It was important to us that the project works in Google Docs. However, Google Docs’ canvas-based rendering made all of our techniques for getting text (accessibility selection to get cursor position for grey text, read text, select text to paste over it) useless. As a workaround, we wrote a chrome extension to help us get this information from the user. Unfortunately, that means users need to install the chrome extension for Codeswitch to work in Docs.

Then we had to figure out what text was selected. Since Google Docs doesn’t actually display any text elements in the browser, we reverse-engineered Google Docs’ API to grab the UI elements that store text within their custom rendering.

Reverse-engineering approach to finding text elements in Google Docs

We found this discussion of how Google’s Canvas-based rendering works extremely helpful.

Determining selected text in Google Docs

Unfortunately, Google Docs renders each line in the canvas as a monolith, so we still needed to figure out what text was being selected. So, given a cursor position in a line and a set of text in the line, we need to estimate which text was selected. To achieve this, we render actual text invisibly on the page, and then measure at which character the selection must start given its real position.

Demonstration of Google Docs canvas rendering hack
We determine which characters were highlighted by rendering invisible text in the document with our chrome extension and measuring its length.

Screen OCR for context when a11y APIs fail

While accessibility APIs are great when they work, plenty of applications (most notably Chrome) don't properly expose their text content through these channels. We built an OCR system to capture context from these stubborn apps[2].

Learnings


Shameless plug: If you think this kind of thing is cool, come work with us at Fergana Labs.

[1] If you're looking for an invite code and don't have one, you may be able to find one if you're clever enough ;)

[2] The OCR feature is currently disabled by default-- we were concerned with privacy and battery life-- but it can be enabled in app settings if you're brave enough to try it out.

[3] We also have additional caching in our AI memory store to limit redundancies, but that's for another blog post.

[4] Related work: check out Tabracadabra, which launched around the same time we built this. When we saw this launch midway through work on this, we concluded that this is an idea that's in the scientific zeitgeist rn.