File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ export default defineComponent({
170
170
<CoreEditor
171
171
v-if =" isMounted"
172
172
ref =" coreEditor"
173
+ :key =" doc?.id"
173
174
v-model =" text"
174
175
:max-width-in-chars =" maxWidthInChars"
175
176
:options =" options"
Original file line number Diff line number Diff line change @@ -31,14 +31,21 @@ export default defineComponent({
31
31
const header = computed (() => doc .value .headers [0 ])
32
32
const { public : { appTitle } } = useConfig ()
33
33
34
+ watch (docId , () => {
35
+ // If we don't create a new placeholder, then the same placeholder id
36
+ // will be used when creating multiple docs back-to-back. This only
37
+ // happens when the editor is not unmounted between new doc creations.
38
+ placeholder .value = new Doc ({ text: formatTags (store .state .context .tags , ' ' ) })
39
+ })
40
+
34
41
const onInput = async (text : string ) => {
35
42
// Todo: Load a new doc before leaving the route so that Ink does not
36
43
// send a new input event (or figure out how to prevent it from sending
37
44
// an input event when data is pushed to the editor from the store).
38
45
if (text && (! docId .value || docId .value === ' new' )) {
39
46
// When we receive input without an active doc, we should always create
40
47
// a new doc with a unique id.
41
- const newDoc = new Doc ({ text })
48
+ const newDoc = new Doc ({ id: placeholder . value . id , text })
42
49
43
50
store .commit (EDIT_DOCUMENT , newDoc )
44
51
Original file line number Diff line number Diff line change @@ -160,4 +160,25 @@ test.describe('editor', () => {
160
160
161
161
await expect ( page . getByTestId ( 'doc-backlinks' ) . getByRole ( 'link' ) ) . toHaveText ( 'Test 2' )
162
162
} )
163
+
164
+ test ( 'does not undo initial doc load' , async ( { page } ) => {
165
+ await page . goto ( '/docs/new' )
166
+ await page . waitForSelector ( '[data-is-mounted="true"]' )
167
+
168
+ await page . keyboard . type ( '# My Test Doc' )
169
+
170
+ // Wait for the data to be persisted.
171
+ await page . waitForTimeout ( 200 )
172
+
173
+ await page . reload ( )
174
+ await page . waitForSelector ( '[data-is-mounted="true"]' )
175
+
176
+ await expect ( page . locator ( '.ink-mde-editor-content' ) ) . toHaveText ( '# My Test Doc' )
177
+
178
+ await page . keyboard . down ( 'Meta' )
179
+ await page . keyboard . press ( 'z' )
180
+ await page . keyboard . up ( 'Meta' )
181
+
182
+ await expect ( page . locator ( '.ink-mde-editor-content' ) ) . toHaveText ( '# My Test Doc' )
183
+ } )
163
184
} )
You can’t perform that action at this time.
0 commit comments