When I saw this, I IMMEDIATELY thought of a tweet from Raymond Camden that I know I’ve seen on more than one occasion.
And I’m pretty sure this is not the first time he’s tweeted this. Let me check…
Yep. Clearly Raymond is predisposed to transpose. But we all know the struggle is real; Raymond is just the only person out here running a campaign to get a “Fat Fingers” standard added to the ECMAScript specification.
“Well, I don’t have fat figners.”
Yes you do! You just misspelled “FINGER”!
So all of our fingers are obese (metaphorically speaking), and I’m skeptical that TC39 is going to do anything to help us out here because they are too busy implementing things like Control Abstraction Operators — whatever the heck that is.
HOW IS THIS WORKING?!
While I’m not privy to the exact code which does this (even if I was, my puny bald head would likely explode), here is what I can see with my eyeballs when I trigger the intellisense in VS Code.
Intellisense is pretty good at doing a forward lookup on whatever term you are typing. In the case of “function”, as long as the letters you are typing are in the same sequential order they are in the word, VS Code will match the word you are looking for. For instance, if we typed every other character in “function” (fnto), it would match like this…
And this search works skipping any amount of letters while going forward in the word.
This makes logical sense, but doesn’t address the problem of transposing characters.
Transposing is when you have the right characters, but their places have been switched by mistake. This happens a LOT when typing. This would be the error of typing “funciton” (t ⟲ i) or “fucntion” (n ⟲ c). This is not because the brain tries to spell the word that way, but because we’re typing so fast that mistakes just happen, probably because the fingers can’t move as fast as the brain.
It looks to me that to account for this issue, VS Code will now look backwards in the string for a matching character. The characters do not have to be right next to each other. In this example, VS Code matches the “c” in “function” even though I completely skipped it and typed an “o” and then included the “c” later.
But it looks like this only works once. In other words, VS Code will do a backwards search, but once it has a match it won’t do any more backwards searches but will continue to search forward.
For instance, you can type “ftuo” and get a match because the “u” come before the “t” and the “o” comes last.
But if you add a “c” here, intellisense will not do a second backwards search and so the word is not recognized.
Also note that any futher forward searches will occur after the last match. Simply put, VS Code intellisense now supports one transposition error within your string.
So to sum all of that up, as long as your word starts with the right character, and you only have one letter that is out of sequential order, VS Code will give you a match.
Also, typing “potatoe” triggers a match for
Since publishing this article, the VS Code team was nice enough to shed some light on how this is actually working…
The logic is pretty simple: We have an algorithm that computes a score given a
fuzzyScore). That itself doesn’t do any permutations nor backwards matching but checks that all pattern-characters occur in the word in order (and it picks the best of those occurrences, e.g.
^black_^knight). Given that algorithm we can simply tweak the
patternand call it multiple times, either when no match was found or to see if a stronger match can be computed (aggressive).
Johannes Rieken — VS Code Team
So it’s a lot smarter than I made it out to be as the algorithm is essentially creating a bunch of possible transposition errors (7 to be exact — if the word is at least that long) and then scoring any of the matches against each other to determine the best result.
You can go ahead and check out the source code that does this yourself since VS Code is open-source and all.
Here’s To You
This one is for you Raymodn, and all of the rest of whose brains are too big and fingers too fat. You never gave up, never lost hope and finally your day is here. I mean it’s not really here because this isn’t exactly what you were asking for but as my wife told me last year when I sang “Happy Birthday” to her on the wrong day, “CLOSE ENOUGH!”
Check out all of the new features in the November release of VS Code.
Satire Dislcaimer: This article is a clinic in poor writing. I do not think that you have fat fingers either literally or metaphorically. Any mispellings are intentional because it’s ironic in this context. I literally can’t do anything wrong here.
Special thanks to Johannes Rieken on the VS Code team