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

CursorRuler changes behavior of "Wrap Paragraph at Ruler" #3

Closed
toddmazierski opened this issue Aug 20, 2013 · 7 comments
Closed

CursorRuler changes behavior of "Wrap Paragraph at Ruler" #3

toddmazierski opened this issue Aug 20, 2013 · 7 comments

Comments

@toddmazierski
Copy link

When CursorRuler is enabled, it appears to change the behavior of the "Wrap Paragraph at Ruler" (wrapLines) command. When the command is invoked, instead of wrapping at a fixed width (ex. 80 characters), it wraps at the cursor's current location.

To work around this bug, I'm overriding the default key binding to include a width argument. For example:

{ "keys": ["super+alt+q"], "command": "wrap_lines", "args": {"width": 80} }
@icylace
Copy link
Owner

icylace commented Aug 21, 2013

I could not replicate this bug in ST2 or ST3. The "Wrap Paragraph at Ruler" command as well as all the other wrap commands in the Edit > Wrap menu work fine for me with CursorRuler enabled.

Are you saying this bug only occurs when CursorRuler is enabled ? Have you tried disabling it and seeing if the bug goes away or persists ?

There shouldn't be any code within CursorRuler that would edit the contents of a view buffer.

@toddmazierski
Copy link
Author

Interesting! I'll provide more information, then. The version of Sublime Text 3 I'm using is "Dev Channel, 3052" on Mac OS 10.7.4.

Here's a video demonstration of the bug: http://cl.ly/1b021S3W3T0h There are 3 parts:

  1. [0:00] Without CursorRuler installed, observe that the text is wrapped at 80 characters, regardless of the cursor location
  2. [0:18] With CursorRuler installed, observe that the text wraps at the cursor's location
  3. [0:38] Without Cursor installed, observe that the behavior returns to that of part 1

@icylace
Copy link
Owner

icylace commented Aug 21, 2013

Thank you for the video demonstration !

I followed the steps that you have shown but was still unable to reproduce the effect you're getting. I would suggest doing a clean install of ST3 with Package Control and trying this experiment again. I just did that myself using the following settings in my user preferences for the sake of this experiment:

{
"rulers": [60],
"wrap_width": 60,
"word_wrap": false
}

This worked for me. Does this work for you ?

@toddmazierski
Copy link
Author

You're welcome!

If I use settings you just shared, I cannot reproduce the bug. However, if I revert back to the defaults (used in the video and shown below), the bug returns.

// Columns in which to display vertical rulers
"rulers": [],

// Disables horizontal scrolling if enabled.
// May be set to true, false, or "auto", where it will be disabled for
// source code, and otherwise enabled.
"word_wrap": "auto",

// Set to a value other than 0 to force wrapping at that column rather than the
// window width
"wrap_width": 0,

@icylace
Copy link
Owner

icylace commented Oct 3, 2013

Ah, interesting !!!

I was finally able to reproduce the errant behavior just by using both "rulers": [] and "wrap_width": 0. ST3 is affected by this but not ST2.

Since CursorRuler is essentially a hack of the rulers preference setting the wrapLines command unfortunately assumes that the dynamic cursor rulers created by CursorRuler are regular static rulers that may be wrapped around.

In theory, the way to get around this would be to bind the menu options and shortcut keys that use the wrapLines command in its default state to a custom command which temporarily turns off CursorRuler using its cursor_ruler_toggle command (which itself is used by "CursorRuler: Toggle Enabled/Disabled" in the command palette) and then calls wrapLines to do the wrapping without the unwanted influence of CursorRuler's rulers and then finally calling cursor_ruler_toggle once more to restore CursorRuler.

I did a quick search and found a thread on running multiple commands in tandem: http://www.sublimetext.com/forum/viewtopic.php?f=5&t=8677&start=0

It's currently an imperfect solution because if CursorRuler was disabled before the wrapping attempt was made then it would be toggled on as the wrapping happens and therefore interfere with it before being toggled off again.

I may update cursor_ruler_toggle to accept an optional boolean that enforces the toggle state to get around this problematic case.

I will of course try to implement this theoretical solution in the next CursorRuler release !

icylace added a commit that referenced this issue Oct 12, 2013
===============================

- General code improvement.
- The CursorRuler settings are now accessible from the "Preferences" -> "Package Settings" menu.
- Fix for #2:  Custom user settings were not being picked up.
- Fix for #3:  Default line wrapping was behaving unexpectedly.  Created a new command called `CursorRuler: Wrap Lines` for doing line wrapping properly.
- Started using Package Control messages.
- Updated readme:  Made more use of GitHub Flavored Markdown.
- Updated readme:  Noted that one of the minor bugs is ST2-only.
@icylace
Copy link
Owner

icylace commented Oct 12, 2013

I just made a new release which implements a slightly refined version of the workaround I offered. Hopefully it works for you !

@icylace icylace closed this as completed Oct 12, 2013
@icylace
Copy link
Owner

icylace commented Oct 12, 2013

Also, note that the "Wrap Paragraph at Ruler" menu item still uses the normal wrapping command. It seems that there isn't a way to override ST's default menu items.

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

2 participants