Sublime Forum

"Smart" horizontal cursor positioning

#11

I was going to report a bug, but then it was already fixed by that “small modification” you made. Thanks!

1 Like

#12

Bizoo, you may be able to implement this is a cleaner way using the xpos attribute of selection regions. If it’s not -1 when the caret is moved down a row, then it specifies the column (in layout coords) for the caret to be placed in.

You can see it in action by pressing end and then down: the caret will be maintained at EOL. Currently, it automatically set to -1 whenever the buffer is edited, so you’d need to find appropriate places to get and set the value.

3 Likes

How: Cursor beyond end-of-line?
Problem with xpos
Reset the move by lines target column
Vintage mode, retain column position
#13

Didn’t know about xpos, thanks for the heads-up.

But I don’t understand exactly what to do with it:
xpos() give me the ‘expected’ position for the cursor, but I don’t think there’s a way to set the xpos(), am I wrong ?

With my current implementation, I set the caret horizontal position before executing the move command.
This way the navigation are still managed by ST2 and work fine even if the next line (when move down) is smaller than the current caret position (so the xpos is correct out of the box).
The only problem is when you need the caret beyond the end of line, so when I need to set xpos.

If xpos is a read-only value, I don’t see any uses for this plugin (but could be useful for others).
Am I missing something ???

1 Like

#14

You can set the xpos by passing a 3rd argument to the Region constructor: sublime.Region(a, b, xpos)

1 Like

#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