git.fiddlerwoaroof.com
Browse code

refactor: move editable-string

Edward authored on 25/02/2021 11:23:31
Showing 1 changed files
... ...
@@ -11,8 +11,17 @@
11 11
 (defgeneric edit (base operation))
12 12
 (defgeneric apply-edits (base operations))
13 13
 
14
+(fw.lu:defclass+ editable-string ()
15
+  ((%string :initarg :string :accessor string-to-edit)
16
+   (%transform :accessor transform :initform 'identity)))
14 17
 
15 18
 
19
+(defmethod apply-edits ((base string) (operations sequence))
20
+  (string-to-edit
21
+   (reduce 'edit
22
+           (sort operations '< :key 'epoch)
23
+           :initial-value (editable-string base))))
24
+
16 25
 (fw.lu:defclass+ insert (op)
17 26
   ((%point :initarg :point :accessor point)
18 27
    (%value :initarg :value :reader value)))
... ...
@@ -26,17 +35,6 @@
26 35
       (if (< new-point point)
27 36
           new-point
28 37
           (+ new-point insert-length)))))
29
-
30
-(fw.lu:defclass+ editable-string ()
31
-  ((%string :initarg :string :accessor string-to-edit)
32
-   (%transform :accessor transform :initform 'identity)))
33
-
34
-(defmethod apply-edits ((base string) (operations sequence))
35
-  (string-to-edit
36
-   (reduce 'edit
37
-           operations
38
-           :initial-value (editable-string base))))
39
-
40 38
 (defun do-insert (base new point)
41 39
   (let ((begin (subseq base 0 point))
42 40
         (end (subseq base point)))