sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 5aa2ed26cc6379a08ecc3b6ea642b8890e5e67d6
parent 8672ad32e972b0c80b5d36fc72f48a16ddff98bd
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sat,  2 Feb 2008 16:42:48 -0800

Merge branch 'initial-view-fix' into next

Diffstat:
M lib/sup/modes/scroll-mode.rb | 2 +-
M lib/sup/modes/thread-view-mode.rb | 19 +++++++++++--------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/lib/sup/modes/scroll-mode.rb b/lib/sup/modes/scroll-mode.rb
@@ -12,7 +12,7 @@ class ScrollMode < Mode
 
   attr_reader :status, :topline, :botline, :leftcol
 
-  COL_JUMP = 4
+  COL_JUMP = 2
 
   register_keymap do |k|
     k.add :line_down, "Down one line", :down, 'j', 'J'
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -318,6 +318,8 @@ 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
     l = @layout[m]
     left = l.depth * INDENT_SPACES
@@ -325,19 +327,20 @@ EOS
 
     ## jump to the top line
     if loose_alignment
-      jump_to_line [l.top - 3, 0].max # give 3 lines of top context
+      jump_to_line [l.top - IDEAL_TOP_CONTEXT, 0].max # give 3 lines of top context
     else
       jump_to_line l.top
     end
 
     ## jump to the left column
-    if loose_alignment
-      ## try and give 4 columns of left context, but not if it means that
-      ## the right of the message is truncated.
-      jump_to_col [[left - 4, rightcol - l.width - 1].min, 0].max
-    else
-      jump_to_col left
-    end
+    ideal_left = left +
+      if loose_alignment
+        -IDEAL_LEFT_CONTEXT + (l.width - buffer.content_width + IDEAL_LEFT_CONTEXT + 1).clamp(0, IDEAL_LEFT_CONTEXT)
+      else
+        0
+      end
+
+    jump_to_col [ideal_left, 0].max
 
     ## either way, move the cursor to the first line
     set_cursor_pos l.top