Skip to content

Preserve sibling elements in settings search

Mark Florian requested to merge 350494-fix-link-removal-in-settings-search into master

What does this MR do and why?

Preserves sibling elements in settings search.

Before, any elements that were siblings of matching text nodes got destroyed, replaced with their normalised textContent. That is, given this DOM:

<p>
  Foo <i>bar</i> qux.
</p>

If you searched for foo, then the above would be transformed into something like:

<p>
  <mark>Foo</mark> bar qux.
</p>

<!-- But the correct DOM would be: -->
<p>
  <mark>Foo</mark> <i>bar</i> qux.
</p>

And then if you cleared the search, it would become:

<p>
  Foo bar qux.
</p>

<!-- But the correct DOM would be the same as before the search: -->
<p>
  Foo <i>bar</i> qux.
</p>

The crux of the problem was that the highlighting algorithm wasn't the inverse of the highlight clearing algorithm. Now, it is, and only text nodes are modified. Matching text nodes are split into non-matching text nodes and mark elements containing the matched search text, and that collection of nodes replaces the original text node.

Addresses #350494 (closed).

Screenshots or screen recordings

Before After
before after

How to set up and validate locally

  1. Visit a project's settings page, e.g., http://gdk.test:3000/gitlab-org/gitlab-test/edit.
  2. Search for ensure.
  3. Observe that the Learn more link is now just plain text.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mark Florian

Merge request reports