Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap without loosing cursor position #19

Open
ggutierrez opened this issue Apr 19, 2013 · 8 comments
Open

Wrap without loosing cursor position #19

ggutierrez opened this issue Apr 19, 2013 · 8 comments

Comments

@ggutierrez
Copy link

It will be very nice when wrapping a paragraph to not loose the current cursor position. That is, after the operation the cursor should remain in the position were it was when the operation was invoked.

@andialbrecht
Copy link

For me it was enough to have the cursor at the end of the last paragraph (instead of below the last paragraph) so I helped myself by commenting line 595 in wrap_plus.py.

That's not really what you want, but for me the current cursor position is at the end of the last paragraph most of the time when I use wrap. Would be nice to see a config option for this too.

@samueljohn
Copy link

👍

@NikolausDemmel
Copy link

+1 on @andialbrecht's suggestion.

@thp-comnets
Copy link

any progress on this issue? I also think the cursor should remain in the current position instead of jumping to the end of the paragraph.

@ggutierrez
Copy link
Author

My workaround is simple. Create a new plugin with the following implementations:

import sublime, sublime_plugin

class MyWrapCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        pos = self.view.sel()[0].begin()
        self.view.run_command('wrap_lines_plus')
        self.view.sel().clear()
        self.view.sel().add(sublime.Region(pos))

Then add the following to your key bindings file:

  { "keys": ["alt+q"], "command": "my_wrap" },

replace the key binding for something tat suits your needs.

@thp-comnets
Copy link

+1 @ggutierrez
thank you very much, that works perfectly fine

evandrocoan added a commit to evandrocoan/ITE that referenced this issue May 9, 2017
evandrocoan added a commit to evandrocoan/ITE that referenced this issue Jun 19, 2017
@evandrocoan
Copy link

evandrocoan commented Apr 26, 2019

I just fixed this on my fork. It took me a lot of work until get it working almost 99% correctly. There are just some rare edge cases: https://github.com/evandrocoan/WrapPlus

Just remember, it has a setting to control this behavior:

    // Control the cursor behavior while wrapping the text. It accepts the following:
    // "cursor_below", will move the cursor/caret to the end the the wrapped text
    // "cursor_stay", will `attempt` to keep the cursor/caret on its original position
    "WrapPlus.after_wrap": "cursor_stay",

@stephen147
Copy link

stephen147 commented Apr 20, 2021

Thanks, @ggutierrez, I changed that py code to:

import sublime, sublime_plugin

class WrapPlusCursorFix(sublime_plugin.TextCommand):
  def run(self, edit):
    pos = self.view.sel()[0].end()
    self.view.run_command('wrap_lines_plus')
    self.view.sel().clear()
    self.view.sel().add(sublime.Region(pos))

It places the cursor at the end of the selection instead of begin().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants