You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2018/01/18 19:12:43 UTC

[whimsy] branch master updated: if selection is present, reflow only selected area

This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 4322580  if selection is present, reflow only selected area
4322580 is described below

commit 432258061682323d3982fef12a7ddf43c29b8a02
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Thu Jan 18 14:12:23 2018 -0500

    if selection is present, reflow only selected area
---
 www/board/agenda/views/buttons/post.js.rb | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/www/board/agenda/views/buttons/post.js.rb b/www/board/agenda/views/buttons/post.js.rb
index 8f313de..a842414 100644
--- a/www/board/agenda/views/buttons/post.js.rb
+++ b/www/board/agenda/views/buttons/post.js.rb
@@ -187,6 +187,16 @@ class Post < Vue
   # perform a reflow of report text
   def reflow()
     report = @report
+    textarea = document.getElementById('post-report-text')
+    indent = start = finish = 0
+
+    # extract selection (if any)
+    if textarea.selectionEnd > textarea.selectionStart
+      start = textarea.selectionStart
+      start -= 1  while start > 0 and report[start-1] != "\n"
+      finish = textarea.selectionEnd
+      finish += 1 while report[finish] != '\n' and finish < report.length-1
+    end
 
     # remove indentation
     unless report =~ /^\S/
@@ -196,11 +206,20 @@ class Post < Vue
         indents.push result[1].length
       end
       unless indents.empty?
-        report.gsub!(RegExp.new('^' + ' ' * Math.min(*indents), 'gm'), '')
+        indent = Math.min(*indents)
+        report.gsub!(RegExp.new('^' + ' ' * indent, 'gm'), '')
       end
     end
 
-    @report = Flow.text(report, @indent)
+    # reflow selection or entire report
+    if finish > start
+      report = Flow.text(report[start..finish], @indent+indent)
+      report.gsub(/^/, ' ' * indent) if indent > 0
+      @report = @report[0...start] + report + @report[finish+1..-1]
+    else
+      @report = Flow.text(report, @indent)
+    end
+
     self.change_message()
   end
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].