Skip to content

Commit

Permalink
fix: incorrect merge
Browse files Browse the repository at this point in the history
  • Loading branch information
BearToCode committed Feb 16, 2024
1 parent e3023a8 commit b6954a4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/core/src/lib/internal/editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@ export function mergeComponent(data: {
return;
}

const wrapper = correspondingComponentElem.parentElement;
if (!wrapper) {
const correspondingWrapper = correspondingComponentElem.parentElement;
if (!correspondingWrapper) {
if (dev) console.error('Failed to merge component: parent element is null');
return;
}

const textarea = wrapper.parentElement?.querySelector('textarea');
const textarea = correspondingWrapper.parentElement?.querySelector('textarea');
if (!textarea) {
if (dev) console.error('Failed to merge component: failed to find textarea');
return;
}

const {
prevLines: prevLines,
compLines: sourceLines,
nextLines: nextLines
} = getContentAroundComponent(wrapper, data.source);
const { prevLines, nextLines } = getContentAroundComponent(
correspondingWrapper,
correspondingComponent
);

const sourceLines = getLinesFromElem(sourceElem as HTMLDivElement);

textarea.value = Array.prototype.concat(prevLines, sourceLines, nextLines).join('\n');

Expand Down

0 comments on commit b6954a4

Please sign in to comment.