@rse/ink-editor 0.0.0-stage → 0.9.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/.claude/CLAUDE.md +1 -0
- package/AGENTS.md +99 -0
- package/CHANGELOG.md +9 -0
- package/README.md +116 -2
- package/dst-stage1/ink-editor-cli.d.ts +2 -0
- package/dst-stage1/ink-editor-cli.js +174 -0
- package/dst-stage1/ink-editor-engine-emacs.d.ts +103 -0
- package/dst-stage1/ink-editor-engine-emacs.js +1530 -0
- package/dst-stage1/ink-editor-engine-nano.d.ts +78 -0
- package/dst-stage1/ink-editor-engine-nano.js +884 -0
- package/dst-stage1/ink-editor-engine-vim.d.ts +124 -0
- package/dst-stage1/ink-editor-engine-vim.js +2220 -0
- package/dst-stage1/ink-editor-engine-vscode.d.ts +79 -0
- package/dst-stage1/ink-editor-engine-vscode.js +850 -0
- package/dst-stage1/ink-editor-mode-emacs.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-emacs.js +143 -0
- package/dst-stage1/ink-editor-mode-nano.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-nano.js +140 -0
- package/dst-stage1/ink-editor-mode-vim.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-vim.js +230 -0
- package/dst-stage1/ink-editor-mode-vscode.d.ts +12 -0
- package/dst-stage1/ink-editor-mode-vscode.js +133 -0
- package/dst-stage1/ink-editor-mode.d.ts +72 -0
- package/dst-stage1/ink-editor-mode.js +24 -0
- package/dst-stage1/ink-editor-syntax.d.ts +14 -0
- package/dst-stage1/ink-editor-syntax.js +149 -0
- package/dst-stage1/ink-editor-text.d.ts +38 -0
- package/dst-stage1/ink-editor-text.js +177 -0
- package/dst-stage1/ink-editor-widget.d.ts +15 -0
- package/dst-stage1/ink-editor-widget.js +132 -0
- package/dst-stage1/ink-editor.d.ts +13 -0
- package/dst-stage1/ink-editor.js +37 -0
- package/dst-stage1/tsc.tsbuildinfo +1 -0
- package/dst-stage2/ink-editor-cli.esm.js +177 -0
- package/dst-stage2/ink-editor.esm.js +5972 -0
- package/etc/c8.json +17 -0
- package/etc/eslint.mts +84 -0
- package/etc/knip.jsonc +51 -0
- package/etc/stx.conf +103 -0
- package/etc/tsc.json +29 -0
- package/etc/vite.mts +79 -0
- package/package.d/@typescript-eslint+typescript-estree+8.74.0.patch +12 -0
- package/package.d/vite+8.4.1.patch +12 -0
- package/package.json +79 -5
- package/src/ink-editor-cli.ts +200 -0
- package/src/ink-editor-engine-emacs.ts +1648 -0
- package/src/ink-editor-engine-nano.ts +978 -0
- package/src/ink-editor-engine-vim.ts +2203 -0
- package/src/ink-editor-engine-vscode.ts +938 -0
- package/src/ink-editor-mode-emacs.ts +137 -0
- package/src/ink-editor-mode-nano.ts +135 -0
- package/src/ink-editor-mode-vim.ts +223 -0
- package/src/ink-editor-mode-vscode.ts +129 -0
- package/src/ink-editor-mode.ts +137 -0
- package/src/ink-editor-syntax.ts +176 -0
- package/src/ink-editor-text.ts +205 -0
- package/src/ink-editor-widget.ts +182 -0
- package/src/ink-editor.ts +48 -0
- package/tst/ink-editor-1-vim.spec.ts +177 -0
- package/tst/ink-editor-2-emacs.spec.ts +211 -0
- package/tst/ink-editor-3-nano.spec.ts +187 -0
- package/tst/ink-editor-4-vscode.spec.ts +187 -0
- package/tst/tsc.json +27 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Ink-Editor -- Text Editor with Exchangeable Editing Modes for Ink
|
|
3
|
+
** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
|
+
**
|
|
5
|
+
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
** a copy of this software and associated documentation files (the
|
|
7
|
+
** "Software"), to deal in the Software without restriction, including
|
|
8
|
+
** without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
** distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
** permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
** the following conditions:
|
|
12
|
+
**
|
|
13
|
+
** The above copyright notice and this permission notice shall be included
|
|
14
|
+
** in all copies or substantial portions of the Software.
|
|
15
|
+
**
|
|
16
|
+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/* terminal-free tests of the Nano engine */
|
|
26
|
+
|
|
27
|
+
/* external dependencies (test suite) */
|
|
28
|
+
import { describe, it } from "mocha"
|
|
29
|
+
import * as chai from "chai"
|
|
30
|
+
|
|
31
|
+
/* external dependencies */
|
|
32
|
+
import { TextareaUtils } from "better-ink-ui"
|
|
33
|
+
|
|
34
|
+
/* internal dependencies */
|
|
35
|
+
import { Nano } from "../src/ink-editor-engine-nano"
|
|
36
|
+
import type { NanoFiles } from "../src/ink-editor-engine-nano"
|
|
37
|
+
import type { TextOps } from "../src/ink-editor-text"
|
|
38
|
+
|
|
39
|
+
/* setup test suite infrastructure */
|
|
40
|
+
chai.config.includeStack = true
|
|
41
|
+
const { expect } = chai
|
|
42
|
+
|
|
43
|
+
/* the text operations of the Textarea, as supplied by the Editor widget */
|
|
44
|
+
const textareaOps: TextOps = {
|
|
45
|
+
previous: TextareaUtils.previous,
|
|
46
|
+
next: TextareaUtils.next,
|
|
47
|
+
wordStart: TextareaUtils.wordStart,
|
|
48
|
+
vertical: (v, o, direction) => {
|
|
49
|
+
const cursor = TextareaUtils.cursor(v, o)
|
|
50
|
+
const rows = TextareaUtils.rows({ value: v, width: 80, cursor })
|
|
51
|
+
return TextareaUtils.vertical({ value: v, rows, cursor, direction })
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* feed the keys of a case into a fresh engine, one key press at a time
|
|
56
|
+
(with "{...}" for named keys like "{^K}", "{M-U}", or "{Enter}") */
|
|
57
|
+
const run = (text: string, keys: string, files?: NanoFiles) => {
|
|
58
|
+
const nano = new Nano(text, textareaOps)
|
|
59
|
+
if (files)
|
|
60
|
+
nano.files = files
|
|
61
|
+
for (const token of keys.match(/\{[^}]+\}|./gsu) ?? [])
|
|
62
|
+
nano.keys([ token.length > 2 && token.startsWith("{") ? token.slice(1, -1) : token ])
|
|
63
|
+
return nano
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* a test case: name, initial text, keys, and expected text */
|
|
67
|
+
type Case = [ string, string, string, string ]
|
|
68
|
+
const fill = (n: number) => Array(n).fill("word").join(" ")
|
|
69
|
+
const cases: Case[] = [
|
|
70
|
+
/* moving */
|
|
71
|
+
[ "^F ^B", "abc", "{^F}{^F}{^B}X", "aXbc" ],
|
|
72
|
+
[ "^A ^E", "abc\ndef", "{^N}{^E}X{^A}Y", "abc\nYdefX" ],
|
|
73
|
+
[ "^N goal column", "abcdef\nab\nabcdef", "{^E}{^B}{^N}{^N}X", "abcdef\nab\nabcdeXf" ],
|
|
74
|
+
[ "^Space", "foo bar", "{^Space}X", "foo Xbar" ],
|
|
75
|
+
[ "M-] bracket", "(a)", "{M-]}X", "(aX)" ],
|
|
76
|
+
[ "^_ go to line", "1\n2\n3", "{^_}3{Enter}X", "1\n2\nX3" ],
|
|
77
|
+
[ "Esc as Meta", "", "abc{Esc}u", "" ],
|
|
78
|
+
|
|
79
|
+
/* cutting and pasting */
|
|
80
|
+
[ "^K ^U", "a\nb\nc", "{^K}{^N}{^U}", "b\na\nc" ],
|
|
81
|
+
[ "^K ^K accumulating", "a\nb\nc", "{^K}{^K}{^E}{Enter}{^U}", "c\na\nb\n" ],
|
|
82
|
+
[ "^K on the last line", "a\nb", "{^N}{^K}{^U}{^U}", "a\nb\nb\n" ],
|
|
83
|
+
[ "M-A ^K region", "abcdef", "{^F}{M-A}{^F}{^F}{^K}", "adef" ],
|
|
84
|
+
[ "M-6 copy line", "a\nb", "{M-6}{^U}", "a\na\nb" ],
|
|
85
|
+
|
|
86
|
+
/* inserting and deleting */
|
|
87
|
+
[ "^D Bsp", "abc", "{^F}{^D}{Bsp}", "c" ],
|
|
88
|
+
[ "M-Bsp", "foo bar", "{^E}{M-Bsp}", "foo " ],
|
|
89
|
+
[ "M-V verbatim", "", "{M-V}{Tab}", "\t" ],
|
|
90
|
+
[ "Tab with mark", "a\nb", "{M-A}{^E}{^N}{Tab}", "\ta\n\tb" ],
|
|
91
|
+
[ "M-{ unindent", "\ta", "{M-{}", "a" ],
|
|
92
|
+
[ "M-3 comment", "a\nb", "{M-3}", "#a\nb" ],
|
|
93
|
+
[ "M-3 uncomment", "#a\nb", "{M-3}", "a\nb" ],
|
|
94
|
+
[ "^J justify", fill(20), "{^J}", fill(14) + "\n" + fill(6) ],
|
|
95
|
+
|
|
96
|
+
/* undoing */
|
|
97
|
+
[ "M-U", "", "abc{M-U}", "" ],
|
|
98
|
+
[ "M-U M-E", "", "abc{M-U}{M-E}", "abc" ],
|
|
99
|
+
|
|
100
|
+
/* searching and replacing */
|
|
101
|
+
[ "^W", "foo bar foo", "{^W}foo{Enter}X", "foo bar Xfoo" ],
|
|
102
|
+
[ "^W wrapping", "foo bar foo", "{M-/}{^W}foo{Enter}X", "Xfoo bar foo" ],
|
|
103
|
+
[ "^W M-W", "a x a x a", "{^W}a{Enter}{M-W}X", "a x a x Xa" ],
|
|
104
|
+
[ "^Q", "a x a", "{M-/}{^Q}a{Enter}X", "a x Xa" ],
|
|
105
|
+
[ "^\\ y n y", "a a a", "{^\\}a{Enter}b{Enter}yny", "b a b" ],
|
|
106
|
+
[ "^\\ all", "a a a", "{^\\}a{Enter}b{Enter}a", "b b b" ],
|
|
107
|
+
[ "^\\ wrapping", "a a a", "{^F}{^F}{^\\}a{Enter}b{Enter}a", "b b b" ],
|
|
108
|
+
|
|
109
|
+
/* regressions */
|
|
110
|
+
[ "^K on the empty last line", "a\nb\n", "{^N}{^N}{^K}{^K}{^U}", "a\nb\n" ],
|
|
111
|
+
[ "M-3 with blank line", "#a\n\n#b", "{M-A}{^N}{^N}{^E}{M-3}", "a\n\nb" ],
|
|
112
|
+
[ "no-op keeps redo", "", "abc{M-U}{M-Bsp}{M-E}", "abc" ]
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
describe("Nano engine", () => {
|
|
116
|
+
for (const [ name, text, keys, expected ] of cases) {
|
|
117
|
+
it(name, () => {
|
|
118
|
+
expect(run(text, keys).value).to.equal(expected)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
it("search wrapped message", () => {
|
|
122
|
+
expect(run("foo bar foo", "{M-/}{^W}foo{Enter}").message).to.equal("Search Wrapped")
|
|
123
|
+
})
|
|
124
|
+
it("unbound key", () => {
|
|
125
|
+
const nano = run("", "{^]}")
|
|
126
|
+
expect(nano.message).to.equal("Unbound key: ^]")
|
|
127
|
+
expect(nano.error).to.equal(true)
|
|
128
|
+
})
|
|
129
|
+
it("^C location", () => {
|
|
130
|
+
expect(run("ab\ncd", "{^N}{^C}").message).to.equal("line 2/2 (100%), col 1/3 (33%), char 4/6 (67%)")
|
|
131
|
+
})
|
|
132
|
+
it("M-D word count", () => {
|
|
133
|
+
expect(run("a b\nc", "{M-D}").message).to.equal("Words: 3 Lines: 2 Chars: 5")
|
|
134
|
+
})
|
|
135
|
+
it("M-D word count with final newline", () => {
|
|
136
|
+
expect(run("a\nb\n", "{M-D}").message).to.equal("Words: 2 Lines: 2 Chars: 4")
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
/* a fake of the file operations, logging the calls */
|
|
141
|
+
const fake = (exists = false) => {
|
|
142
|
+
const log: string[] = []
|
|
143
|
+
let modified = true
|
|
144
|
+
const files: NanoFiles = {
|
|
145
|
+
name: () => "f.txt",
|
|
146
|
+
modified: () => modified,
|
|
147
|
+
write: (file, force, rename) => {
|
|
148
|
+
log.push(`write ${file}|${force}|${rename}`)
|
|
149
|
+
if (exists && !force)
|
|
150
|
+
return { message: `File "${file}" exists`, error: true, exists: true }
|
|
151
|
+
modified = false
|
|
152
|
+
return { message: "Wrote 1 line", error: false }
|
|
153
|
+
},
|
|
154
|
+
quit: (failed) => { log.push(`quit ${failed ? 1 : 0}`) }
|
|
155
|
+
}
|
|
156
|
+
return { log, files }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
describe("Nano engine files", () => {
|
|
160
|
+
it("^O", () => {
|
|
161
|
+
const { log, files } = fake()
|
|
162
|
+
const nano = run("", "{^O}{Enter}", files)
|
|
163
|
+
expect(log).to.deep.equal([ "write f.txt|false|false" ])
|
|
164
|
+
expect(nano.message).to.equal("Wrote 1 line")
|
|
165
|
+
})
|
|
166
|
+
it("^S", () => {
|
|
167
|
+
const { log, files } = fake()
|
|
168
|
+
run("", "{^S}", files)
|
|
169
|
+
expect(log).to.deep.equal([ "write |false|false" ])
|
|
170
|
+
})
|
|
171
|
+
it("^X saving", () => {
|
|
172
|
+
const { log, files } = fake()
|
|
173
|
+
run("", "{^X}y{Enter}", files)
|
|
174
|
+
expect(log).to.deep.equal([ "write f.txt|false|false", "quit 0" ])
|
|
175
|
+
})
|
|
176
|
+
it("^X discarding", () => {
|
|
177
|
+
const { log, files } = fake()
|
|
178
|
+
run("", "{^X}n", files)
|
|
179
|
+
expect(log).to.deep.equal([ "quit 0" ])
|
|
180
|
+
})
|
|
181
|
+
it("^O overwriting", () => {
|
|
182
|
+
const { log, files } = fake(true)
|
|
183
|
+
run("", "{^O}{Bsp}{Bsp}{Bsp}{Bsp}{Bsp}g.txt{Enter}y", files)
|
|
184
|
+
expect(log).to.deep.equal([ "write g.txt|false|true", "write g.txt|true|true" ])
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** Ink-Editor -- Text Editor with Exchangeable Editing Modes for Ink
|
|
3
|
+
** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
|
+
**
|
|
5
|
+
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
** a copy of this software and associated documentation files (the
|
|
7
|
+
** "Software"), to deal in the Software without restriction, including
|
|
8
|
+
** without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
** distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
** permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
** the following conditions:
|
|
12
|
+
**
|
|
13
|
+
** The above copyright notice and this permission notice shall be included
|
|
14
|
+
** in all copies or substantial portions of the Software.
|
|
15
|
+
**
|
|
16
|
+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/* terminal-free tests of the VS Code-style engine */
|
|
26
|
+
|
|
27
|
+
/* external dependencies (test suite) */
|
|
28
|
+
import { describe, it } from "mocha"
|
|
29
|
+
import * as chai from "chai"
|
|
30
|
+
|
|
31
|
+
/* external dependencies */
|
|
32
|
+
import { TextareaUtils } from "better-ink-ui"
|
|
33
|
+
|
|
34
|
+
/* internal dependencies */
|
|
35
|
+
import { Code } from "../src/ink-editor-engine-vscode"
|
|
36
|
+
import type { CodeFiles } from "../src/ink-editor-engine-vscode"
|
|
37
|
+
import { toCursor } from "../src/ink-editor-text"
|
|
38
|
+
import type { TextOps } from "../src/ink-editor-text"
|
|
39
|
+
|
|
40
|
+
/* setup test suite infrastructure */
|
|
41
|
+
chai.config.includeStack = true
|
|
42
|
+
const { expect } = chai
|
|
43
|
+
|
|
44
|
+
/* the text operations of the Textarea, as supplied by the Editor widget */
|
|
45
|
+
const textareaOps: TextOps = {
|
|
46
|
+
previous: TextareaUtils.previous,
|
|
47
|
+
next: TextareaUtils.next,
|
|
48
|
+
wordStart: TextareaUtils.wordStart,
|
|
49
|
+
vertical: (v, o, direction) => {
|
|
50
|
+
const cursor = TextareaUtils.cursor(v, o)
|
|
51
|
+
const rows = TextareaUtils.rows({ value: v, width: 80, cursor })
|
|
52
|
+
return TextareaUtils.vertical({ value: v, rows, cursor, direction })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* feed the keys of a case into a fresh engine, one key press at a time
|
|
57
|
+
(with "{...}" for named keys like "{ctrl+s}", "{shift+left}", or "{enter}") */
|
|
58
|
+
const run = (text: string, keys: string, files?: CodeFiles) => {
|
|
59
|
+
const code = new Code(text, textareaOps)
|
|
60
|
+
if (files)
|
|
61
|
+
code.files = files
|
|
62
|
+
for (const token of keys.match(/\{[^}]+\}|./gsu) ?? [])
|
|
63
|
+
code.keys([ token.length > 2 && token.startsWith("{") ? token.slice(1, -1) : token ])
|
|
64
|
+
return code
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* a test case: name, initial text, keys, expected text, and optional expected cursor */
|
|
68
|
+
type Case = [ string, string, string, string, [ number, number ]? ]
|
|
69
|
+
const cases: Case[] = [
|
|
70
|
+
/* typing, selecting, and deleting */
|
|
71
|
+
[ "typing replaces selection", "abc", "{shift+right}{shift+right}X", "Xc" ],
|
|
72
|
+
[ "shift+end backspace", "abc def", "{right}{shift+end}{backspace}", "a" ],
|
|
73
|
+
[ "left collapses selection", "abc", "{shift+right}{shift+right}{left}X", "Xabc" ],
|
|
74
|
+
[ "ctrl+right", "foo bar", "{ctrl+right}X", "fooX bar" ],
|
|
75
|
+
[ "ctrl+shift+left", "foo bar", "{end}{ctrl+shift+left}X", "foo X" ],
|
|
76
|
+
[ "smart home", " ab", "{end}{home}X", " Xab" ],
|
|
77
|
+
[ "smart home twice", " ab", "{end}{home}{home}X", "X ab" ],
|
|
78
|
+
[ "alt+backspace", "foo bar", "{end}{alt+backspace}", "foo " ],
|
|
79
|
+
[ "down goal column", "abcdef\nab\nabcdef", "{end}{left}{down}{down}X", "abcdef\nab\nabcdeXf" ],
|
|
80
|
+
|
|
81
|
+
/* lines and indentation */
|
|
82
|
+
[ "enter keeps indentation", " a", "{end}{enter}b", " a\n b" ],
|
|
83
|
+
[ "tab inserts spaces", "", "{tab}x", " x" ],
|
|
84
|
+
[ "tab indents lines", "a\nb", "{ctrl+a}{tab}", " a\n b" ],
|
|
85
|
+
[ "shift+tab outdents", " a", "{shift+tab}", "a" ],
|
|
86
|
+
[ "alt+down", "a\nb\nc", "{alt+down}", "b\na\nc", [ 1, 0 ] ],
|
|
87
|
+
[ "alt+up", "a\nb", "{down}{alt+up}", "b\na", [ 0, 0 ] ],
|
|
88
|
+
[ "shift+alt+down", "a\nb", "{shift+alt+down}", "a\na\nb", [ 1, 0 ] ],
|
|
89
|
+
[ "ctrl+/ comments", "a\n b", "{ctrl+a}{ctrl+_}", "# a\n# b" ],
|
|
90
|
+
[ "ctrl+/ uncomments", "# a\n# b", "{ctrl+a}{ctrl+_}", "a\n b" ],
|
|
91
|
+
[ "ctrl+shift+k", "a\nb\nc", "{down}{ctrl+shift+k}", "a\nc" ],
|
|
92
|
+
[ "ctrl+enter", "ab\ncd", "{ctrl+enter}x", "ab\nx\ncd" ],
|
|
93
|
+
[ "ctrl+l", "a\nb", "{ctrl+l}{backspace}", "b" ],
|
|
94
|
+
[ "ctrl+d", "foo bar foo", "{ctrl+d}{ctrl+d}X", "foo bar X" ],
|
|
95
|
+
|
|
96
|
+
/* the clipboard and undoing */
|
|
97
|
+
[ "ctrl+c ctrl+v line", "a\nb", "{ctrl+c}{down}{ctrl+v}", "a\na\nb", [ 2, 0 ] ],
|
|
98
|
+
[ "ctrl+x line", "a\nb", "{ctrl+x}", "b" ],
|
|
99
|
+
[ "ctrl+x ctrl+v selection", "abc", "{shift+right}{ctrl+x}{end}{ctrl+v}", "bca" ],
|
|
100
|
+
[ "ctrl+z", "", "abc{ctrl+z}", "" ],
|
|
101
|
+
[ "ctrl+z ctrl+y", "", "abc{ctrl+z}{ctrl+y}", "abc" ],
|
|
102
|
+
[ "ctrl+x last line", "a\nb", "{down}{ctrl+x}", "a" ],
|
|
103
|
+
[ "ctrl+x last line ctrl+v", "a\nb", "{down}{ctrl+x}{ctrl+v}", "b\na" ],
|
|
104
|
+
[ "no-op delete keeps redo", "", "abc{ctrl+z}{backspace}{delete}{ctrl+y}", "abc" ],
|
|
105
|
+
|
|
106
|
+
/* finding and replacing */
|
|
107
|
+
[ "ctrl+f enter escape", "foo bar foo", "{ctrl+f}foo{enter}{escape}X", "foo bar X" ],
|
|
108
|
+
[ "ctrl+f up", "a x a x", "{ctrl+end}{ctrl+f}x{up}{escape}Y", "a x a Y" ],
|
|
109
|
+
[ "ctrl+h y n y", "a a a", "{ctrl+h}a{enter}b{enter}yny", "b a b" ],
|
|
110
|
+
[ "ctrl+h all", "a a a", "{ctrl+h}a{enter}b{enter}a", "b b b" ],
|
|
111
|
+
[ "ctrl+g", "1\n2\n3", "{ctrl+g}3{enter}X", "1\n2\nX3" ]
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
describe("VS Code-style engine", () => {
|
|
115
|
+
for (const [ name, text, keys, expected, cursor ] of cases) {
|
|
116
|
+
it(name, () => {
|
|
117
|
+
const code = run(text, keys)
|
|
118
|
+
expect(code.value).to.equal(expected)
|
|
119
|
+
if (cursor)
|
|
120
|
+
expect(toCursor(code.value, code.off)).to.deep.equal(cursor)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
it("bracketed paste replaces selection", () => {
|
|
124
|
+
const code = run("abc", "{shift+right}")
|
|
125
|
+
code.paste("XY")
|
|
126
|
+
expect(code.value).to.equal("XYbc")
|
|
127
|
+
})
|
|
128
|
+
it("find count", () => {
|
|
129
|
+
expect(run("a x a x", "{ctrl+f}x{enter}").prompt()).to.equal("Find (2 of 2): x")
|
|
130
|
+
})
|
|
131
|
+
it("mouse click resets goal column", () => {
|
|
132
|
+
const code = run("abcdef\nab\nabcdef", "{end}{down}")
|
|
133
|
+
code.onCursor([ 0, 1 ])
|
|
134
|
+
code.keys([ "down" ])
|
|
135
|
+
code.keys([ "X" ])
|
|
136
|
+
expect(code.value).to.equal("abcdef\naXb\nabcdef")
|
|
137
|
+
})
|
|
138
|
+
it("mouse click ends typing undo step", () => {
|
|
139
|
+
const code = run("", "ab")
|
|
140
|
+
code.onCursor([ 0, 0 ])
|
|
141
|
+
code.keys([ "X" ])
|
|
142
|
+
code.keys([ "ctrl+z" ])
|
|
143
|
+
expect(code.value).to.equal("ab")
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
/* a fake of the file operations, logging the calls */
|
|
148
|
+
const fake = (name = "f.txt") => {
|
|
149
|
+
const log: string[] = []
|
|
150
|
+
let modified = true
|
|
151
|
+
const files: CodeFiles = {
|
|
152
|
+
name: () => name,
|
|
153
|
+
modified: () => modified,
|
|
154
|
+
write: (file, force, rename) => {
|
|
155
|
+
log.push(`write ${file}|${force}|${rename}`)
|
|
156
|
+
modified = false
|
|
157
|
+
return { message: `Saved ${file || name}`, error: false }
|
|
158
|
+
},
|
|
159
|
+
quit: (failed) => { log.push(`quit ${failed ? 1 : 0}`) }
|
|
160
|
+
}
|
|
161
|
+
return { log, files }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
describe("VS Code-style engine files", () => {
|
|
165
|
+
it("ctrl+s", () => {
|
|
166
|
+
const { log, files } = fake()
|
|
167
|
+
const code = run("", "{ctrl+s}", files)
|
|
168
|
+
expect(log).to.deep.equal([ "write |false|false" ])
|
|
169
|
+
expect(code.message).to.equal("Saved f.txt")
|
|
170
|
+
})
|
|
171
|
+
it("ctrl+s without a name", () => {
|
|
172
|
+
const { log, files } = fake("")
|
|
173
|
+
run("", "{ctrl+s}g.txt{enter}", files)
|
|
174
|
+
expect(log).to.deep.equal([ "write g.txt|false|true" ])
|
|
175
|
+
})
|
|
176
|
+
it("ctrl+q saving", () => {
|
|
177
|
+
const { log, files } = fake()
|
|
178
|
+
run("", "{ctrl+q}y", files)
|
|
179
|
+
expect(log).to.deep.equal([ "write |false|false", "quit 0" ])
|
|
180
|
+
})
|
|
181
|
+
it("ctrl+q discarding", () => {
|
|
182
|
+
const { log, files } = fake()
|
|
183
|
+
run("", "{ctrl+q}n", files)
|
|
184
|
+
expect(log).to.deep.equal([ "quit 0" ])
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
package/tst/tsc.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "../dst-stage1",
|
|
4
|
+
"target": "es2023",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"useDefineForClassFields": false,
|
|
8
|
+
"composite": false,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"strictFunctionTypes": true,
|
|
11
|
+
"resolveJsonModule": false,
|
|
12
|
+
"isolatedModules": false,
|
|
13
|
+
"lib": [ "es2023" ],
|
|
14
|
+
"types": [ "node" ],
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"rootDir": ".."
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"*.ts"
|
|
22
|
+
],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"../node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|