mirror of
https://github.com/marktext/marktext.git
synced 2025-05-04 14:40:45 +08:00
fix: Editor jumps to last cursor if you toggle a task-list item (#1911)
This commit is contained in:
parent
c8556c2785
commit
6a50b5cb69
@ -238,6 +238,14 @@ const clickCtrl = ContentState => {
|
|||||||
this.updateChildrenCheckBoxState(checkbox, checked)
|
this.updateChildrenCheckBoxState(checkbox, checked)
|
||||||
this.updateParentsCheckBoxState(checkbox)
|
this.updateParentsCheckBoxState(checkbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const block = this.getBlock(checkbox.id)
|
||||||
|
const parentBlock = this.getParent(block)
|
||||||
|
const firstEditableBlock = this.firstInDescendant(parentBlock)
|
||||||
|
const { key } = firstEditableBlock
|
||||||
|
const offset = 0
|
||||||
|
this.cursor = { start: { key, offset }, end: { key, offset } }
|
||||||
|
return this.partialRender()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
Search
|
Search
|
||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
markdown: String,
|
markdown: String,
|
||||||
cursor: Object,
|
cursor: Object,
|
||||||
@ -124,6 +125,7 @@ export default {
|
|||||||
},
|
},
|
||||||
platform: String
|
platform: String
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
preferences: state => state.preferences,
|
preferences: state => state.preferences,
|
||||||
@ -168,11 +170,13 @@ export default {
|
|||||||
sourceCode: state => state.preferences.sourceCode
|
sourceCode: state => state.preferences.sourceCode
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
this.defaultFontFamily = DEFAULT_EDITOR_FONT_FAMILY
|
this.defaultFontFamily = DEFAULT_EDITOR_FONT_FAMILY
|
||||||
this.CloseIcon = CloseIcon
|
this.CloseIcon = CloseIcon
|
||||||
// Helper to ignore changes when the spell check provider was changed in settings.
|
// Helper to ignore changes when the spell check provider was changed in settings.
|
||||||
this.spellcheckerIgnorChanges = false
|
this.spellcheckerIgnorChanges = false
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectionChange: null,
|
selectionChange: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
@ -186,27 +190,32 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
typewriter: function (value) {
|
typewriter: function (value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.scrollToCursor()
|
this.scrollToCursor()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
focus: function (value) {
|
focus: function (value) {
|
||||||
this.editor.setFocusMode(value)
|
this.editor.setFocusMode(value)
|
||||||
},
|
},
|
||||||
|
|
||||||
fontSize: function (value, oldValue) {
|
fontSize: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setFont({ fontSize: value })
|
editor.setFont({ fontSize: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
lineHeight: function (value, oldValue) {
|
lineHeight: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setFont({ lineHeight: value })
|
editor.setFont({ lineHeight: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
preferLooseListItem: function (value, oldValue) {
|
preferLooseListItem: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
@ -215,12 +224,14 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
tabSize: function (value, oldValue) {
|
tabSize: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setTabSize(value)
|
editor.setTabSize(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
theme: function (value, oldValue) {
|
theme: function (value, oldValue) {
|
||||||
if (value !== oldValue && this.editor) {
|
if (value !== oldValue && this.editor) {
|
||||||
// Agreement:Any black series theme needs to contain dark `word`.
|
// Agreement:Any black series theme needs to contain dark `word`.
|
||||||
@ -237,95 +248,111 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sequenceTheme: function (value, oldValue) {
|
sequenceTheme: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ sequenceTheme: value }, true)
|
editor.setOptions({ sequenceTheme: value }, true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
listIndentation: function (value, oldValue) {
|
listIndentation: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setListIndentation(value)
|
editor.setListIndentation(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
frontmatterType: function (value, oldValue) {
|
frontmatterType: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ frontmatterType: value })
|
editor.setOptions({ frontmatterType: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
superSubScript: function (value, oldValue) {
|
superSubScript: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ superSubScript: value }, true)
|
editor.setOptions({ superSubScript: value }, true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
footnote: function (value, oldValue) {
|
footnote: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ footnote: value }, true)
|
editor.setOptions({ footnote: value }, true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideQuickInsertHint: function (value, oldValue) {
|
hideQuickInsertHint: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ hideQuickInsertHint: value })
|
editor.setOptions({ hideQuickInsertHint: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
editorLineWidth: function (value, oldValue) {
|
editorLineWidth: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
setEditorWidth(value)
|
setEditorWidth(value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
autoPairBracket: function (value, oldValue) {
|
autoPairBracket: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ autoPairBracket: value })
|
editor.setOptions({ autoPairBracket: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
autoPairMarkdownSyntax: function (value, oldValue) {
|
autoPairMarkdownSyntax: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ autoPairMarkdownSyntax: value })
|
editor.setOptions({ autoPairMarkdownSyntax: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
autoPairQuote: function (value, oldValue) {
|
autoPairQuote: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ autoPairQuote: value })
|
editor.setOptions({ autoPairQuote: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
trimUnnecessaryCodeBlockEmptyLines: function (value, oldValue) {
|
trimUnnecessaryCodeBlockEmptyLines: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ trimUnnecessaryCodeBlockEmptyLines: value })
|
editor.setOptions({ trimUnnecessaryCodeBlockEmptyLines: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
bulletListMarker: function (value, oldValue) {
|
bulletListMarker: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ bulletListMarker: value })
|
editor.setOptions({ bulletListMarker: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
orderListDelimiter: function (value, oldValue) {
|
orderListDelimiter: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ orderListDelimiter: value })
|
editor.setOptions({ orderListDelimiter: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideLinkPopup: function (value, oldValue) {
|
hideLinkPopup: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ hideLinkPopup: value })
|
editor.setOptions({ hideLinkPopup: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
autoCheck: function (value, oldValue) {
|
autoCheck: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ autoCheck: value })
|
editor.setOptions({ autoCheck: value })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
codeFontSize: function (value, oldValue) {
|
codeFontSize: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
addCommonStyle({
|
addCommonStyle({
|
||||||
@ -335,12 +362,14 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
codeBlockLineNumbers: function (value, oldValue) {
|
codeBlockLineNumbers: function (value, oldValue) {
|
||||||
const { editor } = this
|
const { editor } = this
|
||||||
if (value !== oldValue && editor) {
|
if (value !== oldValue && editor) {
|
||||||
editor.setOptions({ codeBlockLineNumbers: value }, true)
|
editor.setOptions({ codeBlockLineNumbers: value }, true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
codeFontFamily: function (value, oldValue) {
|
codeFontFamily: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
addCommonStyle({
|
addCommonStyle({
|
||||||
@ -350,6 +379,7 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideScrollbar: function (value, oldValue) {
|
hideScrollbar: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
addCommonStyle({
|
addCommonStyle({
|
||||||
@ -359,6 +389,7 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spellcheckerEnabled: function (value, oldValue) {
|
spellcheckerEnabled: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
const { editor, spellchecker } = this
|
const { editor, spellchecker } = this
|
||||||
@ -383,6 +414,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spellcheckerIsHunspell: function (value, oldValue) {
|
spellcheckerIsHunspell: function (value, oldValue) {
|
||||||
// Special case when the OS supports multiple spell checker because the
|
// Special case when the OS supports multiple spell checker because the
|
||||||
// language may be invalid (provider 1 may support language xyz
|
// language may be invalid (provider 1 may support language xyz
|
||||||
@ -409,6 +441,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spellcheckerNoUnderline: function (value, oldValue) {
|
spellcheckerNoUnderline: function (value, oldValue) {
|
||||||
if (value !== oldValue) {
|
if (value !== oldValue) {
|
||||||
const { editor, spellchecker } = this
|
const { editor, spellchecker } = this
|
||||||
@ -422,6 +455,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spellcheckerAutoDetectLanguage: function (value, oldValue) {
|
spellcheckerAutoDetectLanguage: function (value, oldValue) {
|
||||||
const { spellchecker } = this
|
const { spellchecker } = this
|
||||||
const { isEnabled } = spellchecker
|
const { isEnabled } = spellchecker
|
||||||
@ -429,6 +463,7 @@ export default {
|
|||||||
spellchecker.automaticallyIdentifyLanguages = value
|
spellchecker.automaticallyIdentifyLanguages = value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
spellcheckerLanguage: function (value, oldValue) {
|
spellcheckerLanguage: function (value, oldValue) {
|
||||||
const { spellchecker, spellcheckerIgnorChanges } = this
|
const { spellchecker, spellcheckerIgnorChanges } = this
|
||||||
if (!spellcheckerIgnorChanges && value !== oldValue) {
|
if (!spellcheckerIgnorChanges && value !== oldValue) {
|
||||||
@ -443,6 +478,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
currentFile: function (value, oldValue) {
|
currentFile: function (value, oldValue) {
|
||||||
if (value && value !== oldValue) {
|
if (value && value !== oldValue) {
|
||||||
this.scrollToCursor(0)
|
this.scrollToCursor(0)
|
||||||
@ -450,12 +486,14 @@ export default {
|
|||||||
this.editor && this.editor.hideAllFloatTools()
|
this.editor && this.editor.hideAllFloatTools()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sourceCode: function (value, oldValue) {
|
sourceCode: function (value, oldValue) {
|
||||||
if (value && value !== oldValue) {
|
if (value && value !== oldValue) {
|
||||||
this.editor && this.editor.hideAllFloatTools()
|
this.editor && this.editor.hideAllFloatTools()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created () {
|
created () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.printer = new Printer()
|
this.printer = new Printer()
|
||||||
@ -693,10 +731,12 @@ export default {
|
|||||||
photoCreatorClick: (url) => {
|
photoCreatorClick: (url) => {
|
||||||
shell.openExternal(url)
|
shell.openExternal(url)
|
||||||
},
|
},
|
||||||
|
|
||||||
jumpClick (linkInfo) {
|
jumpClick (linkInfo) {
|
||||||
const { href } = linkInfo
|
const { href } = linkInfo
|
||||||
this.$store.dispatch('FORMAT_LINK_CLICK', { data: { href }, dirname: window.DIRNAME })
|
this.$store.dispatch('FORMAT_LINK_CLICK', { data: { href }, dirname: window.DIRNAME })
|
||||||
},
|
},
|
||||||
|
|
||||||
async imagePathAutoComplete (src) {
|
async imagePathAutoComplete (src) {
|
||||||
const files = await this.$store.dispatch('ASK_FOR_IMAGE_AUTO_PATH', src)
|
const files = await this.$store.dispatch('ASK_FOR_IMAGE_AUTO_PATH', src)
|
||||||
return files.map(f => {
|
return files.map(f => {
|
||||||
@ -704,6 +744,7 @@ export default {
|
|||||||
return Object.assign(f, { iconClass, text: f.file + (f.type === 'directory' ? '/' : '') })
|
return Object.assign(f, { iconClass, text: f.file + (f.type === 'directory' ? '/' : '') })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
async imageAction (image, id, alt = '') {
|
async imageAction (image, id, alt = '') {
|
||||||
const { imageInsertAction, imageFolderPath, preferences } = this
|
const { imageInsertAction, imageFolderPath, preferences } = this
|
||||||
const { pathname } = this.currentFile
|
const { pathname } = this.currentFile
|
||||||
@ -747,9 +788,11 @@ export default {
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
|
|
||||||
imagePathPicker () {
|
imagePathPicker () {
|
||||||
return this.$store.dispatch('ASK_FOR_IMAGE_PATH')
|
return this.$store.dispatch('ASK_FOR_IMAGE_PATH')
|
||||||
},
|
},
|
||||||
|
|
||||||
keyup (event) {
|
keyup (event) {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
this.setImageViewerVisible(false)
|
this.setImageViewerVisible(false)
|
||||||
@ -788,6 +831,7 @@ export default {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
enableSpellchecker () {
|
enableSpellchecker () {
|
||||||
const {
|
const {
|
||||||
spellchecker,
|
spellchecker,
|
||||||
@ -822,6 +866,7 @@ export default {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
switchSpellcheckLanguage (languageCode) {
|
switchSpellcheckLanguage (languageCode) {
|
||||||
const { spellchecker } = this
|
const { spellchecker } = this
|
||||||
const { isEnabled } = spellchecker
|
const { isEnabled } = spellchecker
|
||||||
@ -1182,6 +1227,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-wrapper.source {
|
.editor-wrapper.source {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
@ -1189,15 +1235,18 @@ export default {
|
|||||||
left: 0;
|
left: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-component {
|
.editor-component {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.typewriter .editor-component {
|
.typewriter .editor-component {
|
||||||
padding-top: calc(50vh - 136px);
|
padding-top: calc(50vh - 136px);
|
||||||
padding-bottom: calc(50vh - 54px);
|
padding-bottom: calc(50vh - 54px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-viewer {
|
.image-viewer {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
backdrop-filter: blur(5px);
|
backdrop-filter: blur(5px);
|
||||||
@ -1222,10 +1271,12 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.iv-container {
|
.iv-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.iv-snap-view {
|
.iv-snap-view {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
|
Loading…
Reference in New Issue
Block a user