Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests on update-node-content generic-function. #2

Merged
merged 40 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5e1aa12
More tests on update-node-content generic-function.
svetlyak40wt Mar 13, 2022
b3f7139
Removed duplicate test.
svetlyak40wt Mar 13, 2022
7849c2e
Covered all existing cases for update-node-content.
svetlyak40wt Mar 13, 2022
895c40f
Added code to edit code blocks.
svetlyak40wt Mar 13, 2022
c568938
Moved key processing code into a data-structure like a keymap.
svetlyak40wt Mar 19, 2022
2165f79
Fixed calling prevent default on keydown.
svetlyak40wt Mar 19, 2022
e306a98
Fixed uri copying on saving document version.
svetlyak40wt Mar 19, 2022
97685f2
Fixed find-next-paragraph function.
svetlyak40wt Mar 19, 2022
1af4ae4
Now keymap entries have names.
svetlyak40wt Mar 19, 2022
d8c29ed
Skipping images when searching for the current node.
svetlyak40wt Mar 19, 2022
6895cdf
Fixed strange newlines sent by a browser.
svetlyak40wt Mar 19, 2022
aacbf9b
Fixed adding new list items on Option-Enter.
svetlyak40wt Mar 19, 2022
34c446b
Most log entries are now logged as DEBUG.
svetlyak40wt Mar 20, 2022
fc078e7
MVP of alternative keymap for code blocks.
svetlyak40wt Mar 20, 2022
6f75159
Fixed code block editing. Now Enter adds a new line inside code block.
svetlyak40wt Mar 20, 2022
9727f3e
Enter adds a new line instead of going to the next paragraph.
svetlyak40wt Mar 25, 2022
431d60d
Added code block deletion.
svetlyak40wt Mar 25, 2022
955751c
Almost working moving of the cursor inside the code block.
svetlyak40wt Mar 26, 2022
4f86045
Fixed moving from one code-block's line to another.
svetlyak40wt Mar 26, 2022
0640166
Pasting to code block keeps new lines as is.
svetlyak40wt Mar 26, 2022
7cf49f9
Show active code-block.
svetlyak40wt Mar 26, 2022
7a94dee
Removed attempt to fix code-block Enter problem on the frontend side.
svetlyak40wt Mar 27, 2022
61c1c41
Added support for Option+Enter in code blocks.
svetlyak40wt Mar 27, 2022
6438d6d
Added a function to squash code-block's content.
svetlyak40wt Mar 27, 2022
d623417
Corrected behaviour when editing a paragraph containing an image.
svetlyak40wt Apr 2, 2022
ef7693d
Fixed entering hanging spaces after an image.
svetlyak40wt Apr 3, 2022
e35459a
Fixed image deletion.
svetlyak40wt Apr 3, 2022
92fa468
Fixed paragraph splitting and joining for case when there is an image…
svetlyak40wt Apr 3, 2022
ddfef79
Added a hack to calculate new caret position after the image was inse…
svetlyak40wt Apr 3, 2022
a9904af
Fixed new paragraph creation and cursor position after inserting mark…
svetlyak40wt Apr 4, 2022
4441d1d
Refactoring to make image insertion work. But still incomplete.
svetlyak40wt Apr 9, 2022
427bc11
Almost worked attempt to make typed document pieces work.
svetlyak40wt Apr 18, 2022
21a81dd
Working explicit markup nodes prototype.
svetlyak40wt Apr 19, 2022
2f652f9
Fixed image deletion for some cases.
svetlyak40wt Apr 21, 2022
3182e99
Working drag&drop image uploading.
svetlyak40wt May 3, 2022
964a598
Fixed deletion of the image filling the whole paragraph.
svetlyak40wt May 3, 2022
e49f94d
Fixed test of node split.
svetlyak40wt May 4, 2022
2362d8d
Fixed some corner cases around spliting paragraphs with images.
svetlyak40wt May 4, 2022
1ef61db
Now you can drag&drop images only into paragraphs.
svetlyak40wt May 8, 2022
63a7efc
Fixed missing markup in "new" documents.
svetlyak40wt May 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion reblocks-text-editor-tests.asd
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(defsystem "reblocks-text-editor-tests"
:class :package-inferred-system
:pathname "t"
:depends-on ("reblocks-text-editor-tests/document/ops")
:depends-on ("reblocks-text-editor-tests/document/ops"
"reblocks-text-editor-tests/utils/text"
"reblocks-text-editor-tests/typed-pieces/scribdown")
:perform (test-op (o c)
(unless (symbol-call :rove '#:run c)
(error "Tests failed"))))
41 changes: 41 additions & 0 deletions src/blocks/code.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(uiop:define-package #:reblocks-text-editor/blocks/code
(:use #:cl)
(:import-from #:reblocks-text-editor/document/ops
#:map-document))
(in-package #:reblocks-text-editor/blocks/code)


(defun code (node)
(check-type node common-doc:code-block)
(let ((children (common-doc:children node)))
(if children
(common-doc:text (first children))
"")))


(defun normalize (root-node)
"Normalizes code-block nodes by joining it's children into a single text-node.

This helper is required until this issue will be resolved:

https://github.com/CommonDoc/scriba/issues/15"
(labels ((normalize-code-blocks (current-node depth)
(declare (ignore depth))
(when (typep current-node 'common-doc:code-block)
(let ((children (common-doc:children current-node)))
(when (not (and (= (length children) 1)
(typep (first children)
'common-doc:text-node)))
(setf (common-doc:children current-node)
(list (squash current-node))))))
current-node)
(squash (code-block)
(common-doc:make-text
(with-output-to-string (s)
(common-doc.ops:with-document-traversal (code-block node)
(etypecase node
(common-doc:text-node
(write-string (common-doc:text node) s))
(common-doc:content-node
nil)))))))
(map-document root-node #'normalize-code-blocks)))
12 changes: 12 additions & 0 deletions src/blocks/placeholder.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(uiop:define-package #:reblocks-text-editor/blocks/placeholder
(:use #:cl)
(:import-from #:common-doc
#:define-node))
(in-package #:reblocks-text-editor/blocks/placeholder)


(define-node placeholder (common-doc:document-node)
()
(:tag-name "placeholder")
(:documentation "This node will be replaced by a real one with the same reference."))

27 changes: 27 additions & 0 deletions src/blocks/progress.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(uiop:define-package #:reblocks-text-editor/blocks/progress
(:use #:cl)
(:import-from #:common-doc
#:define-node))
(in-package #:reblocks-text-editor/blocks/progress)


(define-node progress (common-doc:document-node)
((percent :initform 0
:accessor percent))
(:tag-name "progress")
(:documentation "This node will be replaced by a real one with the same reference."))


(defmethod reblocks-text-editor/html::to-html ((node progress))
(let ((percent (ceiling (percent node))))
(let ((reblocks/html:*pretty-html* nil))
(reblocks/html:with-html
(:span :id (common-doc:reference node)
:class "noneditable progress"
:style "display:inline-block; background-color: #83c6ff; width: 100px; height: 0.8em; line-height: 0.8em"
(:span :style (format nil
"display: inline-block; background-color: #2dd12d; width: ~A%; height: 100%"
percent)))))))


(defmethod scriba.emitter:emit ((node progress) stream))
12 changes: 12 additions & 0 deletions src/document/copying.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
(metacopy:defcopy-methods commondoc-markdown:markdown-link
:copy-all t)

(metacopy:defcopy-methods common-doc:image
:copy-all t)

(metacopy:defcopy-methods common-doc:text-node
:copy-all t)

Expand All @@ -55,4 +58,13 @@
(defmethod metacopy:copy-one ((obj quri.uri.http:uri-http) copy-hash)
(quri:copy-uri obj))

(defmethod metacopy:copy-one ((obj quri.uri:uri) copy-hash)
(quri:copy-uri obj))

(defmethod metacopy:copy-one ((obj quri.uri:urn) copy-hash)
(quri:copy-uri obj))

(defmethod metacopy:copy-one ((obj quri.uri.file:uri-file) copy-hash)
(quri:copy-uri obj))


69 changes: 67 additions & 2 deletions src/document/editable.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
(:import-from #:bordeaux-threads
#:make-lock)
(:import-from #:metacopy
#:copy-thing))
#:copy-thing)
(:import-from #:reblocks-text-editor/utils/markdown
#:to-markdown)
;; (:import-from #:reblocks-text-editor/document/ops
;; #:select-outer-block
;; #:split-nodes)
(:import-from #:reblocks-text-editor/utils/scribdown
#:to-scribdown)
(:import-from #:reblocks-text-editor/utils/text
#:collect-all-text))
(in-package #:reblocks-text-editor/document/editable)


Expand All @@ -25,7 +34,63 @@
:documentation "Stores a tuple of two elements.
The first is a node where caret is located and
the second is a number of the caret offset."
:accessor caret-position)))
:accessor caret-position)
(text-before-caret :initform ""
:type string
:documentation "Stores current paragraph's text before the caret."
:accessor text-before-caret)
(text-after-caret :initform ""
:type string
:documentation "Stores current paragraph's text after the caret."
:accessor text-after-caret)))


(defmethod (setf caret-position) :after ((value t) (document editable-document))
(destructuring-bind (node position)
value
(let ((nodes (if (slot-exists-p node 'common-doc:children)
(common-doc:children node)
(list node))))
(destructuring-bind (left right)
(uiop:symbol-call :reblocks-text-editor/document/ops
:split-nodes
nodes
position)
;; TODO: надо придумать что-то с тем, что в разорванной посередине markup
;; конструкции каждая часть обрамляется в markup.
;; возможно тут to-scribdown не лучший вариант и надо просто делать to-text
(let ((text-before
(collect-all-text (common-doc:make-content left))
;; (to-scribdown (common-doc:make-content left)
;; ;; It is important to not trim a space,
;; ;; otherwise a space before the cursor will be lost:
;; :trim-spaces nil)
)
(text-after
(collect-all-text (common-doc:make-content right))
;; (to-scribdown (common-doc:make-content right)
;; ;; It is important to not trim a space,
;; ;; otherwise a space before the cursor will be lost:
;; :trim-spaces nil)
))
(setf (text-before-caret document)
text-before)
(setf (text-after-caret document)
text-after))))
;; (let ((block-node (select-outer-block document node)))
;; (destructuring-bind (left right)
;; (split-nodes (list block-node) position)
;; (setf (text-before-caret document)
;; (to-scribdown (common-doc:make-content left)
;; ;; It is important to not trim a space,
;; ;; otherwise a space before the cursor will be lost:
;; :trim-spaces nil))
;; (setf (text-after-caret document)
;; (to-scribdown (common-doc:make-content right)
;; ;; It is important to not trim a space,
;; ;; otherwise a space before the cursor will be lost:
;; :trim-spaces nil))))
))


(defun get-next-reference-id (document)
Expand Down
Loading