mirror of
https://github.com/marktext/marktext.git
synced 2025-05-17 09:20:24 +08:00
fix: whole selection can not be canceled (#962)
* fix: whole selection can not be canceled * add null check in clickCtrl
This commit is contained in:
parent
413b3f92db
commit
c4664546bd
@ -156,7 +156,9 @@ const backspaceCtrl = ContentState => {
|
|||||||
// 2. select table from the first cell to the last cell, press backsapce.
|
// 2. select table from the first cell to the last cell, press backsapce.
|
||||||
if (/th/.test(startBlock.type) && start.offset === 0 && !startBlock.preSibling) {
|
if (/th/.test(startBlock.type) && start.offset === 0 && !startBlock.preSibling) {
|
||||||
if (
|
if (
|
||||||
end.offset === endBlock.text.length && startOutmostBlock === endOutmostBlock && !endBlock.nextSibling && !maybeLastRow.nextSibling ||
|
end.offset === endBlock.text.length &&
|
||||||
|
startOutmostBlock === endOutmostBlock &&
|
||||||
|
!endBlock.nextSibling && !maybeLastRow.nextSibling ||
|
||||||
startOutmostBlock !== endOutmostBlock
|
startOutmostBlock !== endOutmostBlock
|
||||||
) {
|
) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -107,19 +107,6 @@ const clickCtrl = ContentState => {
|
|||||||
eventCenter.dispatch('muya-format-picker', { reference, formats })
|
eventCenter.dispatch('muya-format-picker', { reference, formats })
|
||||||
}
|
}
|
||||||
|
|
||||||
// bugfix: figure block click
|
|
||||||
if (block.type === 'figure' && block.functionType === 'table') {
|
|
||||||
// first cell in thead
|
|
||||||
const cursorBlock = block.children[1].children[0].children[0].children[0]
|
|
||||||
const offset = cursorBlock.text.length
|
|
||||||
const key = cursorBlock.key
|
|
||||||
this.cursor = {
|
|
||||||
start: { key, offset },
|
|
||||||
end: { key, offset }
|
|
||||||
}
|
|
||||||
needRender = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// update '```xxx' to code block when you click other place or use press arrow key.
|
// update '```xxx' to code block when you click other place or use press arrow key.
|
||||||
if (block && start.key !== this.cursor.start.key) {
|
if (block && start.key !== this.cursor.start.key) {
|
||||||
const oldBlock = this.getBlock(this.cursor.start.key)
|
const oldBlock = this.getBlock(this.cursor.start.key)
|
||||||
@ -137,9 +124,22 @@ const clickCtrl = ContentState => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const needMarkedUpdate = this.checkNeedRender(this.cursor) || this.checkNeedRender({ start, end })
|
const needMarkedUpdate = this.checkNeedRender(this.cursor) || this.checkNeedRender({ start, end })
|
||||||
|
|
||||||
|
if (needRender) {
|
||||||
this.cursor = { start, end }
|
this.cursor = { start, end }
|
||||||
if (needMarkedUpdate || needRender) {
|
|
||||||
return this.partialRender()
|
return this.partialRender()
|
||||||
|
} else if (needMarkedUpdate) {
|
||||||
|
// Fix: whole select can not be canceled #613
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const cursor = selection.getCursorRange()
|
||||||
|
if (!cursor.start || !cursor.end) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cursor = cursor
|
||||||
|
return this.partialRender()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.cursor = { start, end }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user