Fix insert contextlessly#4
Merged
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix
insertContextlesslyand its corresponding tests.Type of Change
Testing
Checklist
Additional Notes