update
This commit is contained in:
@@ -23,7 +23,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
const selectedClass = isSelected ? ' selected' : '';
|
||||
const placeholder = this.getPlaceholder();
|
||||
|
||||
console.log('HeadingBlockHandler.render:', { blockId: block.id, isSelected, content: block.content, level: this.level });
|
||||
|
||||
return `
|
||||
<div
|
||||
@@ -43,7 +42,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('HeadingBlockHandler.setup: Setting up heading block', { blockId: block.id, level: this.level });
|
||||
|
||||
// Set initial content if needed
|
||||
if (block.content && !headingBlock.innerHTML) {
|
||||
@@ -52,14 +50,12 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
|
||||
// Input handler with cursor tracking
|
||||
headingBlock.addEventListener('input', (e) => {
|
||||
console.log('HeadingBlockHandler: Input event', { blockId: block.id });
|
||||
handlers.onInput(e as InputEvent);
|
||||
|
||||
// Track cursor position after input
|
||||
const pos = this.getCursorPosition(element);
|
||||
if (pos !== null) {
|
||||
this.lastKnownCursorPosition = pos;
|
||||
console.log('HeadingBlockHandler: Updated cursor position after input', { pos });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,7 +65,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
const pos = this.getCursorPosition(element);
|
||||
if (pos !== null) {
|
||||
this.lastKnownCursorPosition = pos;
|
||||
console.log('HeadingBlockHandler: Cursor position before keydown', { pos, key: e.key });
|
||||
}
|
||||
|
||||
handlers.onKeyDown(e);
|
||||
@@ -77,24 +72,20 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
|
||||
// Focus handler
|
||||
headingBlock.addEventListener('focus', () => {
|
||||
console.log('HeadingBlockHandler: Focus event', { blockId: block.id });
|
||||
handlers.onFocus();
|
||||
});
|
||||
|
||||
// Blur handler
|
||||
headingBlock.addEventListener('blur', () => {
|
||||
console.log('HeadingBlockHandler: Blur event', { blockId: block.id });
|
||||
handlers.onBlur();
|
||||
});
|
||||
|
||||
// Composition handlers for IME support
|
||||
headingBlock.addEventListener('compositionstart', () => {
|
||||
console.log('HeadingBlockHandler: Composition start', { blockId: block.id });
|
||||
handlers.onCompositionStart();
|
||||
});
|
||||
|
||||
headingBlock.addEventListener('compositionend', () => {
|
||||
console.log('HeadingBlockHandler: Composition end', { blockId: block.id });
|
||||
handlers.onCompositionEnd();
|
||||
});
|
||||
|
||||
@@ -103,7 +94,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
const pos = this.getCursorPosition(element);
|
||||
if (pos !== null) {
|
||||
this.lastKnownCursorPosition = pos;
|
||||
console.log('HeadingBlockHandler: Cursor position after mouseup', { pos });
|
||||
}
|
||||
|
||||
// Selection will be handled by selectionchange event
|
||||
@@ -117,7 +107,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
const pos = this.getCursorPosition(element);
|
||||
if (pos !== null) {
|
||||
this.lastKnownCursorPosition = pos;
|
||||
console.log('HeadingBlockHandler: Cursor position after click', { pos });
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
@@ -127,7 +116,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
const pos = this.getCursorPosition(element);
|
||||
if (pos !== null) {
|
||||
this.lastKnownCursorPosition = pos;
|
||||
console.log('HeadingBlockHandler: Cursor position after keyup', { pos, key: e.key });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -178,11 +166,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
if (selectedText !== this.lastSelectedText) {
|
||||
this.lastSelectedText = selectedText;
|
||||
|
||||
console.log('HeadingBlockHandler: Text selected', {
|
||||
text: selectedText,
|
||||
blockId: block.id
|
||||
});
|
||||
|
||||
// Create range and get rect
|
||||
const range = WysiwygSelection.createRangeFromInfo(selectionInfo);
|
||||
const rect = range.getBoundingClientRect();
|
||||
@@ -302,7 +285,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
// Get the actual heading element
|
||||
const headingBlock = element.querySelector(`.block.heading-${this.level}`) as HTMLDivElement;
|
||||
if (!headingBlock) {
|
||||
console.log('HeadingBlockHandler.getCursorPosition: No heading element found');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -318,25 +300,12 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
if (blockShadowRoot) shadowRoots.push(blockShadowRoot);
|
||||
|
||||
const selectionInfo = WysiwygSelection.getSelectionInfo(...shadowRoots);
|
||||
console.log('HeadingBlockHandler.getCursorPosition: Selection info from shadow DOMs:', {
|
||||
selectionInfo,
|
||||
shadowRootsCount: shadowRoots.length
|
||||
});
|
||||
|
||||
if (!selectionInfo) {
|
||||
console.log('HeadingBlockHandler.getCursorPosition: No selection found');
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('HeadingBlockHandler.getCursorPosition: Range info:', {
|
||||
startContainer: selectionInfo.startContainer,
|
||||
startOffset: selectionInfo.startOffset,
|
||||
collapsed: selectionInfo.collapsed,
|
||||
startContainerText: selectionInfo.startContainer.textContent
|
||||
});
|
||||
|
||||
if (!WysiwygSelection.containsAcrossShadowDOM(headingBlock, selectionInfo.startContainer)) {
|
||||
console.log('HeadingBlockHandler.getCursorPosition: Range not in element');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -347,12 +316,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
|
||||
// Get the text content length up to cursor
|
||||
const position = preCaretRange.toString().length;
|
||||
console.log('HeadingBlockHandler.getCursorPosition: Calculated position:', {
|
||||
position,
|
||||
preCaretText: preCaretRange.toString(),
|
||||
elementText: headingBlock.textContent,
|
||||
elementTextLength: headingBlock.textContent?.length
|
||||
});
|
||||
|
||||
return position;
|
||||
}
|
||||
@@ -363,7 +326,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
|
||||
// For headings, get the innerHTML which includes formatting tags
|
||||
const content = headingBlock.innerHTML || '';
|
||||
console.log('HeadingBlockHandler.getContent:', content);
|
||||
return content;
|
||||
}
|
||||
|
||||
@@ -482,20 +444,11 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
}
|
||||
|
||||
getSplitContent(element: HTMLElement, context?: any): { before: string; after: string } | null {
|
||||
console.log('HeadingBlockHandler.getSplitContent: Starting...');
|
||||
|
||||
const headingBlock = element.querySelector(`.block.heading-${this.level}`) as HTMLDivElement;
|
||||
if (!headingBlock) {
|
||||
console.log('HeadingBlockHandler.getSplitContent: No heading element found');
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('HeadingBlockHandler.getSplitContent: Element info:', {
|
||||
innerHTML: headingBlock.innerHTML,
|
||||
textContent: headingBlock.textContent,
|
||||
textLength: headingBlock.textContent?.length
|
||||
});
|
||||
|
||||
// Get shadow roots from context
|
||||
const wysiwygBlock = context?.component;
|
||||
const parentComponent = wysiwygBlock?.closest('dees-input-wysiwyg');
|
||||
@@ -508,23 +461,12 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
if (blockShadowRoot) shadowRoots.push(blockShadowRoot);
|
||||
|
||||
const selectionInfo = WysiwygSelection.getSelectionInfo(...shadowRoots);
|
||||
console.log('HeadingBlockHandler.getSplitContent: Selection info from shadow DOMs:', {
|
||||
selectionInfo,
|
||||
shadowRootsCount: shadowRoots.length
|
||||
});
|
||||
|
||||
if (!selectionInfo) {
|
||||
console.log('HeadingBlockHandler.getSplitContent: No selection, using last known position:', this.lastKnownCursorPosition);
|
||||
// Try using last known cursor position
|
||||
if (this.lastKnownCursorPosition !== null) {
|
||||
const fullText = headingBlock.textContent || '';
|
||||
const pos = Math.min(this.lastKnownCursorPosition, fullText.length);
|
||||
console.log('HeadingBlockHandler.getSplitContent: Splitting with last known position:', {
|
||||
pos,
|
||||
fullTextLength: fullText.length,
|
||||
before: fullText.substring(0, pos),
|
||||
after: fullText.substring(pos)
|
||||
});
|
||||
return {
|
||||
before: fullText.substring(0, pos),
|
||||
after: fullText.substring(pos)
|
||||
@@ -533,15 +475,8 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('HeadingBlockHandler.getSplitContent: Selection range:', {
|
||||
startContainer: selectionInfo.startContainer,
|
||||
startOffset: selectionInfo.startOffset,
|
||||
startContainerInElement: headingBlock.contains(selectionInfo.startContainer)
|
||||
});
|
||||
|
||||
// Make sure the selection is within this block
|
||||
if (!WysiwygSelection.containsAcrossShadowDOM(headingBlock, selectionInfo.startContainer)) {
|
||||
console.log('HeadingBlockHandler.getSplitContent: Selection not in this block, using last known position:', this.lastKnownCursorPosition);
|
||||
// Try using last known cursor position
|
||||
if (this.lastKnownCursorPosition !== null) {
|
||||
const fullText = headingBlock.textContent || '';
|
||||
@@ -556,11 +491,9 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
|
||||
// Get cursor position first
|
||||
const cursorPos = this.getCursorPosition(element, context);
|
||||
console.log('HeadingBlockHandler.getSplitContent: Cursor position for HTML split:', cursorPos);
|
||||
|
||||
if (cursorPos === null || cursorPos === 0) {
|
||||
// If cursor is at start or can't determine position, move all content
|
||||
console.log('HeadingBlockHandler.getSplitContent: Cursor at start or null, moving all content');
|
||||
return {
|
||||
before: '',
|
||||
after: headingBlock.innerHTML
|
||||
@@ -592,16 +525,6 @@ export class HeadingBlockHandler extends BaseBlockHandler {
|
||||
tempDiv.appendChild(afterFragment);
|
||||
const afterHtml = tempDiv.innerHTML;
|
||||
|
||||
console.log('HeadingBlockHandler.getSplitContent: Final split result:', {
|
||||
cursorPos,
|
||||
beforeHtml,
|
||||
beforeLength: beforeHtml.length,
|
||||
beforeHtmlPreview: beforeHtml.substring(0, 100) + (beforeHtml.length > 100 ? '...' : ''),
|
||||
afterHtml,
|
||||
afterLength: afterHtml.length,
|
||||
afterHtmlPreview: afterHtml.substring(0, 100) + (afterHtml.length > 100 ? '...' : '')
|
||||
});
|
||||
|
||||
return {
|
||||
before: beforeHtml,
|
||||
after: afterHtml
|
||||
|
Reference in New Issue
Block a user