Skip to content

Commit 6a50b5c

Browse files
authored
fix: Editor jumps to last cursor if you toggle a task-list item (#1911)
1 parent c8556c2 commit 6a50b5c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/muya/lib/contentState/clickCtrl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ const clickCtrl = ContentState => {
238238
this.updateChildrenCheckBoxState(checkbox, checked)
239239
this.updateParentsCheckBoxState(checkbox)
240240
}
241+
242+
const block = this.getBlock(checkbox.id)
243+
const parentBlock = this.getParent(block)
244+
const firstEditableBlock = this.firstInDescendant(parentBlock)
245+
const { key } = firstEditableBlock
246+
const offset = 0
247+
this.cursor = { start: { key, offset }, end: { key, offset } }
248+
return this.partialRender()
241249
}
242250
}
243251

src/renderer/components/editorWithTabs/editor.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default {
115115
components: {
116116
Search
117117
},
118+
118119
props: {
119120
markdown: String,
120121
cursor: Object,
@@ -124,6 +125,7 @@ export default {
124125
},
125126
platform: String
126127
},
128+
127129
computed: {
128130
...mapState({
129131
preferences: state => state.preferences,
@@ -168,11 +170,13 @@ export default {
168170
sourceCode: state => state.preferences.sourceCode
169171
})
170172
},
173+
171174
data () {
172175
this.defaultFontFamily = DEFAULT_EDITOR_FONT_FAMILY
173176
this.CloseIcon = CloseIcon
174177
// Helper to ignore changes when the spell check provider was changed in settings.
175178
this.spellcheckerIgnorChanges = false
179+
176180
return {
177181
selectionChange: null,
178182
editor: null,
@@ -186,27 +190,32 @@ export default {
186190
}
187191
}
188192
},
193+
189194
watch: {
190195
typewriter: function (value) {
191196
if (value) {
192197
this.scrollToCursor()
193198
}
194199
},
200+
195201
focus: function (value) {
196202
this.editor.setFocusMode(value)
197203
},
204+
198205
fontSize: function (value, oldValue) {
199206
const { editor } = this
200207
if (value !== oldValue && editor) {
201208
editor.setFont({ fontSize: value })
202209
}
203210
},
211+
204212
lineHeight: function (value, oldValue) {
205213
const { editor } = this
206214
if (value !== oldValue && editor) {
207215
editor.setFont({ lineHeight: value })
208216
}
209217
},
218+
210219
preferLooseListItem: function (value, oldValue) {
211220
const { editor } = this
212221
if (value !== oldValue && editor) {
@@ -215,12 +224,14 @@ export default {
215224
})
216225
}
217226
},
227+
218228
tabSize: function (value, oldValue) {
219229
const { editor } = this
220230
if (value !== oldValue && editor) {
221231
editor.setTabSize(value)
222232
}
223233
},
234+
224235
theme: function (value, oldValue) {
225236
if (value !== oldValue && this.editor) {
226237
// Agreement:Any black series theme needs to contain dark `word`.
@@ -237,95 +248,111 @@ export default {
237248
}
238249
}
239250
},
251+
240252
sequenceTheme: function (value, oldValue) {
241253
const { editor } = this
242254
if (value !== oldValue && editor) {
243255
editor.setOptions({ sequenceTheme: value }, true)
244256
}
245257
},
258+
246259
listIndentation: function (value, oldValue) {
247260
const { editor } = this
248261
if (value !== oldValue && editor) {
249262
editor.setListIndentation(value)
250263
}
251264
},
265+
252266
frontmatterType: function (value, oldValue) {
253267
const { editor } = this
254268
if (value !== oldValue && editor) {
255269
editor.setOptions({ frontmatterType: value })
256270
}
257271
},
272+
258273
superSubScript: function (value, oldValue) {
259274
const { editor } = this
260275
if (value !== oldValue && editor) {
261276
editor.setOptions({ superSubScript: value }, true)
262277
}
263278
},
279+
264280
footnote: function (value, oldValue) {
265281
const { editor } = this
266282
if (value !== oldValue && editor) {
267283
editor.setOptions({ footnote: value }, true)
268284
}
269285
},
286+
270287
hideQuickInsertHint: function (value, oldValue) {
271288
const { editor } = this
272289
if (value !== oldValue && editor) {
273290
editor.setOptions({ hideQuickInsertHint: value })
274291
}
275292
},
293+
276294
editorLineWidth: function (value, oldValue) {
277295
if (value !== oldValue) {
278296
setEditorWidth(value)
279297
}
280298
},
299+
281300
autoPairBracket: function (value, oldValue) {
282301
const { editor } = this
283302
if (value !== oldValue && editor) {
284303
editor.setOptions({ autoPairBracket: value })
285304
}
286305
},
306+
287307
autoPairMarkdownSyntax: function (value, oldValue) {
288308
const { editor } = this
289309
if (value !== oldValue && editor) {
290310
editor.setOptions({ autoPairMarkdownSyntax: value })
291311
}
292312
},
313+
293314
autoPairQuote: function (value, oldValue) {
294315
const { editor } = this
295316
if (value !== oldValue && editor) {
296317
editor.setOptions({ autoPairQuote: value })
297318
}
298319
},
320+
299321
trimUnnecessaryCodeBlockEmptyLines: function (value, oldValue) {
300322
const { editor } = this
301323
if (value !== oldValue && editor) {
302324
editor.setOptions({ trimUnnecessaryCodeBlockEmptyLines: value })
303325
}
304326
},
327+
305328
bulletListMarker: function (value, oldValue) {
306329
const { editor } = this
307330
if (value !== oldValue && editor) {
308331
editor.setOptions({ bulletListMarker: value })
309332
}
310333
},
334+
311335
orderListDelimiter: function (value, oldValue) {
312336
const { editor } = this
313337
if (value !== oldValue && editor) {
314338
editor.setOptions({ orderListDelimiter: value })
315339
}
316340
},
341+
317342
hideLinkPopup: function (value, oldValue) {
318343
const { editor } = this
319344
if (value !== oldValue && editor) {
320345
editor.setOptions({ hideLinkPopup: value })
321346
}
322347
},
348+
323349
autoCheck: function (value, oldValue) {
324350
const { editor } = this
325351
if (value !== oldValue && editor) {
326352
editor.setOptions({ autoCheck: value })
327353
}
328354
},
355+
329356
codeFontSize: function (value, oldValue) {
330357
if (value !== oldValue) {
331358
addCommonStyle({
@@ -335,12 +362,14 @@ export default {
335362
})
336363
}
337364
},
365+
338366
codeBlockLineNumbers: function (value, oldValue) {
339367
const { editor } = this
340368
if (value !== oldValue && editor) {
341369
editor.setOptions({ codeBlockLineNumbers: value }, true)
342370
}
343371
},
372+
344373
codeFontFamily: function (value, oldValue) {
345374
if (value !== oldValue) {
346375
addCommonStyle({
@@ -350,6 +379,7 @@ export default {
350379
})
351380
}
352381
},
382+
353383
hideScrollbar: function (value, oldValue) {
354384
if (value !== oldValue) {
355385
addCommonStyle({
@@ -359,6 +389,7 @@ export default {
359389
})
360390
}
361391
},
392+
362393
spellcheckerEnabled: function (value, oldValue) {
363394
if (value !== oldValue) {
364395
const { editor, spellchecker } = this
@@ -383,6 +414,7 @@ export default {
383414
}
384415
}
385416
},
417+
386418
spellcheckerIsHunspell: function (value, oldValue) {
387419
// Special case when the OS supports multiple spell checker because the
388420
// language may be invalid (provider 1 may support language xyz
@@ -409,6 +441,7 @@ export default {
409441
}
410442
}
411443
},
444+
412445
spellcheckerNoUnderline: function (value, oldValue) {
413446
if (value !== oldValue) {
414447
const { editor, spellchecker } = this
@@ -422,13 +455,15 @@ export default {
422455
}
423456
}
424457
},
458+
425459
spellcheckerAutoDetectLanguage: function (value, oldValue) {
426460
const { spellchecker } = this
427461
const { isEnabled } = spellchecker
428462
if (value !== oldValue && isEnabled) {
429463
spellchecker.automaticallyIdentifyLanguages = value
430464
}
431465
},
466+
432467
spellcheckerLanguage: function (value, oldValue) {
433468
const { spellchecker, spellcheckerIgnorChanges } = this
434469
if (!spellcheckerIgnorChanges && value !== oldValue) {
@@ -443,19 +478,22 @@ export default {
443478
}
444479
}
445480
},
481+
446482
currentFile: function (value, oldValue) {
447483
if (value && value !== oldValue) {
448484
this.scrollToCursor(0)
449485
// Hide float tools if needed.
450486
this.editor && this.editor.hideAllFloatTools()
451487
}
452488
},
489+
453490
sourceCode: function (value, oldValue) {
454491
if (value && value !== oldValue) {
455492
this.editor && this.editor.hideAllFloatTools()
456493
}
457494
}
458495
},
496+
459497
created () {
460498
this.$nextTick(() => {
461499
this.printer = new Printer()
@@ -693,17 +731,20 @@ export default {
693731
photoCreatorClick: (url) => {
694732
shell.openExternal(url)
695733
},
734+
696735
jumpClick (linkInfo) {
697736
const { href } = linkInfo
698737
this.$store.dispatch('FORMAT_LINK_CLICK', { data: { href }, dirname: window.DIRNAME })
699738
},
739+
700740
async imagePathAutoComplete (src) {
701741
const files = await this.$store.dispatch('ASK_FOR_IMAGE_AUTO_PATH', src)
702742
return files.map(f => {
703743
const iconClass = f.type === 'directory' ? 'icon-folder' : 'icon-image'
704744
return Object.assign(f, { iconClass, text: f.file + (f.type === 'directory' ? '/' : '') })
705745
})
706746
},
747+
707748
async imageAction (image, id, alt = '') {
708749
const { imageInsertAction, imageFolderPath, preferences } = this
709750
const { pathname } = this.currentFile
@@ -747,9 +788,11 @@ export default {
747788
748789
return result
749790
},
791+
750792
imagePathPicker () {
751793
return this.$store.dispatch('ASK_FOR_IMAGE_PATH')
752794
},
795+
753796
keyup (event) {
754797
if (event.key === 'Escape') {
755798
this.setImageViewerVisible(false)
@@ -788,6 +831,7 @@ export default {
788831
})
789832
})
790833
},
834+
791835
enableSpellchecker () {
792836
const {
793837
spellchecker,
@@ -822,6 +866,7 @@ export default {
822866
})
823867
})
824868
},
869+
825870
switchSpellcheckLanguage (languageCode) {
826871
const { spellchecker } = this
827872
const { isEnabled } = spellchecker
@@ -1182,22 +1227,26 @@ export default {
11821227
}
11831228
}
11841229
}
1230+
11851231
.editor-wrapper.source {
11861232
position: absolute;
11871233
z-index: -1;
11881234
top: 0;
11891235
left: 0;
11901236
overflow: hidden;
11911237
}
1238+
11921239
.editor-component {
11931240
height: 100%;
11941241
overflow: auto;
11951242
box-sizing: border-box;
11961243
}
1244+
11971245
.typewriter .editor-component {
11981246
padding-top: calc(50vh - 136px);
11991247
padding-bottom: calc(50vh - 54px);
12001248
}
1249+
12011250
.image-viewer {
12021251
position: fixed;
12031252
backdrop-filter: blur(5px);
@@ -1222,10 +1271,12 @@ export default {
12221271
}
12231272
}
12241273
}
1274+
12251275
.iv-container {
12261276
width: 100%;
12271277
height: 100%;
12281278
}
1279+
12291280
.iv-snap-view {
12301281
opacity: 1;
12311282
bottom: 20px;

0 commit comments

Comments
 (0)