Home Download Buy Blog Forum Support

[FIXED] Wrap paragraph at XX characters, too greedy

[FIXED] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Tue Aug 30, 2011 3:07 pm


*** Please see my 11/13 post for a fix to this issue ***


When wrapping a paragraph of text to xx characters, it appears that the command is a bit too greedy and ends up wrapping all surrounding content until it hits a newline either above or below the selection.

Code: Select all
<html>
<head>
  <title>Wrapping Bug</title>
</head>
<body>
  <p class="does_not_wrap_properly">
    Select lines 7-10, Edit -> Wrap paragraph at 120 chars. All of the indenting for
    surrounding content changes. Lorem ipsum dolor sit amet, consectetur
    adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
    aliqua.
  </p>
  <p class="wraps_properly">

    Select lines 14-17, Edit -> Wrap at paragraph 120 chars. This time with the newline
    before and after the paragraph, it indents properly and does not change
    surrounding content. Lorem ipsum dolor sit amet, consectetur adipisicing
    elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  </p>
</body>
</html>


Here are my user preferences:
Code: Select all
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"ensure_newline_at_eof_on_save": true
}


Is there a file that contains this command or macro that I can override until a bug fix is in, or is it implemented in compiled code?
Last edited by GMFlash on Sun Nov 13, 2011 7:36 am, edited 2 times in total.
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm

Re: [Build 2112 BUG] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Sat Sep 03, 2011 10:03 pm

This bug also appears in build 2112. Changed build from 2109 -> 2112 in title.
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm

Re: [Build 2112 BUG] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Wed Sep 07, 2011 2:59 am

This bug also appears in build 2113. Changed build from 2112 -> 2113 in title.
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm

Re: [Build 2113 BUG] Wrap paragraph at XX characters, too greedy

Postby jps on Wed Sep 07, 2011 3:52 am

This is working as designed: paragraphs are defined to text bounded by blank lines.

Wrap paragraph is implemented via a plugin, in Default/paragraph.py
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: [Build 2113 BUG] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Wed Sep 07, 2011 4:07 pm

I understand your point about paragraphs, however, it is different than expected behavior and real-world usage:

TextMate.png
TextMate.png (113.53 KiB) Viewed 1200 times

vs

Sublime Text 2.png
Sublime Text 2.png (107.77 KiB) Viewed 1201 times

All editors I've used wrap any text that is highlighted to the current level of indentation, regardless of leading and trailing blank lines. When writing HTML, it is not a common practice to put a blank line before and after the content between <p> tags. The wrap feature in its current state unfortunately isn't very usable for the most common use cases.

Perhaps this can be changed to "Wrap text at XX characters" and apply only to the lines selected?
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm

Re: [Build 2113 BUG] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Mon Nov 07, 2011 4:14 pm

Is there a better way to report bugs/issues? It seems that topics posted to this forum slowly drift away and are forgotten. I still see the current behavior of this command as a bug because it is not usable in the most common scenarios. It should wrap all text in the selection, regardless of whether it is separated by whitespace or not. I like this editor and want to be your customer. Please correct this basic functionality and you'll sell another license.
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm

Re: [FIXED] Wrap paragraph at XX characters, too greedy

Postby GMFlash on Sun Nov 13, 2011 7:34 am

I went ahead and created a workaround for this issue. The "wrap paragraph" command now behaves exactly like TextMate.

Code: Select all
# Place this code in Packages/User/paragraph.py

class WrapLinesCommand(WrapLinesCommand):
    def run(self, edit, width=0):
        if width == 0 and self.view.settings().get("wrap_width"):
            try:
                width = int(self.view.settings().get("wrap_width"))
            except TypeError:
                pass

        if width == 0 and self.view.settings().get("rulers"):
            # try and guess the wrap width from the ruler, if any
            try:
                width = int(self.view.settings().get("rulers")[0])
            except ValueError:
                pass
            except TypeError:
                pass

        if width == 0:
            width = 78

        # Make sure tabs are handled as per the current buffer
        tab_width = 8
        if self.view.settings().get("tab_size"):
            try:
                tab_width = int(self.view.settings().get("tab_size"))
            except TypeError:
                pass

        if tab_width == 0:
            tab_width == 8

        for s in self.view.sel():
            wrapper = textwrap.TextWrapper()
            wrapper.expand_tabs = False
            wrapper.width = width
            prefix = self.extract_prefix(s)
            if prefix:
                wrapper.initial_indent = prefix
                wrapper.subsequent_indent = prefix
                wrapper.width -= self.width_in_spaces(prefix, tab_width)

            if wrapper.width < 0:
                continue

            txt = self.view.substr(s)
            last_char = u"\n" if txt[-1] == u"\n" else ""
            txt = re.sub('\s{2,}', ' ', txt.strip())
            if prefix:
                txt = txt.replace(prefix, u"")

            txt = string.expandtabs(txt, tab_width)

            txt = wrapper.fill(txt) + last_char
            self.view.replace(edit, s, txt)
GMFlash
 
Posts: 10
Joined: Tue Aug 30, 2011 2:55 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 22 guests