mirror of
https://github.com/marktext/marktext.git
synced 2025-05-04 03:32:36 +08:00
feat: enable paragraph menu and disable paragraph menu
This commit is contained in:
parent
0f5d5c4734
commit
e6fcdda5e0
@ -12,6 +12,7 @@ import historyCtrl from './historyCtrl'
|
|||||||
import arrowCtrl from './arrowCtrl'
|
import arrowCtrl from './arrowCtrl'
|
||||||
import pasteCtrl from './pasteCtrl'
|
import pasteCtrl from './pasteCtrl'
|
||||||
import copyCutCtrl from './copyCutCtrl'
|
import copyCutCtrl from './copyCutCtrl'
|
||||||
|
import paragraphCtrl from './paragraphCtrl'
|
||||||
import importMarkdown from '../utils/importMarkdown'
|
import importMarkdown from '../utils/importMarkdown'
|
||||||
|
|
||||||
const prototypes = [
|
const prototypes = [
|
||||||
@ -25,6 +26,7 @@ const prototypes = [
|
|||||||
pasteCtrl,
|
pasteCtrl,
|
||||||
copyCutCtrl,
|
copyCutCtrl,
|
||||||
tableBlockCtrl,
|
tableBlockCtrl,
|
||||||
|
paragraphCtrl,
|
||||||
importMarkdown
|
importMarkdown
|
||||||
]
|
]
|
||||||
|
|
||||||
|
12
src/editor/contentState/paragraphCtrl.js
Normal file
12
src/editor/contentState/paragraphCtrl.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import selection from '../selection'
|
||||||
|
|
||||||
|
const paragraphCtrl = ContentState => {
|
||||||
|
ContentState.prototype.selectionChange = function () {
|
||||||
|
const { start, end } = selection.getCursorRange()
|
||||||
|
start.type = this.getBlock(start.key).type
|
||||||
|
end.type = this.getBlock(end.key).type
|
||||||
|
return { start, end }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default paragraphCtrl
|
@ -297,6 +297,10 @@ class Aganippe {
|
|||||||
if (!this._isEditChinese || event.type === 'input') {
|
if (!this._isEditChinese || event.type === 'input') {
|
||||||
this.contentState.updateState(event)
|
this.contentState.updateState(event)
|
||||||
}
|
}
|
||||||
|
if (event.type === 'click' || event.type === 'keyup') {
|
||||||
|
const selectionChanges = this.contentState.selectionChange()
|
||||||
|
eventCenter.dispatch('selectionChange', selectionChanges)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventCenter.attachDOMEvent(container, 'click', changeHandler)
|
eventCenter.attachDOMEvent(container, 'click', changeHandler)
|
||||||
|
@ -1,3 +1,36 @@
|
|||||||
|
import { Menu, ipcMain } from 'electron'
|
||||||
|
|
||||||
|
const getParagraph = () => {
|
||||||
|
const menus = Menu.getApplicationMenu()
|
||||||
|
return menus.items.filter(menu => menu.label === 'Paragraph')[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
const allCtrl = bool => {
|
||||||
|
const paragraphMenuItem = getParagraph()
|
||||||
|
paragraphMenuItem.submenu.items.forEach(item => (item.enabled = bool))
|
||||||
|
}
|
||||||
|
|
||||||
|
const disableNoMultiple = () => {
|
||||||
|
const paragraphMenuItem = getParagraph()
|
||||||
|
const disableLabels = [
|
||||||
|
'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5', 'Heading 6',
|
||||||
|
'Upgrade Heading Level', 'Degrade Heading Level',
|
||||||
|
'Table'
|
||||||
|
]
|
||||||
|
paragraphMenuItem.submenu.items
|
||||||
|
.filter(item => disableLabels.includes(item.label))
|
||||||
|
.forEach(item => (item.enabled = false))
|
||||||
|
}
|
||||||
|
|
||||||
export const paragraph = (win, type) => {
|
export const paragraph = (win, type) => {
|
||||||
win.webContents.send('AGANI::paragraph', { type })
|
win.webContents.send('AGANI::paragraph', { type })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcMain.on('AGANI::selection-change', (e, { start, end }) => {
|
||||||
|
allCtrl(true)
|
||||||
|
if (/th|td/.test(start.type) || /th|td/.test(end.type)) {
|
||||||
|
allCtrl(false)
|
||||||
|
} else if (start.key !== end.key) {
|
||||||
|
disableNoMultiple()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
title="Insert Table"
|
title="Insert Table"
|
||||||
:visible.sync="dialogTableVisible"
|
:visible.sync="dialogTableVisible"
|
||||||
:show-close="isShowClose"
|
:show-close="isShowClose"
|
||||||
|
:modal="false"
|
||||||
|
custom-class="ag-dialog-table"
|
||||||
width="450px"
|
width="450px"
|
||||||
>
|
>
|
||||||
<el-form :model="tableChecker" :inline="true">
|
<el-form :model="tableChecker" :inline="true">
|
||||||
@ -64,6 +66,9 @@
|
|||||||
this.editor.on('change', (markdown, wordCount) => {
|
this.editor.on('change', (markdown, wordCount) => {
|
||||||
this.$store.dispatch('SAVE_FILE', { markdown, wordCount })
|
this.$store.dispatch('SAVE_FILE', { markdown, wordCount })
|
||||||
})
|
})
|
||||||
|
this.editor.on('selectionChange', changes => {
|
||||||
|
this.$store.dispatch('SELECTION_CHANGE', changes)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -107,11 +112,14 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style>
|
||||||
@import '../../editor/themes/github.css';
|
@import '../../editor/themes/github.css';
|
||||||
@import '../../editor/index.css';
|
@import '../../editor/index.css';
|
||||||
.editor-component {
|
.editor-component {
|
||||||
height: calc(100vh - 22px);
|
height: calc(100vh - 22px);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
.ag-dialog-table {
|
||||||
|
background: rgb(239, 239, 239);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -101,6 +101,10 @@ const actions = {
|
|||||||
commit('SET_STATUS', false)
|
commit('SET_STATUS', false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
SELECTION_CHANGE ({ commit }, changes) {
|
||||||
|
console.log(changes)
|
||||||
|
ipcRenderer.send('AGANI::selection-change', changes)
|
||||||
|
},
|
||||||
LISTEN_FOR_EXPORT ({ commit }) {
|
LISTEN_FOR_EXPORT ({ commit }) {
|
||||||
ipcRenderer.on('AGANI::export', (e, { type }) => {
|
ipcRenderer.on('AGANI::export', (e, { type }) => {
|
||||||
bus.$emit('export', type)
|
bus.$emit('export', type)
|
||||||
|
Loading…
Reference in New Issue
Block a user