Binary search for cursor placement


#1

Hi, I just created a prototype for a very simple package that implements a kind of binary search for cursor placement.

It works by allowing the user to choose a direction of cursor movements and moving the cursor in that direction as a binary search would do. The idea is that the user focuses on a spot where to place the cursor and then bin search to that spot issuing left/right commands.

You can try it for yourself by searching the package database for binsearch-positioning.

Since I am new to Atom development I am sure that the code can be much improved, any help/suggestion will be appreciated.

In particular I would like to know what you think about the idea and if you have any suggestions about the key binding to be associated with the left/right commands. Currently I am using ctrl-< and ctrl->, but I would prefer ctrl-left and ctrl-right. Unfortunately I don’t think this choice would play nice on all platforms, am I right?

If you do think that ctrl-left, ctrl-right are better choices, I cannot make atom to use that key bindings (probably to prevent the above mentioned problems on other platforms), do you have any idea about how to force that choice?

Update: I’ve changed the keybinding to ctrl-alt-left and ctrl-alt-right. Hope this improves the experience.

Another area where I know I need help is in testing the package. I have no idea how to best organise the tests given that the package depends on keyboard events (in particular on the “keyup” event to work properly). More in general I am not familiar with UI testing in Atom.

Thanks in advance to everybody.

Cheers.


#2

Hello.

It is possible to make different sets of key commands; a set for each OS. Also it is possible to make it available to have the user select if he wants to use these presets or have his own associations.

I am however not sure whereto to direct your focus to get the information you need. hopefully another would follow up with details.

Cheers.


Edit1 - Maybe some resources to look at:

  1. Different key-binding sets
    https://github.com/burodepeper/language-markdown/blob/master/keymaps/markdown.cson

  2. Enable default key-bindings
    https://github.com/burodepeper/language-markdown/blob/master/lib/main.js#180


#3

Hi danPadric, thanks for your reply and sorry for the time it took me to see it – I guess I need to change some of the notification settings :-).

I will have a look at the links you provided just for learning something new, however I am not planning right now further work on the package. It is working fine on my installation and by the lack of activity on github I guess that no one except me is using it.

Anyway, I thank you again and I will be sure to delve into that documentation in case issues are opened to fix this particular problem.

Cheers,
Roberto


#4

It’s very easy to add alternative keybindings for different operating systems, because Atom sets a class on the atom-workspace element that you can check to identify the current OS. Here’s an example of how to implement multiple command sets. It would take you less than five minutes to replicate that, so I think it’s definitely worth the time even if your package is not currently in heavy demand.


#5

Thanks @DamnedScholar!

You are right. Any suggestion about good bindings for windows and linux? I am not a user of those systems, so my guesses are probably of limited value…

Presently I’ve set them to:

   win32: ctrl-alt + left/right
   linux: alt + left/right
   darwin: ctrl-alt + left/right

Linux differs from the others since (at least in the window manager I am using in my virtual machine) ctrl-alt + left/right moves between spaces.

Thanks in advance for any suggestion.


#6

In general it’s about the same, with ctrl replacing cmd in almost every case. Yours look fine. On Windows, the only thing I have on ctrl-alt-left/right is an emmet navigation command, so that binding would work fine for me.