Indentation isn't preserved in comments

Bug #76604 reported by Gustavo Niemeyer
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Triaged
Medium
Unassigned

Bug Description

When a patch excerpt is pasted in a comment, the indentation of lines starting with +- is lost.

E.g:

def my_func():
    print "This"
    print "is"
    print "right"

 def my_func():
     print "This"
- print "is"
+ print "broken"

Tags: lp-bugs ui
Changed in malone:
status: Unconfirmed → Confirmed
Revision history for this message
Matthew Paul Thomas (mpt) wrote :

This is by design. We retain leading spaces by converting them to HTML non-breaking spaces. But if we did that for *all* spaces in descriptions and comments, that would make pages scroll horizontally in mobile browsers and other narrow windows, making Launchpad less usable overall.

Perhaps we need to switch back to showing bug descriptions and comments in a proportional font, like Trac does, to make it clearer that patches etc should be attached instead of being typed as comments.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

We include diff excerpts in comments, while discussing a change being proposed. It doesn't
make sense to attach that kind of comment. Making it clear that Launchpad doesn't support
pre-formatted text in comments is making it clear that it lacks a feature pretty much every
other issue tracker in the market offers.

I could argue that preserving spaces is even more important than mobile browsers, since it's a
more common usability problem to the market Launchpad is targeting, but we don't have to
discuss this. I'm sure there are ways to prevent the usability bug described above without
sacrificing the other kind of usability you're after.

A few suggestions:

1. Convert any sequence of spaces where n > 1 to   and on n == 1, preserve it as
a normal space, thus introducing a breaking point. The principle here is: why would someone
enter more than one space in sequence in a text area if it wasn't supposed to be preserved?

2. Introduce breakable spaces between unbreakable spaces.

Check http://labix.org/tmp/break-me.html for an example.

Revision history for this message
Matthew Paul Thomas (mpt) wrote :

Ah, excellent idea! We could convert consecutive spaces into strings of alternating breaking and unbreaking spaces.

Changed in malone:
importance: Undecided → Medium
Revision history for this message
Anders Kaseorg (andersk) wrote :

Instead of alternating, I would suggest converting consecutive spaces to all   except the last one:
  word_____word -> word    _word
(so that the browser never wraps before a   leading to misalignment).

Or, you could forget &nbsp; entirely and just use <p style="white-space: pre-wrap" /> or <pre style="white-space: pre-wrap" /> to solve the horizontal scrolling problem:
  <http://www.w3.org/TR/CSS21/text.html#white-space-prop>
  <http://labnol.blogspot.com/2006/10/html-css-trick-for-displaying-code.html>

Revision history for this message
Karl Fogel (kfogel) wrote :

Just a note that this bit me in a non-patch situation, see

   https://bugs.edge.launchpad.net/launchpad/+bug/317136/comments/2

and the comments following it. (That comment would not have been appropriate as an attachment, IMHO.)

I tend to agree with Gustavo that supporting formatted text is important. I've seen lots of comments in bug trackers where people essentially do ASCII art to illustrate something. Maybe in an ideal world we'd get away from ASCII art, but... it's the standard right now :-).

Revision history for this message
Anders Kaseorg (andersk) wrote :

Not even all leading whitespace is preserved. Leading tabs are converted into leading spaces:

        This line starts with eight spaces.
 This line starts with a tab.

summary: - Indentation isn't preserved for patches
+ Indentation isn't preserved in comments
Revision history for this message
Martin Pool (mbp) wrote :

fwiw merge proposals do get this right (example https://code.edge.launchpad.net/~mbp/bzr/progress-output/+merge/14944).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.