mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
fix: 粘贴和拖拽插入文本时,保留换行
This commit is contained in:
parent
1501203a39
commit
7428cac662
@ -3,6 +3,7 @@ import { MutationTypes, useStore } from '@/store'
|
||||
import { decrypt } from '@/utils/crypto'
|
||||
import { PPTElement, Slide } from '@/types/slides'
|
||||
import { createRandomCode } from '@/utils/common'
|
||||
import { parseText2Paragraphs } from '@/utils/textParser'
|
||||
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
||||
import useCreateElement from '@/hooks/useCreateElement'
|
||||
|
||||
@ -103,7 +104,10 @@ export default () => {
|
||||
}
|
||||
|
||||
// 普通文本
|
||||
else if (!onlyElements && !onlySlide) pasteText(clipboardData)
|
||||
else if (!onlyElements && !onlySlide) {
|
||||
const string = parseText2Paragraphs(clipboardData)
|
||||
pasteText(string)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
9
src/utils/textParser.ts
Normal file
9
src/utils/textParser.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export const parseText2Paragraphs = (text: string) => {
|
||||
const htmlText = text.replace(/[\n\r]+/g, '<br>')
|
||||
const paragraphs = htmlText.split('<br>')
|
||||
let string = ''
|
||||
for (const paragraph of paragraphs) {
|
||||
if (paragraph) string += `<div>${paragraph}</div>`
|
||||
}
|
||||
return string
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { computed, onMounted, onUnmounted, Ref } from 'vue'
|
||||
import { useStore } from '@/store'
|
||||
import { getImageDataURL } from '@/utils/image'
|
||||
import { parseText2Paragraphs } from '@/utils/textParser'
|
||||
import useCreateElement from '@/hooks/useCreateElement'
|
||||
|
||||
export default (elementRef: Ref<HTMLElement | undefined>) => {
|
||||
@ -24,12 +25,13 @@ export default (elementRef: Ref<HTMLElement | undefined>) => {
|
||||
else if (dataTransferItem.kind === 'string' && dataTransferItem.type === 'text/plain') {
|
||||
dataTransferItem.getAsString(text => {
|
||||
if (disableHotkeys.value) return
|
||||
const string = parseText2Paragraphs(text)
|
||||
createTextElement({
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: 600,
|
||||
height: 50,
|
||||
}, text)
|
||||
}, string)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user