icylace / CursorRuler

Marks the current cursor position(s) using dynamic rulers. For Sublime Text 2 and 3.
62 stars 5 forks source link

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

Closed toddmazierski closed 10 years ago

toddmazierski commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

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 commented 10 years ago

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 commented 10 years ago

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

icylace commented 10 years ago

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.