mirror of
https://github.com/marktext/marktext.git
synced 2025-05-04 03:32:36 +08:00
Bugfix: #55
This commit is contained in:
parent
98280ab0d9
commit
d0fe613135
2
.github/TODOLIST.md
vendored
2
.github/TODOLIST.md
vendored
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
- [ ] Left click menu.
|
- [ ] Left click menu.
|
||||||
|
|
||||||
- [ ] Rename and moveTo in **File Menu**
|
- [x] Rename and moveTo in **File Menu**
|
||||||
|
|
||||||
- [x] Preference in **Mark Text** Menu
|
- [x] Preference in **Mark Text** Menu
|
||||||
|
|
||||||
|
@ -18,13 +18,16 @@ import './assets/symbolIcon/index.css'
|
|||||||
|
|
||||||
class Aganippe {
|
class Aganippe {
|
||||||
constructor (container, options) {
|
constructor (container, options) {
|
||||||
|
const { focusMode = false, theme = 'light', markdown = '' } = options
|
||||||
this.container = container
|
this.container = container
|
||||||
const eventCenter = this.eventCenter = new EventCenter()
|
const eventCenter = this.eventCenter = new EventCenter()
|
||||||
const floatBox = this.floatBox = new FloatBox(eventCenter)
|
const floatBox = this.floatBox = new FloatBox(eventCenter)
|
||||||
const tablePicker = this.tablePicker = new TablePicker(eventCenter)
|
const tablePicker = this.tablePicker = new TablePicker(eventCenter)
|
||||||
this.contentState = new ContentState(eventCenter, floatBox, tablePicker)
|
this.contentState = new ContentState(eventCenter, floatBox, tablePicker)
|
||||||
this.emoji = new Emoji() // emoji instance: has search(text) clear() methods.
|
this.emoji = new Emoji() // emoji instance: has search(text) clear() methods.
|
||||||
this.focusMode = false
|
this.focusMode = focusMode
|
||||||
|
this.theme = theme
|
||||||
|
this.markdown = markdown
|
||||||
// private property
|
// private property
|
||||||
this._isEditChinese = false
|
this._isEditChinese = false
|
||||||
this.init()
|
this.init()
|
||||||
@ -64,6 +67,11 @@ class Aganippe {
|
|||||||
this.dispatchCopyCut()
|
this.dispatchCopyCut()
|
||||||
this.dispatchTableToolBar()
|
this.dispatchTableToolBar()
|
||||||
this.dispatchCodeBlockClick()
|
this.dispatchCodeBlockClick()
|
||||||
|
|
||||||
|
const { theme, focusMode, markdown } = this
|
||||||
|
this.setTheme(theme)
|
||||||
|
this.setMarkdown(markdown)
|
||||||
|
this.setFocusMode(focusMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,7 +402,7 @@ class Aganippe {
|
|||||||
return this.contentState.getCodeMirrorCursor()
|
return this.contentState.getCodeMirrorCursor()
|
||||||
}
|
}
|
||||||
|
|
||||||
setMarkdown (markdown, cursor) {
|
setMarkdown (markdown, cursor, renderCursor = true) {
|
||||||
// if markdown is blank, dont need to import markdown
|
// if markdown is blank, dont need to import markdown
|
||||||
if (!markdown.trim()) return
|
if (!markdown.trim()) return
|
||||||
let newMarkdown = markdown
|
let newMarkdown = markdown
|
||||||
@ -403,7 +411,7 @@ class Aganippe {
|
|||||||
}
|
}
|
||||||
this.contentState.importMarkdown(newMarkdown)
|
this.contentState.importMarkdown(newMarkdown)
|
||||||
this.contentState.importCursor(cursor)
|
this.contentState.importCursor(cursor)
|
||||||
this.contentState.render()
|
this.contentState.render(renderCursor)
|
||||||
this.dispatchChange()
|
this.dispatchChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,11 +437,13 @@ class Aganippe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTheme (name) {
|
setTheme (name) {
|
||||||
|
if (!name) return
|
||||||
if (name === 'dark') {
|
if (name === 'dark') {
|
||||||
codeMirrorConfig.theme = 'railscasts'
|
codeMirrorConfig.theme = 'railscasts'
|
||||||
} else {
|
} else {
|
||||||
delete codeMirrorConfig.theme
|
delete codeMirrorConfig.theme
|
||||||
}
|
}
|
||||||
|
this.theme = name
|
||||||
this.contentState.render()
|
this.contentState.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,6 @@ export const EXTENSION_HASN = {
|
|||||||
pdf: '.pdf'
|
pdf: '.pdf'
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const DEFAULT_THEME = 'dark'
|
|
||||||
|
|
||||||
export const VIEW_MENU_ITEM = {
|
export const VIEW_MENU_ITEM = {
|
||||||
'Source Code Mode': false,
|
'Source Code Mode': false,
|
||||||
'Typewriter Mode': false,
|
'Typewriter Mode': false,
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
:source-code="sourceCode"
|
:source-code="sourceCode"
|
||||||
:markdown="markdown"
|
:markdown="markdown"
|
||||||
:cursor="cursor"
|
:cursor="cursor"
|
||||||
v-if="!sourceCode"
|
|
||||||
:theme="theme"
|
:theme="theme"
|
||||||
:dark-color="darkColor"
|
:dark-color="darkColor"
|
||||||
:light-color="lightColor"
|
:light-color="lightColor"
|
||||||
@ -23,7 +22,7 @@
|
|||||||
:font-size="fontSize"
|
:font-size="fontSize"
|
||||||
></editor>
|
></editor>
|
||||||
<source-code
|
<source-code
|
||||||
v-else
|
v-if="sourceCode"
|
||||||
:markdown="markdown"
|
:markdown="markdown"
|
||||||
:cursor="cursor"
|
:cursor="cursor"
|
||||||
:theme="theme"
|
:theme="theme"
|
||||||
|
@ -83,9 +83,12 @@
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
theme: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
markdown: String,
|
markdown: String,
|
||||||
cursor: Object,
|
cursor: Object,
|
||||||
theme: String,
|
|
||||||
lineHeight: [Number, String],
|
lineHeight: [Number, String],
|
||||||
fontSize: [Number, String],
|
fontSize: [Number, String],
|
||||||
lightColor: String,
|
lightColor: String,
|
||||||
@ -124,23 +127,17 @@
|
|||||||
created () {
|
created () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const ele = this.$refs.editor
|
const ele = this.$refs.editor
|
||||||
this.editor = new Aganippe(ele)
|
const { theme, focus: focusMode, markdown, typewriter } = this
|
||||||
const { container } = this.editor
|
const { container } = this.editor = new Aganippe(ele, { theme, focusMode, markdown })
|
||||||
const { markdown, theme } = this
|
|
||||||
// init set markdown and edit mode(typewriter mode and focus mode)
|
if (typewriter) {
|
||||||
if (markdown.trim()) {
|
|
||||||
this.setMarkdownToEditor(markdown)
|
|
||||||
if (this.typewriter) {
|
|
||||||
this.scrollToCursor()
|
this.scrollToCursor()
|
||||||
}
|
}
|
||||||
this.editor.setFocusMode(this.focus)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (theme) {
|
// the default theme is light write in the store
|
||||||
this.editor.setTheme(theme)
|
|
||||||
this.addThemeStyle(theme)
|
this.addThemeStyle(theme)
|
||||||
}
|
|
||||||
|
|
||||||
|
// listen for bus events.
|
||||||
bus.$on('file-loaded', this.setMarkdownToEditor)
|
bus.$on('file-loaded', this.setMarkdownToEditor)
|
||||||
bus.$on('undo', this.handleUndo)
|
bus.$on('undo', this.handleUndo)
|
||||||
bus.$on('redo', this.handleRedo)
|
bus.$on('redo', this.handleRedo)
|
||||||
@ -151,6 +148,7 @@
|
|||||||
bus.$on('replaceValue', this.handReplace)
|
bus.$on('replaceValue', this.handReplace)
|
||||||
bus.$on('find', this.handleFind)
|
bus.$on('find', this.handleFind)
|
||||||
bus.$on('insert-image', this.handleSelect)
|
bus.$on('insert-image', this.handleSelect)
|
||||||
|
bus.$on('content-in-source-mode', this.handleMarkdownChange)
|
||||||
|
|
||||||
this.editor.on('change', (markdown, wordCount, cursor) => {
|
this.editor.on('change', (markdown, wordCount, cursor) => {
|
||||||
this.$store.dispatch('SAVE_FILE', { markdown, wordCount, cursor })
|
this.$store.dispatch('SAVE_FILE', { markdown, wordCount, cursor })
|
||||||
@ -186,30 +184,36 @@
|
|||||||
}
|
}
|
||||||
link.href = href
|
link.href = href
|
||||||
},
|
},
|
||||||
|
|
||||||
handleUndo () {
|
handleUndo () {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
this.editor.undo()
|
this.editor.undo()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleRedo () {
|
handleRedo () {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
this.editor.redo()
|
this.editor.redo()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSelect (url) {
|
handleSelect (url) {
|
||||||
if (!this.sourceCode) {
|
if (!this.sourceCode) {
|
||||||
this.editor && this.editor.insertImage(url)
|
this.editor && this.editor.insertImage(url)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSearch (value, opt) {
|
handleSearch (value, opt) {
|
||||||
const searchMatches = this.editor.search(value, opt)
|
const searchMatches = this.editor.search(value, opt)
|
||||||
this.$store.dispatch('SEARCH', searchMatches)
|
this.$store.dispatch('SEARCH', searchMatches)
|
||||||
this.scrollToHighlight()
|
this.scrollToHighlight()
|
||||||
},
|
},
|
||||||
|
|
||||||
handReplace (value, opt) {
|
handReplace (value, opt) {
|
||||||
const searchMatches = this.editor.replace(value, opt)
|
const searchMatches = this.editor.replace(value, opt)
|
||||||
this.$store.dispatch('SEARCH', searchMatches)
|
this.$store.dispatch('SEARCH', searchMatches)
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollToCursor () {
|
scrollToCursor () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const { container } = this.editor
|
const { container } = this.editor
|
||||||
@ -217,6 +221,7 @@
|
|||||||
animatedScrollTo(container, container.scrollTop + y - STANDAR_Y, 300)
|
animatedScrollTo(container, container.scrollTop + y - STANDAR_Y, 300)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollToHighlight () {
|
scrollToHighlight () {
|
||||||
// Scroll to search highlight word
|
// Scroll to search highlight word
|
||||||
const { container } = this.editor
|
const { container } = this.editor
|
||||||
@ -227,11 +232,13 @@
|
|||||||
animatedScrollTo(container, container.scrollTop + y - STANDAR_Y, DURATION)
|
animatedScrollTo(container, container.scrollTop + y - STANDAR_Y, DURATION)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleFind (action) {
|
handleFind (action) {
|
||||||
const searchMatches = this.editor.find(action)
|
const searchMatches = this.editor.find(action)
|
||||||
this.$store.dispatch('SEARCH', searchMatches)
|
this.$store.dispatch('SEARCH', searchMatches)
|
||||||
this.scrollToHighlight()
|
this.scrollToHighlight()
|
||||||
},
|
},
|
||||||
|
|
||||||
async handleExport (type) {
|
async handleExport (type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'styledHtml': {
|
case 'styledHtml': {
|
||||||
@ -252,6 +259,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleEditParagraph (type) {
|
handleEditParagraph (type) {
|
||||||
if (type === 'table') {
|
if (type === 'table') {
|
||||||
this.tableChecker = { rows: 4, columns: 3 }
|
this.tableChecker = { rows: 4, columns: 3 }
|
||||||
@ -263,18 +271,28 @@
|
|||||||
this.editor && this.editor.updateParagraph(type)
|
this.editor && this.editor.updateParagraph(type)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleInlineFormat (type) {
|
handleInlineFormat (type) {
|
||||||
this.editor && this.editor.format(type)
|
this.editor && this.editor.format(type)
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDialogTableConfirm () {
|
handleDialogTableConfirm () {
|
||||||
this.dialogTableVisible = false
|
this.dialogTableVisible = false
|
||||||
this.editor && this.editor.createTable(this.tableChecker)
|
this.editor && this.editor.createTable(this.tableChecker)
|
||||||
},
|
},
|
||||||
|
|
||||||
setMarkdownToEditor (markdown) {
|
setMarkdownToEditor (markdown) {
|
||||||
const { cursor } = this
|
const { cursor } = this
|
||||||
this.editor && this.editor.setMarkdown(markdown, cursor)
|
this.editor && this.editor.setMarkdown(markdown, cursor)
|
||||||
|
},
|
||||||
|
|
||||||
|
// listen for markdown change form source mode
|
||||||
|
handleMarkdownChange ({ markdown, cursor, renderCursor }) {
|
||||||
|
console.log(markdown, cursor)
|
||||||
|
this.editor && this.editor.setMarkdown(markdown, cursor, renderCursor)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
bus.$off('file-loaded', this.setMarkdownToEditor)
|
bus.$off('file-loaded', this.setMarkdownToEditor)
|
||||||
bus.$off('undo', this.handleUndo)
|
bus.$off('undo', this.handleUndo)
|
||||||
@ -294,7 +312,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* @import '../../editor/themes/dark.css';*/
|
|
||||||
@import '../../editor/index.css';
|
@import '../../editor/index.css';
|
||||||
.editor-wrapper {
|
.editor-wrapper {
|
||||||
height: calc(100vh - 22px);
|
height: calc(100vh - 22px);
|
||||||
@ -302,8 +319,7 @@
|
|||||||
.editor-wrapper.source {
|
.editor-wrapper.source {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
left: -10000px;
|
width: 100%;
|
||||||
opacity: 0;
|
|
||||||
}
|
}
|
||||||
.editor-component {
|
.editor-component {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -67,6 +67,9 @@
|
|||||||
bus.$on('font-setting', this.handleFontSetting)
|
bus.$on('font-setting', this.handleFontSetting)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
bus.$off('font-setting', this.handleFontSetting)
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleFontSetting () {
|
handleFontSetting () {
|
||||||
this.showFontSetting = true
|
this.showFontSetting = true
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import codeMirror, { setMode, setCursorAtLastLine } from '../../editor/codeMirror'
|
import codeMirror, { setMode, setCursorAtLastLine } from '../../editor/codeMirror'
|
||||||
import ContentState from '../../editor/contentState'
|
|
||||||
import bus from '../bus'
|
import bus from '../bus'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -41,7 +40,6 @@
|
|||||||
created () {
|
created () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const { markdown = '', theme } = this
|
const { markdown = '', theme } = this
|
||||||
this.contentState = new ContentState()
|
|
||||||
const container = this.$refs.sourceCode
|
const container = this.$refs.sourceCode
|
||||||
const codeMirrorConfig = {
|
const codeMirrorConfig = {
|
||||||
value: '',
|
value: '',
|
||||||
@ -67,9 +65,11 @@
|
|||||||
this.setMarkdown(markdown)
|
this.setMarkdown(markdown)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
beforeDestory () {
|
beforeDestroy () {
|
||||||
bus.$off('file-loaded', this.setMarkdown)
|
bus.$off('file-loaded', this.setMarkdown)
|
||||||
bus.$off('dotu-select', this.handleSelectDoutu)
|
bus.$off('dotu-select', this.handleSelectDoutu)
|
||||||
|
const { markdown, cursor } = this
|
||||||
|
bus.$emit('content-in-source-mode', { markdown, cursor, renderCursor: true })
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleSelectDoutu (url) {
|
handleSelectDoutu (url) {
|
||||||
@ -83,10 +83,7 @@
|
|||||||
editor.on('cursorActivity', (cm, event) => {
|
editor.on('cursorActivity', (cm, event) => {
|
||||||
const cursor = cm.getCursor()
|
const cursor = cm.getCursor()
|
||||||
const markdown = cm.getValue()
|
const markdown = cm.getValue()
|
||||||
// get word count
|
bus.$emit('content-in-source-mode', { markdown, cursor, renderCursor: false })
|
||||||
this.contentState.importMarkdown(markdown, cursor)
|
|
||||||
const wordCount = this.contentState.wordCount()
|
|
||||||
this.$store.dispatch('SAVE_FILE', { markdown, cursor, wordCount })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
setMode(editor, 'markdown')
|
setMode(editor, 'markdown')
|
||||||
|
@ -5,9 +5,18 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
@media print {
|
@media print {
|
||||||
|
html, body {
|
||||||
|
background: #fff !important;
|
||||||
|
}
|
||||||
body .editor-component {
|
body .editor-component {
|
||||||
height: auto !important;
|
height: auto !important;
|
||||||
}
|
}
|
||||||
|
body .editor-wrapper {
|
||||||
|
z-index: 1 !important;
|
||||||
|
}
|
||||||
|
body .source-code {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
body .editor-component #ag-editor-id,
|
body .editor-component #ag-editor-id,
|
||||||
body [contenteditable] {
|
body [contenteditable] {
|
||||||
caret-color: transparent !important;
|
caret-color: transparent !important;
|
||||||
|
@ -11,7 +11,7 @@ const state = {
|
|||||||
value: ''
|
value: ''
|
||||||
},
|
},
|
||||||
// user preference
|
// user preference
|
||||||
theme: '',
|
theme: 'light',
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
lineHeight: 1.6,
|
lineHeight: 1.6,
|
||||||
lightColor: '#303133', // color in light theme
|
lightColor: '#303133', // color in light theme
|
||||||
|
Loading…
Reference in New Issue
Block a user