commit e4d2c4ce8470cce3ef02cefabe7d46a4ba6bffeb
parent 25c43de7c92f50135bcc07c8e6104b444cae3193
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Sat, 19 Dec 2009 09:47:46 -0800
Merge branch 'toggle-line-wrap' into next
Diffstat:
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -41,8 +41,6 @@ end
module Redwood
module Chunk
- WRAP_LEN = 80 # wrap messages and text attachments at this width
-
class Attachment
HookManager.register "mime-decode", <<EOS
Decodes a MIME attachment into text form. The text will be displayed
@@ -110,7 +108,6 @@ EOS
@lines = nil
if text
@lines = text.gsub("\r\n", "\n").gsub(/\t/, " ").gsub(/\r/, "").split("\n")
- @lines = lines.map {|l| l.chomp.wrap WRAP_LEN}.flatten
@quotable = true
end
end
@@ -167,8 +164,7 @@ EOS
attr_reader :lines
def initialize lines
- @lines = lines.map { |l| l.chomp.wrap WRAP_LEN }.flatten # wrap
-
+ @lines = lines
## trim off all empty lines except one
@lines.pop while @lines.length > 1 && @lines[-1] =~ /^\s*$/ && @lines[-2] =~ /^\s*$/
end
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -67,6 +67,7 @@ EOS
k.add :archive_and_next, "Archive this thread, kill buffer, and view next", 'a'
k.add :delete_and_next, "Delete this thread, kill buffer, and view next", 'd'
+ k.add :toggle_wrap, "Toggle wrapping of text", 'w'
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'
@@ -128,6 +129,8 @@ EOS
end
end
+ @wrap = true
+
@layout[latest].state = :open if @layout[latest].state == :closed
@layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
@@ -135,6 +138,12 @@ EOS
regen_text
end
+ def toggle_wrap
+ @wrap = !@wrap
+ regen_text
+ buffer.mark_dirty if buffer
+ end
+
def draw_line ln, opts={}
if ln == curpos
super ln, :highlight => true
@@ -761,7 +770,9 @@ private
else
raise "Bad chunk: #{chunk.inspect}" unless chunk.respond_to?(:inlineable?) ## debugging
if chunk.inlineable?
- chunk.lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] }
+ lines = chunk.lines
+ lines = lines.map { |l| l.chomp.wrap buffer.content_width }.flatten if @wrap
+ lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] }
elsif chunk.expandable?
case state
when :closed