]> git.cworth.org Git - sup/commitdiff
"loose alignment" of the first open message when starting thread-view-mode
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 13 Jan 2008 07:04:19 +0000 (23:04 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 14 Jan 2008 00:16:43 +0000 (16:16 -0800)
Align the first open message of thread-view-mode heuristically. Try and
give some top and left context, but not so much that the message is
cropped.

lib/sup/modes/thread-index-mode.rb
lib/sup/modes/thread-view-mode.rb

index 89dfec95ae12d066d542238e4852f0367fd490a4..0d90be48f1ee9b4eae2a6cf8064a2cfed16a4cc8 100644 (file)
@@ -91,7 +91,7 @@ EOS
       mode = ThreadViewMode.new t, @hidden_labels, self
       BufferManager.spawn t.subj, mode
       BufferManager.draw_screen
-      mode.jump_to_first_open
+      mode.jump_to_first_open true
       BufferManager.draw_screen # lame TODO: make this unnecessary
       ## the first draw_screen is needed before topline and botline
       ## are set, and the second to show the cursor having moved
index bd5c568765879666b5e055c54777a3d3ffd1c037..a7fa964f3125deb3290fc3cf7c44b05231fc572f 100644 (file)
@@ -275,16 +275,16 @@ EOS
     end
   end
 
-  def jump_to_first_open
+  def jump_to_first_open loose_alignment=false
     m = @message_lines[0] or return
     if @layout[m].state != :closed
-      jump_to_message m
+      jump_to_message m, loose_alignment
     else
-      jump_to_next_open
+      jump_to_next_open loose_alignment
     end
   end
 
-  def jump_to_next_open
+  def jump_to_next_open loose_alignment=false
     return continue_search_in_buffer if in_search? # hack: allow 'n' to apply to both operations
     m = (curpos ... @message_lines.length).argfind { |i| @message_lines[i] }
     return unless m
@@ -292,7 +292,7 @@ EOS
       break if @layout[nextm].state != :closed
       m = nextm
     end
-    jump_to_message nextm if nextm
+    jump_to_message nextm, loose_alignment if nextm
   end
 
   def align_current_message
@@ -300,7 +300,7 @@ EOS
     jump_to_message m
   end
 
-  def jump_to_prev_open
+  def jump_to_prev_open loose_alignment=false
     m = (0 .. curpos).to_a.reverse.argfind { |i| @message_lines[i] } # bah, .to_a
     return unless m
     ## jump to the top of the current message if we're in the body;
@@ -312,22 +312,32 @@ EOS
         break if @layout[prevm].state != :closed
         m = prevm
       end
-      jump_to_message prevm if prevm
+      jump_to_message prevm, loose_alignment if prevm
     else
-      jump_to_message m
+      jump_to_message m, loose_alignment
     end
   end
 
-  def jump_to_message m
+  def jump_to_message m, loose_alignment=false
     l = @layout[m]
     left = l.depth * INDENT_SPACES
     right = left + l.width
 
     ## jump to the top line
-    jump_to_line l.top
+    if loose_alignment
+      jump_to_line [l.top - 3, 0].max # give 3 lines of top context
+    else
+      jump_to_line l.top
+    end
 
     ## jump to the left column
-    jump_to_col left
+    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
 
     ## either way, move the cursor to the first line
     set_cursor_pos l.top