* fix: #813

* add one more para of exportHtml.generate

* remove debug codes
This commit is contained in:
Ran Luo 2019-06-16 21:38:14 +08:00 committed by Felix Häusler
parent 165e8985b0
commit 47da3bd193
4 changed files with 26 additions and 6 deletions

View File

@ -25,11 +25,29 @@ class ClickEvent {
if (!start || !end) { if (!start || !end) {
return return
} }
const startBlock = contentState.getBlock(start.key)
const nextTextBlock = contentState.findNextBlockInLocation(startBlock)
// Commit native cursor position because right-clicking doesn't update the cursor postion. if (
contentState.cursor = { nextTextBlock && nextTextBlock.key === end.key &&
start, end.offset === 0 &&
end start.offset === startBlock.text.length
) {
// Set cursor at the end of start block and reset cursor
// Because if you right click at the end of one text block, the cursor.start will at the end of
// start block and the cursor.end will at the next text block beginning. So we reset the cursor
// at the end of start block.
contentState.cursor = {
start,
end: start
}
selection.setCursorRange(contentState.cursor)
} else {
// Commit native cursor position because right-clicking doesn't update the cursor postion.
contentState.cursor = {
start,
end
}
} }
const sectionChanges = contentState.selectionChange(contentState.cursor) const sectionChanges = contentState.selectionChange(contentState.cursor)

View File

@ -15,6 +15,7 @@ class DragDrop {
eventCenter.attachDOMEvent(container, 'dragover', dragoverHandler) eventCenter.attachDOMEvent(container, 'dragover', dragoverHandler)
} }
dropBinding () { dropBinding () {
const { container, eventCenter, contentState } = this.muya const { container, eventCenter, contentState } = this.muya

View File

@ -161,7 +161,7 @@ class ExportHtml {
* @param {*} title Page title * @param {*} title Page title
* @param {*} printOptimization Optimize HTML and CSS for printing * @param {*} printOptimization Optimize HTML and CSS for printing
*/ */
async generate (title = '', printOptimization = false) { async generate (title = '', printOptimization = false, extraCss = '') {
// WORKAROUND: Hide Prism.js style when exporting or printing. Otherwise the background color is white in the dark theme. // WORKAROUND: Hide Prism.js style when exporting or printing. Otherwise the background color is white in the dark theme.
const highlightCssStyle = printOptimization ? `@media print { ${highlightCss} }` : highlightCss const highlightCssStyle = printOptimization ? `@media print { ${highlightCss} }` : highlightCss
const html = await this.renderHtml() const html = await this.renderHtml()
@ -208,6 +208,7 @@ class ExportHtml {
} }
} }
</style> </style>
<style>${extraCss}</style>
</head> </head>
<body> <body>
<article class="markdown-body"> <article class="markdown-body">

View File

@ -36,7 +36,7 @@ export const showContextMenu = (event, { start, end }) => {
) )
} }
[CUT, COPY, COPY_AS_HTML, COPY_AS_MARKDOWN].forEach(item => { ;[CUT, COPY, COPY_AS_HTML, COPY_AS_MARKDOWN].forEach(item => {
item.enabled = !disableCutAndCopy item.enabled = !disableCutAndCopy
}) })