lib/sup/modes/thread-view-mode.rb in sup-0.4 vs lib/sup/modes/thread-view-mode.rb in sup-0.5

- old
+ new

@@ -47,24 +47,32 @@ k.add :compose, "Compose message to person", 'm' k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "(" k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")" k.add :pipe_message, "Pipe message or attachment to a shell command", '|' - k.add_multi "(A)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk| + k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk| kk.add :archive_and_kill, "Archive this thread and kill buffer", 'a' kk.add :delete_and_kill, "Delete this thread and kill buffer", 'd' kk.add :spam_and_kill, "Mark this thread as spam and kill buffer", 's' kk.add :unread_and_kill, "Mark this thread as unread and kill buffer", 'N' end - k.add_multi "(A)rchive/(d)elete/mark as (s)pam/mark as u(N)read/do (n)othing:", ',' do |kk| + k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read/do (n)othing:", ',' do |kk| kk.add :archive_and_next, "Archive this thread, kill buffer, and view next", 'a' kk.add :delete_and_next, "Delete this thread, kill buffer, and view next", 'd' kk.add :spam_and_next, "Mark this thread as spam, kill buffer, and view next", 's' kk.add :unread_and_next, "Mark this thread as unread, kill buffer, and view next", 'N' kk.add :do_nothing_and_next, "Kill buffer, and view next", 'n' end + + k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read/do (n)othing:", ']' do |kk| + kk.add :archive_and_prev, "Archive this thread, kill buffer, and view previous", 'a' + kk.add :delete_and_prev, "Delete this thread, kill buffer, and view previous", 'd' + kk.add :spam_and_prev, "Mark this thread as spam, kill buffer, and view previous", 's' + kk.add :unread_and_prev, "Mark this thread as unread, kill buffer, and view previous", 'N' + kk.add :do_nothing_and_prev, "Kill buffer, and view previous", 'n' + end end ## there are a couple important instance variables we hold to format ## the thread and to provide line-based functionality. @layout is a ## map from Messages to MessageLayouts, and @chunk_layout from @@ -316,31 +324,34 @@ else jump_to_message m, loose_alignment 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 right = left + l.width ## 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 end def expand_all_messages @@ -378,10 +389,16 @@ def spam_and_next; spam_and_then :next end def delete_and_next; delete_and_then :next end def unread_and_next; unread_and_then :next end def do_nothing_and_next; do_nothing_and_then :next end + def archive_and_prev; archive_and_then :prev end + def spam_and_prev; spam_and_then :prev end + def delete_and_prev; delete_and_then :prev end + def unread_and_prev; unread_and_then :prev end + def do_nothing_and_prev; do_nothing_and_then :prev end + def archive_and_then op dispatch op do @thread.remove_label :inbox UpdateManager.relay self, :archived, @thread.first end @@ -414,18 +431,21 @@ def dispatch op return if @dying @dying = true + l = lambda do + yield if block_given? + BufferManager.kill_buffer_safely buffer + end + case op when :next - @index_mode.launch_next_thread_after(@thread) do - @thread.save Index if block_given? && yield - BufferManager.kill_buffer_safely buffer - end + @index_mode.launch_next_thread_after @thread, &l + when :prev + @index_mode.launch_prev_thread_before @thread, &l when :kill - @thread.save Index if yield - BufferManager.kill_buffer_safely buffer + l.call else raise ArgumentError, "unknown thread dispatch operation #{op.inspect}" end end private :dispatch