Sublime Forum

"Smart" horizontal cursor positioning

#15

Yeah ! Thanks for the helping hand John.

It looks like everything works fine now.
Maybe there’s still something to do to simplify the code, but I have no time right now to dig further… Maybe later.

Actually, I seriously think to replace the standard up/down cursor with these ones. But maybe jps already thought about putting something similar in the core ST2 :wink:

Grab it at https://github.com/bizoo/SmartCursor and give it a try.

1 Like

#16

For what it’s worth, I’ve replaced the standard up and down arrows with this. I did this:

[code] { “keys”: “up”], “command”: “smart_cursor”, “args”: {“cmd”: “move”, “by”: “lines”, “forward”: false}, “context”:

  { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]

},
{ “keys”: “down”], “command”: “smart_cursor”, “args”: {“cmd”: “move”, “by”: “lines”, “forward”: true}, “context”:

  { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]

},
[/code]

1 Like

#17

Thanks adzenith for the keybindings, will replace the examples from github with these ones.
I’ve just added it to my keybindings !

1 Like

#18

This sounds cool. I need to give this a try.

1 Like

#19

Updated github right now with the new keybindings from adzenith and the fixes for the only issues I’ve found after a day of work:
-After selecting a text from right to left and delete/modify it, caret must be placed to the starting point of the selection (so, technically, always sel.a and not sel.begin()).
-Move down after an edit at the last line of the file move the caret horizontally but, of course, not vertically, which is IMHO not what users are expecting.

1 Like

#20

[quote=“adzenith”]For what it’s worth, I’ve replaced the standard up and down arrows with this. I did this:

[code] { “keys”: “up”], “command”: “smart_cursor”, “args”: {“cmd”: “move”, “by”: “lines”, “forward”: false}, “context”:

  { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]

},
{ “keys”: “down”], “command”: “smart_cursor”, “args”: {“cmd”: “move”, “by”: “lines”, “forward”: true}, “context”:

  { "key": "auto_complete_visible", "operator": "equal", "operand": false }
]

},
[/code][/quote]

@adzenith:
I used these keymaps but found a small issue:
When you go at the end of the auto complete list, press one more down close the auto complete and execute a move down command, not a smart_cursor down command.
If I remove the context, it works as expected.

Did you find an issue with enabling the smart_cursor for auto complete or did you add context ‘in case of’ ?
Thanks for your reply.

1 Like

#21

@adzenith
I know it’s a old question (previous post), but I’m still interested by the answer.

1 Like

#22

Hey, sorry, didn’t notice the question until just now! I seem to recall I added them because I couldn’t use the arrow keys to navigate autocomplete.
I just tried taking the context out, and it causes a different bug:

foo| [autocomplete window, item 0 selected]

press down

|foo [autocomplete window, item 1 selected]

The insertion point moves to the beginning of the line.

1 Like

#23

Thanks for your answer.

I couldn’t reproduce this bug, or I don’t understand it:
You mean that when changing selection in autocomplete window, the cursor move in the file view ?
I couldn’t reproduce it.
Do you have the last version of the repository https://github.com/bizoo/SmartCursor

1 Like

#24

Haha nope! Looks like I still had the second commit or so. I think I’d checked out the code using git so Package Manager stopped updating it. Whoops! Works now. :smile:

1 Like

#25

Oh wait, hold up, it’s doing it again.
Open a new buffer, set it to Python (so we get autocomplete), and type:

foo foobar f
now press down. For me, it snaps to the beginning of the line.

1 Like

#26

Yes you’re right, there’s something that goes wrong when autocomplete is triggered.
Thanks for your feedback, I’ll take a look on this issue later…

If only Jon could implement this feature in core ST3 :wink:

1 Like

#27

I just discovered also that you can’t navigate the sidebar with the arrow keys unless you have those contexts set up…

1 Like

#28

Is it ST3 compatible bizoo?

1 Like

#29

It must works on ST3 as is.

1 Like

#30

I just wanted to say thank you for creating this plugin. I also migrated from TextPad on Windows and the smart cursor feature in that program was a real insight into how programmers actually use the cursor. As far as I can tell in my initial usage you’ve correctly adapted this feature to ST.

