@adecore/editor-core 0.0.1 → 0.17.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +110 -0
- package/LICENSE.apache-2.0.txt +201 -0
- package/NOTICE +11 -0
- package/README.md +54 -0
- package/dist/block-folds.d.ts +3 -0
- package/dist/block-folds.js +112 -0
- package/dist/brackets.d.ts +5 -0
- package/dist/brackets.js +136 -0
- package/dist/closer-tracker.d.ts +9 -0
- package/dist/closer-tracker.js +46 -0
- package/dist/comments.d.ts +14 -0
- package/dist/comments.js +344 -0
- package/dist/document.d.ts +148 -0
- package/dist/document.js +1729 -0
- package/dist/edit-source.d.ts +19 -0
- package/dist/edit-source.js +1 -0
- package/dist/enter.d.ts +17 -0
- package/dist/enter.js +387 -0
- package/dist/fold-roles.d.ts +6 -0
- package/dist/fold-roles.js +142 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +7 -0
- package/dist/languages.d.ts +12 -0
- package/dist/languages.js +51 -0
- package/dist/lexical-folds.d.ts +10 -0
- package/dist/lexical-folds.js +116 -0
- package/dist/lexical.d.ts +16 -0
- package/dist/lexical.js +74 -0
- package/dist/line-commands.d.ts +9 -0
- package/dist/line-commands.js +306 -0
- package/dist/markup-regions.d.ts +8 -0
- package/dist/markup-regions.js +331 -0
- package/dist/offsets.d.ts +2 -0
- package/dist/offsets.js +14 -0
- package/dist/paste.d.ts +9 -0
- package/dist/paste.js +108 -0
- package/dist/preserve-case.d.ts +1 -0
- package/dist/preserve-case.js +61 -0
- package/dist/rope.d.ts +22 -0
- package/dist/rope.js +246 -0
- package/dist/search.d.ts +26 -0
- package/dist/search.js +85 -0
- package/dist/structure.d.ts +50 -0
- package/dist/structure.js +124 -0
- package/dist/text-span.d.ts +7 -0
- package/dist/text-span.js +211 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +1 -0
- package/dist/typing-context.d.ts +30 -0
- package/dist/typing-context.js +270 -0
- package/dist/typing-handlers.d.ts +15 -0
- package/dist/typing-handlers.js +125 -0
- package/dist/words.d.ts +7 -0
- package/dist/words.js +72 -0
- package/package.json +34 -3
- package/src/block-folds.ts +117 -0
- package/src/brackets.ts +159 -0
- package/src/closer-tracker.ts +60 -0
- package/src/comments.ts +411 -0
- package/src/document.ts +2021 -0
- package/src/edit-source.ts +25 -0
- package/src/enter.ts +452 -0
- package/src/fold-roles.ts +166 -0
- package/src/index.ts +22 -0
- package/src/languages.ts +77 -0
- package/src/lexical-folds.ts +138 -0
- package/src/lexical.ts +113 -0
- package/src/line-commands.ts +356 -0
- package/src/markup-regions.ts +333 -0
- package/src/offsets.ts +16 -0
- package/src/paste.ts +126 -0
- package/src/preserve-case.ts +62 -0
- package/src/rope.ts +278 -0
- package/src/search.ts +119 -0
- package/src/structure.ts +223 -0
- package/src/text-span.ts +230 -0
- package/src/types.ts +141 -0
- package/src/typing-context.ts +329 -0
- package/src/typing-handlers.ts +143 -0
- package/src/words.ts +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 Bas Milius
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
@adecore/editor-core
|
|
2
|
+
|
|
3
|
+
Original project sources remain under FSL-1.1-MIT (see LICENSE), except what is named below.
|
|
4
|
+
|
|
5
|
+
The word-boundary predicates in src/words.ts are adapted from the IntelliJ Platform, Copyright
|
|
6
|
+
2000-2023 JetBrains s.r.o. and contributors, under the Apache License, Version 2.0 (see
|
|
7
|
+
LICENSE.apache-2.0.txt). The TypeScript translation is a modified version. README.md names the
|
|
8
|
+
upstream file and revision.
|
|
9
|
+
|
|
10
|
+
This package is independent and is not affiliated with JetBrains or Microsoft. It does not bundle
|
|
11
|
+
Monaco, CodeMirror, or the IntelliJ Platform runtime.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @adecore/editor-core
|
|
2
|
+
|
|
3
|
+
Read the [editor-core handbook](https://adecore.dev/editor-core/handbook/) for the complete setup, concepts, host integration and testing guides.
|
|
4
|
+
|
|
5
|
+
The document model and editing logic of the smart editor, with no DOM and no dependencies. It runs in the browser, Bun and Node. The view that draws it and the language client that feeds it are separate packages (`@adecore/editor`, `@adecore/lsp`).
|
|
6
|
+
|
|
7
|
+
`DocumentModel` holds the text as a persistent rope, the selections, a bounded undo history and the editing commands. Offsets are UTF-16 code units, lines and columns zero-based. A batch of edits is simultaneous and in the coordinates of the text before it.
|
|
8
|
+
|
|
9
|
+
## API
|
|
10
|
+
|
|
11
|
+
Everything comes from the package root.
|
|
12
|
+
|
|
13
|
+
- `DocumentModel`: `getText`, `getLine`, `slice`, `getSelections`, `getPrimary`, `getSnapshot`, `subscribe`, `applyEdits`, `setText`, `undo`, `redo`, `positionAt`, `offsetAt`, `find`, `findNext`, `replace`, `replaceAll`, `getFoldingRanges`, `typeText`, `paste`, `execute`, and `wordSelectionAt`, `wordStartBefore` and `wordEndAfter` for the mouse.
|
|
14
|
+
- The selections are in the order they were added, and the last is the primary caret; a merge that takes it in keeps it last.
|
|
15
|
+
- `applyEdits` takes `expectedRevision` and refuses the batch if the text moved on. A revision only goes up.
|
|
16
|
+
- `typeText` is one keystroke on every caret. It pairs brackets and quotes (each with its own option, and not in plain text), pairs a bracket only when the text after it has no closer for it, pairs a quote only when no identifier character follows, types over a closer, wraps a selection in a bracket, `<` or quote and swaps the quotes of a string when one of them is selected, sends a closing bracket alone on its line back to the indentation of its opener, leaves a Python docstring opener at three quotes and moves a `;` to the end of a call. It reads the language id (`typescript`, `php`, `python`, and so on) to tell code from comments and strings.
|
|
17
|
+
- `paste` writes the document's own line breaks, takes one line for each caret when the counts match, puts text copied from a bare caret (`wholeLines`) above the line of each bare caret, and moves a pasted block to the indentation of the line it lands on, only when it lands in code and not in a string, a template literal, a comment or a heredoc.
|
|
18
|
+
- `execute` runs an `EditorCommand`: word and camel-hump movement, smart Home and End, backspace, Enter and its variants (start a line below or above, split a line), Tab, join lines, toggle case, auto-indent, line duplicate, delete and move, line and block comment toggles, indent, multiple carets (add above and below, which takes them back when pressed the other way, and one per selected line), selection expansion and the occurrence commands (next, unselect and all).
|
|
19
|
+
- A word move stops at the end of a word, then at the start of the next line, and on an empty line, going back at the start of a word and then the end of the line above; deleting by word stops at both edges of a word. Camel humps are off unless `camelCase` is true. Home and End take `visualLine`, so a wrapped row is an edge of its own, and Home inside the indentation goes to the start of the line.
|
|
20
|
+
- `lineSpan` in the command options names the lines that stand on one row of the screen, which a host with folds fills in: a collapsed fold is then one line to delete, duplicate, comment and move (it swaps with the whole row it passes, and `onLinesMoved` tells the host where each line went), one word stop that never lands inside it, and its lines are skipped by add caret above and below.
|
|
21
|
+
- Select next occurrence selects the word at the caret, then whole words with the same case; from a selection it finds the text inside other words too. The end of the text is said (`occurrencesExhausted`) and the press after it starts again.
|
|
22
|
+
- `getFoldingRanges` also reads, with a language, runs of import lines, runs of line comments and `region` markers (`lexicalFolds`), and the whole-line blocks of Markdown (front matter, code fences, tables, the section under a heading) and PHP (heredocs and nowdocs, `<?php ... ?>` blocks between markup) in `blockFolds`.
|
|
23
|
+
- A range may carry a `role`, which is what the settings fold by when a file opens: the file header, a documentation comment, imports, a region, an object or array literal in a script and a PHP attribute list are read off the text (`fold-roles.ts`). The body of a function, a method or a class, and the tag a server's range starts with, come from `hints` in the options, which a host fills from a language server's symbols and folding ranges as offsets. A symbol names the bracket pair that closes where it ends, or the indented block that does; a range the text has no fold for becomes a `server` fold, one per line it starts on.
|
|
24
|
+
- `replace` and `replaceAll` can give the replacement the case of the match (`preserveCase`).
|
|
25
|
+
- Enter works from the lexer's state at the caret. It continues a line comment when text follows the caret (with the marker the comment starts with, so a PHP `#` and a Python `##` go on as they are), closes and continues `/*` and `/**` comments with the stars lined up under the opener's first star (a `/** text */` that closes on its line gives the closer a line of its own), splits a string literal with the language's concatenation (not in the value of a JSX attribute or the path of an import, `require` or `export ... from`, where it breaks the line as it is), closes a brace nothing closes, indents after an opener, `def f():` (the code before a trailing comment decides, as if the comment were not there), a YAML `key:`, a `case` label, an open tag and a statement left unfinished, and replaces the whitespace after the caret by the indentation it computes.
|
|
26
|
+
- Comment toggles use a table of markers per language (`commentSyntax`), with the region of a Vue file picked by the caret's line. Line comments go in at the smallest indentation of the lines, and a lone caret moves down a line. A language with block comments only wraps each line.
|
|
27
|
+
- Backspace at the start of a line also takes the whitespace that trails the line above. Tab inserts up to the next tab stop, which for several carets on a line counts what the carets before it added, or steps over a closer the editor added.
|
|
28
|
+
- `scanBrackets` pairs brackets lexically, for code that does not parse yet.
|
|
29
|
+
- `changedSpan` is the one stretch that differs between two texts and `changedSpans` the stretches of a bounded line diff (Myers on interned lines, then trimmed to the characters), which `applyEdits` takes as one batch. A diff past 4 million steps of work, 1,000 edited lines or 16 MiB between the first and last change is the one span. On 100,000 lines (6 MB) with three changes it takes about 20 ms.
|
|
30
|
+
- `findMatches` and `replacementText` are the search the model uses.
|
|
31
|
+
- `isWordBoundary`, `isHumpBoundary` and `wordBoundary` are the word predicates and the navigation on top of them.
|
|
32
|
+
- Types for selections, edits, changes, snapshots, commands and options.
|
|
33
|
+
|
|
34
|
+
## Port scope and provenance
|
|
35
|
+
|
|
36
|
+
This package comes from a proof of concept editor that ports IntelliJ's editing behavior. Only one thing is ported code: the character-level word-boundary predicates in `src/words.ts` (`isWordBoundary`, `isHumpBound`, `isLowerCaseOrDigit` and `isPunctuation`). Their upstream is `platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java` in JetBrains/intellij-community at `7184b03af6c5370e79a01ded0df68cf56d7669da`, lines 934 through 982, under Apache 2.0. The file keeps the copyright header, and `NOTICE` and `LICENSE.apache-2.0.txt` come with the package.
|
|
37
|
+
|
|
38
|
+
The branch order, the start and end asymmetry, and the underscore, dollar and acronym rules are kept. Java's character tests are written as Unicode properties plus Java's whitespace and control ranges. Like the upstream char overloads, they look at UTF-16 code units, and a newer Unicode version in the runtime can classify a new character differently than Java does.
|
|
39
|
+
|
|
40
|
+
The rest is written here: the rope, transactions and history, the commands, search, folding and the lexical scanners. Bracket matching and delimiter typing were checked against IntelliJ's documented behavior and its `TypedParenImpl` and `TypedQuoteImpl` handlers, which depend on PSI and were not copied. Enter, comment toggling, join lines, paste and the handlers for typing over a selection follow the behavior of the same editor's handlers, with the lexer standing in for the syntax tree and no formatter; none of their code is used. Navigation avoids surrogate pairs and CRLF. IntelliJ's token filters, quoted-token policies and visual-line rules are not part of this.
|
|
41
|
+
|
|
42
|
+
## Known limits
|
|
43
|
+
|
|
44
|
+
- The scanners are lexical, not parsers. A `/` after an ambiguous construct can read as a regex or a division, and JSX text, Python triple quotes and HTML or XML tag pairs are not modeled. PHP is: the markup around its tags and heredoc and nowdoc bodies are lexer modes, so nothing in them pairs, indents or reads as code. `scanStructure`, behind folding and selection expansion, does not know regex literals or template interpolation.
|
|
45
|
+
- Language is a string id (the Shiki ones) with positive lists for the lexer: which languages have `//`, `#` (anywhere, or only at the start of a word in shell, YAML and Dockerfile), `--`, `/* */` and `<!-- -->` comments, which have braces, and a table of comment markers. An unknown id has no comments and no braces, so nothing in it reads as a comment. Indentation is worked out from brackets, keywords and the end of the previous line, not by a formatter, so Auto-indent Lines leaves languages without braces alone. It also leaves markup alone: only lines the lexer calls code are re-indented, never the lines of JSX elements (a scanner finds them, `markup-regions.ts`), a Vue template or anything outside its script and style blocks, the markup and heredocs of a PHP file, and the bodies of template literals, multi-line strings and comments.
|
|
46
|
+
- Smart semicolons only cross a trailing chain of `)` and `]`, and only in TypeScript, JavaScript and PHP.
|
|
47
|
+
- Search, folding and selection expansion read the whole document on request, synchronously. A regex has no timeout, so run untrusted patterns in a worker.
|
|
48
|
+
- Word navigation reads what it crosses: a single 4 MiB word takes well over half a second. History keeps the last 200 steps. The rope has no size cap and was measured up to 25 MiB (`bun run benchmark`).
|
|
49
|
+
- Backspace and delete by grapheme need `Intl.Segmenter`.
|
|
50
|
+
- Columns are UTF-16, not graphemes or visual columns, and tab stops only matter for indentation commands and indentation folds.
|
|
51
|
+
|
|
52
|
+
## Packaging
|
|
53
|
+
|
|
54
|
+
This unpublished package is private at version `0.0.0`. Its sources retain FSL-1.1-MIT except the explicitly attributed Apache-2.0 word predicates; `LICENSE`, `NOTICE` and `LICENSE.apache-2.0.txt` are included in the package. Source consumers enable `source` in their bundler and TypeScript `customConditions`. Default exports use compiled JavaScript and declarations. Run `bun run build`, `bun run typecheck`, `bun run test`, or the separate `bun run benchmark` from the package after workspace installation.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { rangeOf } from './lexical-folds.js';
|
|
2
|
+
const MARKDOWN = /^(markdown|md|mdx)$/i;
|
|
3
|
+
const HEADING = /^(#{1,6})\s+\S/;
|
|
4
|
+
const FENCE = /^\s*(`{3,}|~{3,})/;
|
|
5
|
+
const TABLE_ROW = /^\s*\|/;
|
|
6
|
+
const HEREDOC = /<<<[ \t]*(["']?)([A-Za-z_]\w*)\1\s*$/;
|
|
7
|
+
/*
|
|
8
|
+
* Front matter, code fences, tables and the sections under headings. A fence closes on a line of the same
|
|
9
|
+
* character and at least as long, and what a fence holds is never read as a heading or a table.
|
|
10
|
+
*/
|
|
11
|
+
function markdownFolds(lineCount, getLine) {
|
|
12
|
+
const result = [];
|
|
13
|
+
const headings = [];
|
|
14
|
+
let first = 0;
|
|
15
|
+
if (lineCount > 0 && getLine(0).text.trim() === '---') {
|
|
16
|
+
for (let line = 1; line < lineCount; line++) {
|
|
17
|
+
const text = getLine(line).text.trim();
|
|
18
|
+
if (text === '---' || text === '...') {
|
|
19
|
+
result.push(rangeOf(0, line, getLine, 'block', 'front-matter'));
|
|
20
|
+
first = line + 1;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
let tableStart = -1;
|
|
26
|
+
const flushTable = (end) => {
|
|
27
|
+
if (tableStart !== -1 && end > tableStart) {
|
|
28
|
+
result.push(rangeOf(tableStart, end, getLine, 'block', 'table'));
|
|
29
|
+
}
|
|
30
|
+
tableStart = -1;
|
|
31
|
+
};
|
|
32
|
+
for (let line = first; line < lineCount; line++) {
|
|
33
|
+
const text = getLine(line).text;
|
|
34
|
+
const fence = FENCE.exec(text);
|
|
35
|
+
if (fence !== null) {
|
|
36
|
+
flushTable(line - 1);
|
|
37
|
+
const marker = fence[1];
|
|
38
|
+
let end = -1;
|
|
39
|
+
for (let next = line + 1; next < lineCount && end === -1; next++) {
|
|
40
|
+
const closer = FENCE.exec(getLine(next).text);
|
|
41
|
+
if (closer !== null && closer[1][0] === marker[0] && closer[1].length >= marker.length && getLine(next).text.trim() === closer[1]) {
|
|
42
|
+
end = next;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (end !== -1) {
|
|
46
|
+
result.push(rangeOf(line, end, getLine, 'block', 'code-fence'));
|
|
47
|
+
line = end;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (TABLE_ROW.test(text)) {
|
|
52
|
+
tableStart = tableStart === -1 ? line : tableStart;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
flushTable(line - 1);
|
|
56
|
+
const heading = HEADING.exec(text);
|
|
57
|
+
if (heading !== null) {
|
|
58
|
+
headings.push({ line, level: heading[1].length });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
flushTable(lineCount - 1);
|
|
62
|
+
for (const [index, heading] of headings.entries()) {
|
|
63
|
+
const next = headings.slice(index + 1).find((candidate) => candidate.level <= heading.level);
|
|
64
|
+
let end = (next?.line ?? lineCount) - 1;
|
|
65
|
+
while (end > heading.line && getLine(end).text.trim() === '') {
|
|
66
|
+
end--;
|
|
67
|
+
}
|
|
68
|
+
if (end > heading.line) {
|
|
69
|
+
result.push(rangeOf(heading.line, end, getLine, 'section'));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/* `<?php ... ?>` blocks that sit between markup, and heredocs and nowdocs. A block that opens the file is the file, not a fold. */
|
|
75
|
+
function phpFolds(lineCount, getLine) {
|
|
76
|
+
const result = [];
|
|
77
|
+
let open = -1;
|
|
78
|
+
for (let line = 0; line < lineCount; line++) {
|
|
79
|
+
const text = getLine(line).text;
|
|
80
|
+
const heredoc = HEREDOC.exec(text);
|
|
81
|
+
if (heredoc !== null) {
|
|
82
|
+
const closer = new RegExp(`^\\s*${heredoc[2]}\\b`);
|
|
83
|
+
for (let next = line + 1; next < lineCount; next++) {
|
|
84
|
+
if (closer.test(getLine(next).text)) {
|
|
85
|
+
result.push(rangeOf(line, next, getLine, 'block', 'heredoc'));
|
|
86
|
+
line = next;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const opened = open === -1 ? text.search(/<\?(?:php\b|=)/) : -1;
|
|
93
|
+
const closed = text.indexOf('?>', Math.max(0, opened));
|
|
94
|
+
if (opened !== -1 && closed === -1) {
|
|
95
|
+
open = line === 0 ? -1 : line;
|
|
96
|
+
}
|
|
97
|
+
else if (open !== -1 && closed !== -1) {
|
|
98
|
+
if (line > open) {
|
|
99
|
+
result.push(rangeOf(open, line, getLine, 'block', 'php-tag'));
|
|
100
|
+
}
|
|
101
|
+
open = -1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/* The folds of whole lines that a language has beyond brackets and indentation. */
|
|
107
|
+
export function blockFolds(lineCount, getLine, language) {
|
|
108
|
+
if (MARKDOWN.test(language)) {
|
|
109
|
+
return markdownFolds(lineCount, getLine);
|
|
110
|
+
}
|
|
111
|
+
return language.toLowerCase() === 'php' ? phpFolds(lineCount, getLine) : [];
|
|
112
|
+
}
|
package/dist/brackets.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { hasBlockComments, hasDashComments, hasHashComments, hashNeedsWordStart, hasMarkupComments, hasSlashComments, isPhp, isScript, isWordCharacter, openers, startsExpression, startsExpressionAfter, startsWord } from './lexical.js';
|
|
2
|
+
function skipLine(text, at) {
|
|
3
|
+
const end = text.indexOf('\n', at + 1);
|
|
4
|
+
return end < 0 ? text.length : end;
|
|
5
|
+
}
|
|
6
|
+
function skipComment(text, from, terminator) {
|
|
7
|
+
const end = text.indexOf(terminator, from);
|
|
8
|
+
return end < 0 ? text.length : end + terminator.length - 1;
|
|
9
|
+
}
|
|
10
|
+
function skipString(text, at, quote, endsAtLineBreak) {
|
|
11
|
+
let cursor = at + 1;
|
|
12
|
+
for (; cursor < text.length; cursor++) {
|
|
13
|
+
if (text[cursor] === '\\') {
|
|
14
|
+
cursor++;
|
|
15
|
+
}
|
|
16
|
+
else if (text[cursor] === quote || (endsAtLineBreak && /[\r\n]/.test(text[cursor]))) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return cursor;
|
|
21
|
+
}
|
|
22
|
+
function skipRegex(text, at) {
|
|
23
|
+
let inClass = false;
|
|
24
|
+
let cursor = at + 1;
|
|
25
|
+
for (; cursor < text.length; cursor++) {
|
|
26
|
+
const character = text[cursor];
|
|
27
|
+
if (character === '\\') {
|
|
28
|
+
cursor++;
|
|
29
|
+
}
|
|
30
|
+
else if (character === '[') {
|
|
31
|
+
inClass = true;
|
|
32
|
+
}
|
|
33
|
+
else if (character === ']') {
|
|
34
|
+
inClass = false;
|
|
35
|
+
}
|
|
36
|
+
else if ((character === '/' && !inClass) || /[\r\n]/.test(character)) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return cursor;
|
|
41
|
+
}
|
|
42
|
+
/* Lexical pairing for incomplete code; malformed nesting never produces crossing pairs. */
|
|
43
|
+
export function scanBrackets(text, language = 'typescript') {
|
|
44
|
+
const pairs = new Map();
|
|
45
|
+
const unmatched = new Set();
|
|
46
|
+
const stack = [];
|
|
47
|
+
const script = isScript(language);
|
|
48
|
+
const hashComments = hasHashComments(language);
|
|
49
|
+
const hashAtWordStart = hashNeedsWordStart(language);
|
|
50
|
+
const dashComments = hasDashComments(language);
|
|
51
|
+
const phpAttributes = isPhp(language);
|
|
52
|
+
const slashComments = hasSlashComments(language);
|
|
53
|
+
const blockComments = hasBlockComments(language);
|
|
54
|
+
const markupComments = hasMarkupComments(language);
|
|
55
|
+
let inTemplate = false;
|
|
56
|
+
let expectsExpression = true;
|
|
57
|
+
for (let at = 0; at < text.length; at++) {
|
|
58
|
+
const char = text[at];
|
|
59
|
+
const next = text[at + 1];
|
|
60
|
+
if (inTemplate) {
|
|
61
|
+
if (char === '\\') {
|
|
62
|
+
at++;
|
|
63
|
+
}
|
|
64
|
+
else if (char === '`') {
|
|
65
|
+
inTemplate = false;
|
|
66
|
+
expectsExpression = false;
|
|
67
|
+
}
|
|
68
|
+
else if (char === '$' && next === '{') {
|
|
69
|
+
stack.push({ at: ++at, close: '}', template: true });
|
|
70
|
+
inTemplate = false;
|
|
71
|
+
expectsExpression = true;
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (/\s/.test(char)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (markupComments && text.startsWith('<!--', at)) {
|
|
79
|
+
at = skipComment(text, at + 4, '-->');
|
|
80
|
+
}
|
|
81
|
+
else if ((slashComments && char === '/' && next === '/') ||
|
|
82
|
+
(dashComments && char === '-' && next === '-') ||
|
|
83
|
+
(hashComments && char === '#' && !(phpAttributes && next === '[') && (!hashAtWordStart || startsWord(text, at)))) {
|
|
84
|
+
at = skipLine(text, at);
|
|
85
|
+
}
|
|
86
|
+
else if (blockComments && char === '/' && next === '*') {
|
|
87
|
+
at = skipComment(text, at + 2, '*/');
|
|
88
|
+
}
|
|
89
|
+
else if (char === '"' || char === "'") {
|
|
90
|
+
at = skipString(text, at, char, script);
|
|
91
|
+
expectsExpression = false;
|
|
92
|
+
}
|
|
93
|
+
else if (script && char === '`') {
|
|
94
|
+
inTemplate = true;
|
|
95
|
+
}
|
|
96
|
+
else if (script && char === '/' && expectsExpression) {
|
|
97
|
+
at = skipRegex(text, at);
|
|
98
|
+
expectsExpression = false;
|
|
99
|
+
}
|
|
100
|
+
else if (openers[char]) {
|
|
101
|
+
stack.push({ at, close: openers[char] });
|
|
102
|
+
expectsExpression = true;
|
|
103
|
+
}
|
|
104
|
+
else if (/[)\]}]/.test(char)) {
|
|
105
|
+
const open = stack.at(-1);
|
|
106
|
+
if (open?.close === char) {
|
|
107
|
+
stack.pop();
|
|
108
|
+
pairs.set(open.at, at);
|
|
109
|
+
pairs.set(at, open.at);
|
|
110
|
+
inTemplate = open.template === true;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
unmatched.add(at);
|
|
114
|
+
// A mismatched closer keeps a distant opener from claiming it later.
|
|
115
|
+
for (const abandoned of stack.splice(0)) {
|
|
116
|
+
unmatched.add(abandoned.at);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
expectsExpression = false;
|
|
120
|
+
}
|
|
121
|
+
else if (isWordCharacter(char)) {
|
|
122
|
+
const start = at;
|
|
123
|
+
while (at + 1 < text.length && isWordCharacter(text[at + 1])) {
|
|
124
|
+
at++;
|
|
125
|
+
}
|
|
126
|
+
expectsExpression = startsExpression(text.slice(start, at + 1));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
expectsExpression = startsExpressionAfter(char);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const open of stack) {
|
|
133
|
+
unmatched.add(open.at);
|
|
134
|
+
}
|
|
135
|
+
return { pairs, unmatched };
|
|
136
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Selection, TextEdit } from './types.ts';
|
|
2
|
+
export declare class CloserTracker {
|
|
3
|
+
private marks;
|
|
4
|
+
add(open: number, close: number): void;
|
|
5
|
+
isCloserAt(offset: number): boolean;
|
|
6
|
+
map(edits: readonly TextEdit[]): void;
|
|
7
|
+
prune(selections: readonly Selection[]): void;
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|