           old-lines (:lines old-model)
           caretpos (evovle-caret-pos component prevcaretpos old-caret-line-pos old-caret-line old-selection-mark old-text old-lines supplied-text)
           text (evolve-text component prevcaretpos caretpos old-selection-mark old-text supplied-text)
-          lines (let [raw-lines (clojure.string/split-lines text)]
-                  (if (.endsWith text "\n")
-                    (fgc/conjv raw-lines "")
-                    raw-lines))
+          lines (split-to-lines text)
           selection-mark (evovle-selection-mark component caretpos old-selection-mark)
           caret-coord (pos->coord component lines caretpos)
           selection-mark-coord (pos->coord component lines selection-mark)

              caret-x (get-caret-x (subs text old-first-visible-symbol) caret-pos)
              width (- (m/x (get-property component [:this] :clip-size)) (* 1 (get-hgap)) (awt/px))]
          (if (> caret-x width)
            (let [ diff (- caret-x width)]
              (+
                old-first-visible-symbol
                (loop [ i 1]
                  (if (>= (awt/strw (subs text old-first-visible-symbol (+ old-first-visible-symbol i))) diff)
                    i
                    (recur
                      (inc i))))))
            old-first-visible-symbol))))
    0))

;; TODO avoid duplication with skin
(defn- text-str-h [] (* (flatgui.awt/strh) 2.5))

(fg/defevolverfn auto-scroll-evolver :viewport-matrix
  (let [text-field-id (first (first (:children component)))

            [flatgui.widgets.component]
            [flatgui.widgets.scrollpanel]
            [flatgui.inputchannels.keyboard :as keyboard]
            [flatgui.inputchannels.mouse :as mouse]
            [flatgui.inputchannels.clipboard :as clipboard]
            [flatgui.inputchannels.awtbase :as inputbase]
            [flatgui.util.matrix :as m]
