Subject: [sup-talk] [PATCH] Be less overzealous in moving text to the left column

From: [email-masked] (Carl Worth)
Date: Wed, 19 Aug 2009 23:31:25 -0700

Specifically, scroll as little as possible to get the current message
to just fit on the right side.
---

This seems to work quite nicely and I think is ready to be comitted as
is. It's still not perfect in a few ways though, which I think we can
leave for subsequent commits:

1. I *think* that with this change the loose_alignment mode is
   unnecessary. But I confess that I didn't totally understand the
   calculation it is making, so I tried to just preserve its behavior
   rather than ripping it out.

2. In deep threads of short messages, (so that lots of nesting is
   visible in one screenful), it's easier than it was before for
   messages other than the current message to be scrolled off to the
   right, (though the current message is always made to fit if
   possible). I can imagine someone finding the current patch
   unacceptable based on this.

   The fix for this would be to consider the total width of all
   visible messages when making the calculation made here, rather than
   just the width of the current message. I'm not sure how readily
   available that number is.

3. It's still easy to get stuff scrolled off to the left, (which was a
   symptom of the original bug I'm trying to fix), when doing
   something like (E: Expand all messages). This command should
   recompute a left column, so perhaps we should abstract the
   left-column calculation out to some shared place.

Anyway, all feedback is quite welcome,

-Carl (happy to finally be running code from git and contributing patches)

 lib/sup/modes/thread-view-mode.rb |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index dfe30ff..678b841 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -423,6 +423,9 @@ EOS
         0
       end
 
+    ## scroll as little as possible to make the message fit
+    ideal_left = (-(buffer.content_width - l.width - left - 1)).clamp(0, ideal_left)
+
     jump_to_col [ideal_left, 0].max
 
     ## either way, move the cursor to the first line
-- 
1.6.3.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/16ea9c2d/attachment.bin>

---

From: [email-masked] (William Morgan)
Date: Sun, 23 Aug 2009 10:55:59 -0700

> to just fit on the right side.

Is this the same as setting loose_alignment to true, and the
IDEAL_*_CONTENTs to 0?
-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Carl Worth)
Date: Wed, 26 Aug 2009 14:53:32 -0700

> Is this the same as setting loose_alignment to true, and the

I don't think so.

Doing that, (at least as in the below patch, for example), always puts
the current message flush left. And that can result in later messages
in the threads, (not descendants of the current thread though), being
cut off on the left. (And all this with dozens of empty columns on the
right of my terminal.) That's precisely the behavior I was getting
before my patch and which I'm trying to change.

What I want instead is for the message to appear in its "natural"
position (according to the threading), unless that would cause the
message to be cut off on the right. In which case, we jump to the
minimum column such that:

	1. We don't cut any of the current message off on the left

	2. We display all of the message on the right, (if possible
	   without violating point 1).

I believe that what I've coded achieves that. The two open questions I
still have are:

	A. Is there some simpler way to achieve the result I want with
	   some of the existing code?

	B. If not, is some of the existing code rendered obsolete with
	   my code in place?

As for (B), for example, with my code in place I don't think there's
any need for a notion of "ideal context". The ideal context is the
natural position of the thread.

And I still haven't figured out what loose_alignment means and which
actions will cause loose vs. non-loose layout.

-Carl

diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index dfe30ff..b7bbc7c 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -401,9 +401,9 @@ EOS
     end
   end
 
-  IDEAL_TOP_CONTEXT = 3 # try and give 3 rows of top context
-  IDEAL_LEFT_CONTEXT = 4 # try and give 4 columns of left context
-  def jump_to_message m, loose_alignment=false
+  IDEAL_TOP_CONTEXT = 0 # don't bother trying to give any rows of top context
+  IDEAL_LEFT_CONTEXT = 0 # don't bother trying to give any columns of left context
+  def jump_to_message m, loose_alignment=true
     l = @layout[m]
     left = l.depth * INDENT_SPACES
     right = left + l.width
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090826/8c5c013c/attachment.bin>

---

From: [email-masked] (William Morgan)
Date: Thu, 03 Sep 2009 10:12:25 -0700

> actions will cause loose vs. non-loose layout.

Yeah, it's not really clear where I was going with that. The whole thing
was in need of some rethinking and additional comments. I've made a
branch 'alignment-tweaks', merged into next, which I think has the
behavior you were looking for: left-column movement is minimized when
using 'n' and 'p' to jump between messages. You can also use 'z' to
align the left column with the current message.

Check it out and let me know what you think. If this bugs people, also
let me know. :)
-- 
William <wmorgan-sup at masanjin.net>