Skip to content

Commit

Permalink
api: add mergeText arg for insertAfter/Before
Browse files Browse the repository at this point in the history
  • Loading branch information
sailist committed Feb 9, 2025
1 parent effed62 commit f783e31
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,11 @@ export class AnchorQuery implements AnchorQueryInterface, QueryCallback {
throw new Error('Method not implemented.');
}

_insertBefore(src: Node, target: Element): ContainerType {
_insertBefore(src: Node, target: Element, mergeText = true): ContainerType {
const parent = target.parentNode;
const prev = this._getNeighborSibling({ container: target, step: { direction: 'left', stride: 'char' } });

if (src instanceof Text && prev instanceof Text) {
if (src instanceof Text && prev instanceof Text && mergeText) {
prev.textContent = (prev.textContent || "") + (src.textContent || "");
src.remove();
return prev;
Expand All @@ -911,11 +911,11 @@ export class AnchorQuery implements AnchorQueryInterface, QueryCallback {
return src;
}

_insertAfter(src: Node, target: Element): ContainerType {
_insertAfter(src: Node, target: Element, mergeText = true): ContainerType {
const parent = target.parentNode;
const next = this._getNeighborSibling({ container: target, step: { direction: 'right', stride: 'char' } });

if (src instanceof Text && next instanceof Text) {
if (src instanceof Text && next instanceof Text && mergeText) {
next.textContent = (src.textContent || "") + (next.textContent || "");
src.remove();
return next;
Expand Down

0 comments on commit f783e31

Please sign in to comment.