I give up, there's no way to get Snippet Pixie to auto-expand snippets while typing in non-accessible applications such as browsers or those developed with Electron etc.
I tried monitoring keystrokes at a higher level for tell-tale snippet triggers, then faking keystrokes to backtrack select characters and check the select clipboard for an abbreviation match. This turned out to be a rather resource intensive and flaky method of working out whether a snippet should then be stuffed into the clipboard and pasted over the selection.
I iterated on that method a lot, came up with some routines that made it more and more reliable and performant, but still, some times you had to wait for the checking to do its thing and could often see the selection walking when the error correction and retries kicked in to combat the temperamental async Linux clipboard. If you created any abbreviations that ended in commonly used letters or punctuation characters then you could often find yourself frustratedly waiting for Snippet Pixie to fail so you could carry on typing.
I created a snippet on purpose that I knew would piss me off, it ended in a "$". I did this to drive my desire to improve the algorithm whenever I was writing code for my day job in PhpStorm, you use
$ a lot in PHP. It worked to some extent, it caused me enough headaches that I often ended up right clicking Snippet Pixie's icon and hitting "Stop Snippet Pixie" so I could get on with my day. This would impact other areas of my day as I would seriously miss not having a text expander while answering support requests etc. Just silly things, like not wanting to type "WP Offload Media" over and over again, "ome`" is way shorter and easier to type.
A little over a fortnight ago I was using the most excellent Ideogram app by Cassidy James Blaede to pop open an emoji picker and pick 👍️ for the millionth time that day, when it occurred to me that maybe I should just give in, stop fighting non-accessible apps, and also create a shortcut popup window to search for and paste snippets. So that's what I've done.
You can open Snippet Pixie's "Search and Paste" window at any time by hitting its shortcut, which by default is Ctrl+` (grave).
You can then just start typing the abbreviation or anything you remember from the abbreviation or its contents to narrow down the list of snippets. Hit tab to focus the list, and then either navigate the list with the usual up and down arrows etc and hit Enter on the one you want to use, or hit its number. You can just press Escape or the Ctrl+` shortcut again if you change your mind and don't want to paste a snippet.
When you do choose a snippet from the Search and Paste window it'll close and the expanded text will be sent to the system clipboard and then pasted into whatever app you had open before hitting the shortcut.
It works really well, and the window and general usage pattern may look really familiar to some people. That's because a lot of the code for the Search and Paste window and how it safely closes and pastes is adapted/liberated/borrowed/stolen from Clipped by David Hewitt.
Until I started this little exercise a couple of weeks ago I'd never actually used Clipped before, but had used some of its code when trying to get Snippet Pixie compatible with browsers etc previously. I was led to that code via comments in Ideogram's own code that first time, it worked well for what I needed those bits to do. When I started thinking about how to do a popup snippet search and paste window I first took a look at Ideogram, but that quickly led me to Clipped again. This time I took a much deeper look at the app's code, and had a play with it, it's fantastic! As much as I love the convenience of snippets, I'd not really used a clipboard manager before, but now that I've got Clipped I'm a convert, it's saved me having to go back and re-copy and paste stuff many times.
Anyway, back to Snippet Pixie. It wasn't all plain sailing, but I was able to adapt a good chunk of code from Clipped for the new search and paste window, sprinkle in some code for working with snippets, showing their abbreviations and bodies, and a few little tweaks here and there, and Bob's your uncle, we have a search and paste window opening from a shortcut. 🎉️
While I've now been able to rip out all the janky clipboard code I was using for searching entered text for an abbreviation to auto-expand, auto-expansion is still in place for accessible apps. So if you're a fan of Quilter, LibreOffice, or any other native Linux app that is accessible, then you're all good, type your abbreviation and Snippet Pixie will expand it in-place for you. You don't have to use the shortcut.
However, if you decide that you prefer the shortcut, or maybe still have issues with auto-expansion in accessible apps 😱️, then Snippet Pixie now has a new "Auto expand snippets" setting you can toggle on and off in its revamped preferences menu, which has also gained a "Shortcut" submenu.
Oh, yeah, the shortcut, that too was initially inspired by some of Ideogram's code, but I also found some interesting stuff in Clipped regarding being able to change the shortcut. In Snippet Pixie's Shortcut preferences submenu you can change the shortcut from Ctrl+` to whatever suits you best. Just click on the existing shortcut and you'll be asked to type a new one.
In the above screenshot you can also see a couple of settings related to how the shortcut works.
You can turn on "Search selected text" if you like. When on, if you have any text selected in an app before you hit the Snippet Pixie search and paste shortcut, then that will be used as the initial search for snippets. It's off by default for a reason though. While at first I thought it was an awesome idea, in reality I often found that the search text was being populated with text I didn't expect, such as previously copied text. This is an unfortunate side effect of how the Linux clipboard works, it's quite easy for the "select" (a.k.a Primary) clipboard to end up with the contents of the copy clipboard. That kind of makes sense when you think about how you first select text and then copy it, but it is a bit annoying some times.
However, if you also use the on by default "Focus search box" setting, then it's not a huge deal as you can just start typing to replace what was automatically inserted into the search box. This is a diversion from how Clipped works, which naturally selects the list of previous clipboard entries as you're very likely to want something just recently clipped and therefore it's more convenient. But with Snippet Pixie I find I'm generally searching for an abbreviation anyway, so by default I've switched initial focus to the search box. However, turn off that "Focus search box" setting and the first entry in the list of snippets will be selected when the window opens. This does have its attractions too when "Search selected text" is enabled as you could find you've got a narrow list of snippets to hand and can quickly select the one you want without having to hit the tab key to focus the list first. 🤷♂️️
So that's it really, Snippet Pixie 1.4.0 is now available on the elementary OS AppCenter, and will be available on the Snap Store soon¹.
Here's the changelog for Snippet Pixie 1.4.0:
- Added Search and Paste window, opened with shortcut Ctrl+` by default.
- Added "Auto expand snippets" checkbox to preferences menu for enabling/disabling snippet expansion while typing in accessible apps.
- Added ability to change Search and Paste shortcut in preferences menu.
- Added preference for whether text selected before using shortcut is used for initial search.
- Added option to focus search box when using the search and paste shortcut.
- Fixed support for Wayland.
- Removed auto expanding of snippets in non-accessible applications such as browsers and electron apps (use shortcut for search and paste window instead).
¹ I'm holding off on the Snap just now as there's a couple of improvements in 1.4.1 that are important to Snaps, once through review and test I'll promote it to the Snap's stable channel.