Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make bold and italic tags persist after block conversion (text type) #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/components/Block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,37 @@ function clearSearch (searchTermLength: number, openedWithSlash: boolean = false
// If openedWithSlash, searchTermLength = 0 but we still need to clear
if (searchTermLength < 1 && !openedWithSlash)
return
const pos = getCaretPosWithoutTags().pos
const startIdx = pos - searchTermLength - 1
const endIdx = pos

let pos:number, startIdx:number, endIdx:number;
let finalText:string, finalTextWithTags:string = '';
// Refers to current block type before change
if (isTextBlock(props.block.type)) {
pos = getCaretPos().pos;
// Subtract extra 3 for <p> in front
startIdx = pos - searchTermLength - 4;
endIdx = pos - 3;
const htmlContent = getHtmlContent();
finalTextWithTags = htmlContent.substring(0, startIdx) + htmlContent.substring(endIdx);
}
pos = getCaretPosWithoutTags().pos
startIdx = pos - searchTermLength - 1
endIdx = pos
const textContent = getTextContent()
finalText = textContent.substring(0, startIdx) + textContent.substring(endIdx)

setTimeout(() => {
const originalText = (content.value as any).$el.innerText
props.block.details.value = originalText.substring(0, startIdx) + originalText.substring(endIdx);
// Refers to block type after change
if (isTextBlock(props.block.type)) {
props.block.details.value = `<p>${originalText.substring(0, startIdx) + originalText.substring(endIdx)}</p>`
if (finalTextWithTags !== '') {
props.block.details.value = '<p>' + finalTextWithTags + '</p>'
} else {
// We came from a heading type, so use plain text
props.block.details.value = '<p>' + finalText + '</p>'
}
} else if (props.block.type === BlockType.Divider) {
props.block.details = {}
} else {
(content.value as any).$el.innerText = originalText.substring(0, startIdx) + originalText.substring(endIdx)
props.block.details.value = finalText
}
setTimeout(() => setCaretPos(startIdx))
})
Expand Down
11 changes: 10 additions & 1 deletion src/components/Lotion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ function deleteBlock (blockIdx: number) {
}

function setBlockType (blockIdx: number, type: BlockType) {
props.page.blocks[blockIdx].details.value = blockElements.value[blockIdx].getTextContent()
if (isTextBlock(props.page.blocks[blockIdx].type)) {
// If target is text or quote, keep <strong> and <em> tags, and add <p> tags
if (isTextBlock(type)) {
props.page.blocks[blockIdx].details.value = '<p>' + blockElements.value[blockIdx].getHtmlContent() + '</p>'
}
else {
// If not, we can just get the text content
props.page.blocks[blockIdx].details.value = blockElements.value[blockIdx].getTextContent()
}
}
props.page.blocks[blockIdx].type = type
if (type === BlockType.Divider) {
props.page.blocks[blockIdx].details = {}
Expand Down