To contribute, I noticed on this threat that aren’t any newb instructions for installing this. So I’ll add those here and hopefully help anyone else who comes along. These instructions are for ST 2

  • Install Sublime Package Manager following these instructions: sublime.wbond.net/installation
  • Restart Sublime (not sure if this is required)
  • Menu: Preferences / Package Control
  • Choose “Add Repository”
  • Paste in: github.com/bizoo/SmartCursor
  • Menu: Preferences / Package Control
  • Choose “Install Package”
  • Type SmartCursor
  • You should see the SmartCursor plugin - click on it to install
  • Takes a few seconds to download and it should show success at the bottom of ST
  • Add the keybindings to your user keybinding file by:
    ** Menu: Preferences / Key Bindings - User
    ** Paste this file into your Key Bindings: raw.github.com/bizoo/SmartCurso … ime-keymap
    ** (Note this file is also located in [sublime program folder]/Data/Packages/SmartCursor if it’s easier to get from there)
    ** Save and close
  • Restart Sublime (not sure if this is required)

If anyone sees errors in those install instructions, please repost with corrections. I hope this helps another beginner with Sublime Text and SmartCursor! Thanks for developing this!

Keywords to help others find this thread: TextPad, Sublime Text, cursor position, new line, arrow keys, cursor behavior, change

1 Like

#31

Was just made aware of the SmartCursor plugin, which I haven’t yet had the chance to try.

I added the following to the existing (three year old!) request on user echo, to mimic TextPad’s behavior. It comes from my blog.

TextPad is much smarter with cursor placement

This seemingly small and subtle thing is actually what I miss most most. TextPad is much smarter about where to place the cursor when pressing the up and down keys.

First, place your cursor here, either with the keyboard or mouse:

http://i.imgur.com/kEUndtN.jpg

Type “Hello”:

http://i.imgur.com/7fmvZPh.jpg

And then press the down arrow. Sublime takes you here:

http://i.imgur.com/vsFw9lA.jpg

TextPad takes you here:

http://i.imgur.com/Q3fToVI.jpg

This makes it much much easier to do common things on contiguous lines, such as populate lists with unique values. It remembers where you originally placed the cursor, or where you started typing (after navigating around with arrows).

The second part of this is that, when clicking outside of the right margin, the remembered position is where you click the mouse, not where the cursor is actually placed. So the cursor goes to the end of the line, as you expect

http://i.imgur.com/t1aTOPL.jpg

But when you press down, Sublime goes here

http://i.imgur.com/fejI0J8.jpg

And TextPad goes here

http://i.imgur.com/tFDX7E0.jpg

In both situations, in TextPad, clicking the right or left arrow resets the position.

1 Like

#32

SmartCursor is not available via ST3 Package Control. :frowning:

Just manually installed it, via the “download zip” button on the github page. Had to unzip it, then re-zip the contents–not the folder–as SmartCursor.sublime-package.

At first glance, it WORKS with situation one in my above description, when the cursor is in the middle of the line.

It doesn’t work in situation two, when the cursor is clicked outside of the right margin. Any plans for this?

But that’s a huge improvement!! :smile:

1 Like

#33

[quote=“aliteralmind”]SmartCursor is not available via ST3 Package Control. :frowning:

Just manually installed it, via the “download zip” button on the github page. Had to unzip it, then re-zip the contents–not the folder–as SmartCursor.sublime-package.[/quote]

There’s a post in this topic on how to install it using Package Manager (http://www.sublimetext.com/forum/posting.php?mode=reply&f=4&t=2529#pr53225)

If I understand your explication, it’s more or less the behavior of the END key:
That put the cursor at the end of the current line and tell ST to always go to the end of line when moving up/down.
There’s also a post from jps on the subject (https://forum.sublimetext.com/t/smart-horizontal-cursor-positioning/2050/14&hilit=xpos#p38288)

But I’ve no plan to do something like that, don’t think it’s useful for me and it is probably very difficult to implement with the current mouse API.

1 Like

#34

Appreciate the response. Even in its current state, it’s much much better than without it. So thanks.

1 Like