Skip to content

Fix insert contextlessly#4

Merged
ethantw merged 2 commits into
mainfrom
fix-insert-contextlessly
May 2, 2026
Merged

Fix insert contextlessly#4
ethantw merged 2 commits into
mainfrom
fix-insert-contextlessly

Conversation

@ethantw

@ethantw ethantw commented May 2, 2026

Copy link
Copy Markdown
Owner

Description

Fix insertContextlessly and its corresponding tests.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test addition or update

Testing

  • All existing tests pass
  • New tests added for new functionality
  • Manual testing completed

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

ethantw added 2 commits May 2, 2026 23:02
`Insert.purs:untilInsertable` walks the DOM looking for an "insertable"
position relative to a matched portion's text node, used by `Around
Outer` and the family of constructors that place brackets outside the
portion's parent. The walk uses sibling presence as the stop condition:
hit any non-ignored sibling and stop at the current node.

`Transformer.purs` injects an empty text-node placeholder for every
start/end portion (the `slice 0 indexInNode nodeText` result, which is
"" when the match starts at the beginning of its text node). In
contextful mode the default `ignore` predicate returns true for empty
text, so the walk transparently skips past these placeholders. In
contextless mode `ignore = const false` treats every node as real
content, so the walk stops at the placeholder — and `Around Outer`
brackets get trapped inside the original parent instead of reaching the
enclosing element boundary.

Fix: short-circuit the walk-up on `DOM.isEmptyTextNode` regardless of
the `ignore` predicate. Empty text nodes carry no user-visible content
and are commonly synthetic — treating them as transparent for walk-up
is a property of the DOM, not of the user's options. Contextful mode is
unaffected (the empty placeholders were already getting skipped via
`ignore`); contextless `Around Outer` now correctly pushes brackets to
the boundary, matching contextful behaviour for non-context elements.

The helper `DOM.isEmptyTextNode` already existed; one extra import line
plus a pre-check in the `Just sibling` branch.

Pre-existing tests all continue to pass (this commit alone — the test
additions exercising the new behaviour land in the next commit).
…vel inline elements

Two related upgrades to the contextless suite:

1. **Block-level fixtures replace the prior weak ones.** PS wrap/transform
   used `<p>ab</p><p>cd</p>` + `/a|b/` — a single-character regex matching
   per-context, which contextful would also fire. TS match/replace/transform/
   wrap used `<b>ab</b>c` + `/[a-z]{3}/` — `<b>` is inline, so contextful
   and contextless behave identically; the test wasn't proving anything
   contextless-specific. All replaced with `<p>a</p><p>b</p>` + `/ab/`,
   where contextful yields zero hits and contextless tree-flattening is
   the only thing that makes the regex fire.

2. **Text-level fixtures added in parallel.** `<a>a</a><b>b</b>` for each
   of the six operations. Inline elements aren't context boundaries so
   contextful and contextless behave identically — these cases pin parity:
   contextless mode doesn't introduce surprises for non-boundary elements,
   and the operations work cleanly when text-level wrappers are present.

`insertContextlessly` now has both `Around Inner` and `Around Outer` cases
across both block-level and text-level fixtures. Outer expected outputs
reflect the walk-up fix from the preceding commit: `[<p>a</p>|<p>b</p>]`
for block-level, `[<a>a</a>|<b>b</b>]` for text-level — brackets reach the
enclosing element boundary instead of being trapped by the placeholder.

Comment blocks in both files capture the Inner/Outer split (Inner places
brackets in the portion's text flow without walk-up; Outer reaches the
enclosing boundary by walking up past empty placeholders) so future
readers don't have to re-derive it from the source.

PS 85/85, JS 86/86.
@ethantw ethantw merged commit 6022837 into main May 2, 2026
1 check passed
@ethantw ethantw deleted the fix-insert-contextlessly branch May 2, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant