]> gitweb.factorcode.org Git - factor.git/commitdiff
documents: simplify to use ``string-lines``.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 Feb 2017 19:11:42 +0000 (11:11 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 Feb 2017 19:11:42 +0000 (11:11 -0800)
basis/documents/documents.factor

index edab127f5ecd8b1d1ee18fef0dcaf4169dc555ad..b12e93f2519e2a52f563807cd5e7e057d59b1fec 100644 (file)
@@ -110,25 +110,6 @@ CONSTANT: doc-start { 0 0 }
 : with-undo ( ..a document quot: ( ..a document -- ..b ) -- ..b )
     [ t >>inside-undo? ] dip keep f >>inside-undo? drop ; inline
 
-! XXX: This is the old string-lines behavior, it would be nice
-! if we could update documents to work with the new string-lines
-! behavior.
-: split-lines ( str -- seq )
-    dup [ "\r\n" member? ] any? [
-        "\n" split
-        [
-            but-last-slice [
-                "\r" ?tail drop "\r" split
-            ] map! drop
-        ] [
-            [ length 1 - ] keep [ "\r" split ] change-nth
-        ]
-        [ concat ]
-        tri
-    ] [
-        1array
-    ] if ;
-
 PRIVATE>
 
 :: doc-range ( from to document -- string )
@@ -143,7 +124,9 @@ PRIVATE>
 
 :: set-doc-range ( string from to document -- )
     from to = string empty? and [
-        string split-lines :> new-lines
+        string string-lines
+        string ?last [ "\r\n" member? ] [ t ] if*
+        [ "" suffix ] when :> new-lines
         new-lines from text+loc :> new-to
         from to document doc-range :> old-string
         old-string string from to new-to <edit> document add-undo