Author Topic: Keytip, some fixer-upper code for you  (Read 3272 times)

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Keytip, some fixer-upper code for you
« on: September 25, 2013, 11:26:20 AM »
Webstorm, or one of its plugins -- has this functionality where if you press a prefix key, then another key, the second key will be used to throw up a bunch of tooltips at places in your code where the second key letter exists. Each tooltip then has a unique hotkey letter on it, 0-9 a-z, and pressing one of those will move your cursor to that point in code. This beats using arrow keys or incremental search to move around.

I've only seen this functionality in a video so I don't know exactly how it works, but to avoid craziness, the implementation here does not do every matching letter -- only the ones that occur on word-type boundaries, at beginning or ends of words and subwords. But it does light up every non-alphanumeric. It is limited to 36 tips, but this can be changed.

This is fixer-upper code because there are a few basic functions you are going to build yourself because I don't have time to yank them out of my library due to dependencies. These are:
file2array(_str filename) and what I call 'hash' functions, which are structured storage.... hash_new, and then the pair -- void hash_push(typeless hash,_str dotpath, typeless val) and typeless hash_get_r(typeless hash, _str dotpath).

These just store and get data in the hash at the dotpath location ('a.hash.within.a.hash') type of stucture, like javascript objects. This macro only deals with a few XY values, so it all could easily be ported to use arrays.

You will also have to change the font on the label too, it is not on your machine. You will want to make it to match your editor font.
Note, when this is loaded on it will bog down while it creates 36 hidden tooltip forms, but once that is done the action is very responsive.

There is one major part where it does not operate properly -- if your cursor is scrolled out of view. I don't know how to detect that.

I think this is cool functionality, maybe Slickedit could pick it up.