Home Download Buy Blog Forum Support

"Smart" horizontal cursor positioning

Re: "Smart" horizontal cursor positioning

Postby adzenith on Tue Oct 09, 2012 6:32 pm

I was going to report a bug, but then it was already fixed by that "small modification" you made. Thanks!
adzenith
 
Posts: 1204
Joined: Mon Oct 19, 2009 9:12 pm

Re: "Smart" horizontal cursor positioning

Postby jps on Thu Oct 11, 2012 8:11 pm

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.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: "Smart" horizontal cursor positioning

Postby bizoo on Thu Oct 11, 2012 9:30 pm

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 ???
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: "Smart" horizontal cursor positioning

Postby jps on Thu Oct 11, 2012 11:24 pm

You can set the xpos by passing a 3rd argument to the Region constructor: sublime.Region(a, b, xpos)
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: "Smart" horizontal cursor positioning

Postby bizoo on Fri Oct 12, 2012 1:19 pm

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 ;)

Grab it at https://github.com/bizoo/SmartCursor and give it a try.
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: "Smart" horizontal cursor positioning

Postby adzenith on Fri Oct 12, 2012 11:52 pm

For what it's worth, I've replaced the standard up and down arrows with this. I did this:
Code: Select all
  { "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 }
    ]
  },
adzenith
 
Posts: 1204
Joined: Mon Oct 19, 2009 9:12 pm

Re: "Smart" horizontal cursor positioning

Postby bizoo on Mon Oct 15, 2012 9:14 am

Thanks adzenith for the keybindings, will replace the examples from github with these ones.
I've just added it to my keybindings !
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: "Smart" horizontal cursor positioning

Postby facelessuser on Mon Oct 15, 2012 3:49 pm

This sounds cool. I need to give this a try.
facelessuser
 
Posts: 1459
Joined: Tue Apr 05, 2011 7:38 pm

Re: "Smart" horizontal cursor positioning

Postby bizoo on Tue Oct 16, 2012 8:24 am

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.
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: "Smart" horizontal cursor positioning

Postby bizoo on Mon Nov 12, 2012 2:06 pm

adzenith wrote:For what it's worth, I've replaced the standard up and down arrows with this. I did this:
Code: Select all
  { "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 }
    ]
  },

@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.
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

PreviousNext

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 8 guests

cron