implement image upload
This commit is contained in:
@ -114,14 +114,11 @@ export class WysiwygFormatting {
|
||||
|
||||
// Check if ANY part of the selection contains this formatting
|
||||
const hasFormatting = this.selectionContainsTag(range, tagName);
|
||||
console.log(`Formatting check for <${tagName}>: ${hasFormatting ? 'HAS formatting' : 'NO formatting'}`);
|
||||
|
||||
if (hasFormatting) {
|
||||
console.log(`Removing <${tagName}> formatting from selection`);
|
||||
// Remove all instances of this tag from the selection
|
||||
this.removeTagFromSelection(range, tagName);
|
||||
} else {
|
||||
console.log(`Adding <${tagName}> formatting to selection`);
|
||||
// Wrap selection with the tag
|
||||
const wrapper = document.createElement(tagName);
|
||||
try {
|
||||
@ -144,18 +141,13 @@ export class WysiwygFormatting {
|
||||
* Check if the selection contains or is within any instances of a tag
|
||||
*/
|
||||
private static selectionContainsTag(range: Range, tagName: string): boolean {
|
||||
console.log(`Checking if selection contains <${tagName}>...`);
|
||||
|
||||
// First check: Are we inside a tag? (even if selection doesn't include the tag)
|
||||
let node: Node | null = range.startContainer;
|
||||
console.log('Start container:', range.startContainer, 'type:', range.startContainer.nodeType);
|
||||
|
||||
while (node && node !== range.commonAncestorContainer.ownerDocument) {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = node as Element;
|
||||
console.log(` Checking parent element: <${element.tagName.toLowerCase()}>`);
|
||||
if (element.tagName.toLowerCase() === tagName) {
|
||||
console.log(` ✓ Found <${tagName}> as parent of start container`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -164,14 +156,11 @@ export class WysiwygFormatting {
|
||||
|
||||
// Also check the end container
|
||||
node = range.endContainer;
|
||||
console.log('End container:', range.endContainer, 'type:', range.endContainer.nodeType);
|
||||
|
||||
while (node && node !== range.commonAncestorContainer.ownerDocument) {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = node as Element;
|
||||
console.log(` Checking parent element: <${element.tagName.toLowerCase()}>`);
|
||||
if (element.tagName.toLowerCase() === tagName) {
|
||||
console.log(` ✓ Found <${tagName}> as parent of end container`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -183,7 +172,6 @@ export class WysiwygFormatting {
|
||||
const contents = range.cloneContents();
|
||||
tempDiv.appendChild(contents);
|
||||
const tags = tempDiv.getElementsByTagName(tagName);
|
||||
console.log(` Selection contains ${tags.length} complete <${tagName}> tags`);
|
||||
|
||||
return tags.length > 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user