Skip to content

Add case-sensitive and whole-word toggles to find-in-page #13

Description

@webtools-dotcom

Find-in-page works but always matches case-insensitively, with no way to change it. Ctrl+F in any other browser has these toggles.

Where the code is

The matching happens in an injected script, not in Rust. src-tauri/src/commands/browser/scripts/chrome_features.js defines window.__zynlexFind(query), which calls a findAll(query) helper and highlights the results.

The Rust side is a thin wrapper. src-tauri/src/commands/browser/find.rs has browser_find, browser_find_next and browser_stop_find, and they just build a JS call as a string and evaluate it.

The UI is src/components/browser/FindBar.tsx.

What needs doing

  1. Add two toggle buttons to FindBar.tsx. Aa for case sensitivity, and something for whole word.
  2. Thread the two booleans through browser_find in find.rs. Note that the JS call is built by string formatting, so the query already goes through js_string_literal for escaping. Keep using it.
  3. Update findAll in chrome_features.js to respect both flags. Whole-word matching usually means a regex with \b boundaries, but be careful escaping the user query before putting it in a regex, it is arbitrary input.
  4. Re-run the search when either toggle changes so results update immediately.

Worth knowing

  • The existing highlight logic wraps matches with range.surroundContents(mark). It is already inside a try/catch because that call throws when a range crosses element boundaries. Do not remove that.
  • The result count reported back to the UI needs to stay correct after filtering.
  • Keep the toggles keyboard-reachable, Ctrl+F users tend not to touch the mouse.

Reasonable first issue if you want to touch a bit of Rust and a bit of frontend without needing to understand the WebView2 COM layer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions