|
@@ -11,15 +11,13 @@ a new list item when user presses `Enter` key.
|
11
|
11
|
In Notus (document model used by Zefyr editor), such rules are called
|
12
|
12
|
*heuristic rules*. There are two main purposes for heuristic rules:
|
13
|
13
|
|
14
|
|
-1. User experience: rules like above-mentioned autoformatting of links
|
15
|
|
- are here to make editing a user friendly process.
|
16
|
|
-2. Semantics preservation: this is mostly invisible for the user but
|
17
|
|
- is very important nevertheless. There is a set of rules to make sure
|
18
|
|
- that a document change conforms to the data format and model
|
19
|
|
- semantics.
|
|
14
|
+1. User experience: rules like above-mentioned autoformatting of links are here to make editing a user friendly process.
|
|
15
|
+2. Semantics preservation: this is mostly invisible for the user but is very important nevertheless. There is a set of rules to make sure that a document change conforms to the data format and model semantics.
|
20
|
16
|
|
21
|
17
|
Let's cover the second item in more detail.
|
22
|
18
|
|
|
19
|
+### Example heuristic rule
|
|
20
|
+
|
23
|
21
|
Say, a user is editing following document (cursor position is indicated
|
24
|
22
|
by pipe `|` character):
|
25
|
23
|
|
|
@@ -39,7 +37,8 @@ var change = doc.format(
|
39
|
37
|
```
|
40
|
38
|
|
41
|
39
|
If we try to apply this change as-is it would have no effect or, more
|
42
|
|
-likely, result in an `AssertionError`. This is why all methods in
|
|
40
|
+likely, result in an `AssertionError` because we are trying to apply line style
|
|
41
|
+to a character in the middle of a line. This is why all methods in
|
43
|
42
|
`NotusDocument` have an extra step which applies heuristic rules to
|
44
|
43
|
the change (there is one method which skips this step, `compose`,
|
45
|
44
|
read more on it later) before actually composing it.
|
|
@@ -62,13 +61,13 @@ what user intended to do.
|
62
|
61
|
There are more similar scenarios which are covered by heuristic rules
|
63
|
62
|
to ensure consistency with the document model and provide better UX.
|
64
|
63
|
|
65
|
|
-### `NotusDocument.compose()` and skipping heuristic rules.
|
|
64
|
+### `NotusDocument.compose()` and skipping heuristic rules
|
66
|
65
|
|
67
|
66
|
The `compose()` method is the only method which skips the step of
|
68
|
67
|
applying heuristic rules and therefore **should be used with great
|
69
|
68
|
care** as it can result in corrupted document state.
|
70
|
69
|
|
71
|
|
-Use this method when you sure that the change you are about to compose
|
|
70
|
+Use this method when you are sure that the change you are about to compose
|
72
|
71
|
conforms to the document model and data format semantics.
|
73
|
72
|
|
74
|
73
|
This method exists mostly to enable following use cases:
|