修复文字高度同步的bug

This commit is contained in:
pipipi-pikachu 2021-01-21 19:57:14 +08:00
parent a0f7732d22
commit 96e811d502
2 changed files with 22 additions and 6 deletions

View File

@ -378,14 +378,15 @@ export default (
document.onmouseup = e => { document.onmouseup = e => {
isMouseDown = false isMouseDown = false
emitter.emit(EmitterEvents.SCALE_ELEMENT_STATE, false)
document.onmousemove = null document.onmousemove = null
document.onmouseup = null document.onmouseup = null
alignmentLines.value = [] alignmentLines.value = []
if(startPageX === e.pageX && startPageY === e.pageY) return if(startPageX === e.pageX && startPageY === e.pageY) return
store.commit(MutationTypes.UPDATE_SLIDE, { elements: elementList.value }) store.commit(MutationTypes.UPDATE_SLIDE, { elements: elementList.value })
emitter.emit(EmitterEvents.SCALE_ELEMENT_STATE, false)
addHistorySnapshot() addHistorySnapshot()
} }
} }

View File

@ -85,9 +85,23 @@ export default defineComponent({
const elementRef = ref<HTMLElement | null>(null) const elementRef = ref<HTMLElement | null>(null)
const isScaling = ref(false) const isScaling = ref(false)
const realHeightCache = ref(-1)
emitter.on(EmitterEvents.SCALE_ELEMENT_STATE, state => { const scaleElementStateListener = (state: boolean) => {
isScaling.value = state isScaling.value = state
if(!state && realHeightCache.value !== -1) {
store.commit(MutationTypes.UPDATE_ELEMENT, {
id: props.elementInfo.id,
props: { height: realHeightCache.value },
})
realHeightCache.value = -1
}
}
emitter.on(EmitterEvents.SCALE_ELEMENT_STATE, state => scaleElementStateListener(state))
onUnmounted(() => {
emitter.off(EmitterEvents.SCALE_ELEMENT_STATE, state => scaleElementStateListener(state))
}) })
const updateTextElementHeight = (entries: ResizeObserverEntry[]) => { const updateTextElementHeight = (entries: ResizeObserverEntry[]) => {
@ -96,13 +110,14 @@ export default defineComponent({
const realHeight = contentRect.height const realHeight = contentRect.height
if(!isScaling.value) { if(props.elementInfo.height !== realHeight) {
if(props.elementInfo.height !== realHeight) { if(!isScaling.value) {
store.commit(MutationTypes.UPDATE_ELEMENT, { store.commit(MutationTypes.UPDATE_ELEMENT, {
id: props.elementInfo.id, id: props.elementInfo.id,
props: { height: realHeight }, props: { height: realHeight },
}) })
} }
else realHeightCache.value = realHeight
} }
} }
const resizeObserver = new ResizeObserver(updateTextElementHeight) const resizeObserver = new ResizeObserver(updateTextElementHeight)