Skip to content

Comments

add AdGuard syntax highlighting to custom filter rule editor#264

Merged
0xCUB3 merged 8 commits intomainfrom
feature/adguard-syntax-highlighting
Feb 23, 2026
Merged

add AdGuard syntax highlighting to custom filter rule editor#264
0xCUB3 merged 8 commits intomainfrom
feature/adguard-syntax-highlighting

Conversation

@0xCUB3
Copy link
Owner

@0xCUB3 0xCUB3 commented Feb 23, 2026

Syntax highlighting for the custom filter rule editor. Tokenizer handles all AdGuard rule types (comments, element hiding, URL blocking, exceptions, modifiers, extended CSS, scriptlets, HTML filtering, regex). Wired into EditUserListView on both macOS and iOS via native NSTextView/UITextView wrappers.

Closes #263

Test plan:

  • Open Edit User List, paste AdGuard rules, verify colors appear
  • Type rules character by character, confirm cursor doesn't jump
  • Check both macOS and iOS
  • Check light and dark mode contrast

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @0xCUB3, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience in the custom filter rule editor by integrating real-time AdGuard syntax highlighting. This visual aid improves the readability and maintainability of filter rules, making it easier for users to author and manage their custom AdGuard configurations on both macOS and iOS. The implementation leverages native text views for optimal performance and user interaction.

Highlights

  • Real-time AdGuard Syntax Highlighting: Introduced real-time AdGuard syntax highlighting to the custom filter rule editor (EditUserListView) for both macOS and iOS platforms.
  • New AdGuardSyntaxHighlighter: Developed a new AdGuardSyntaxHighlighter tokenizer capable of coloring various AdGuard rule components, including comments, element hiding rules, URL blocking, exceptions, modifiers, extended CSS, scriptlets, HTML filtering, and regex patterns.
  • New SyntaxHighlightingTextView: Created a SyntaxHighlightingTextView SwiftUI representable that wraps native NSTextView (macOS) and UITextView (iOS), providing highlighting, preserving cursor position during updates, and guarding against update loops.
Changelog
  • docs/plans/2026-02-23-adguard-syntax-highlighting-design.md
    • Added a detailed design document outlining the implementation plan for AdGuard syntax highlighting.
  • wBlock/AdGuardSyntaxHighlighter.swift
    • Introduced a new AdGuardSyntaxHighlighter struct responsible for tokenizing and applying syntax coloring to AdGuard filter rules.
    • Defined a Theme struct for platform-adaptive colors.
    • Implemented regex-based pattern matching for various AdGuard rule types (comments, exceptions, element hiding, URL blocking, modifiers, etc.).
    • Provided methods to highlight a given string and apply colors/fonts based on detected patterns.
  • wBlock/ContentView.swift
    • Replaced existing TextEditor instances in EditUserListView with the new SyntaxHighlightingTextView for both iOS and macOS targets.
    • Removed redundant font and background styling as these are now handled by SyntaxHighlightingTextView.
  • wBlock/SyntaxHighlightingTextView.swift
    • Created a new SwiftUI NSViewRepresentable (macOS) and UIViewRepresentable (iOS) to wrap native NSTextView and UITextView.
    • Integrated the AdGuardSyntaxHighlighter to apply real-time syntax highlighting.
    • Implemented logic to preserve the cursor position during text updates and re-highlighting.
    • Configured native text view properties for a monospaced font and disabled automatic text features.
Activity
  • A detailed implementation plan was created and followed, breaking down the feature into logical tasks.
  • The AdGuardSyntaxHighlighter tokenizer was developed and compiled.
  • The SyntaxHighlightingTextView representable was created and compiled for both macOS and iOS.
  • The new syntax highlighting view was integrated into EditUserListView for both platforms.
  • Platform-specific color API differences were addressed to ensure correct rendering on both macOS and iOS.
  • Manual testing was planned to verify correct syntax coloring for various rule types and to ensure cursor stability during typing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces AdGuard syntax highlighting to the custom filter rule editor on both macOS and iOS. The changes involve creating a new AdGuardSyntaxHighlighter class responsible for tokenizing and applying NSAttributedString colors to AdGuard rules using regular expressions, and a SyntaxHighlightingTextView SwiftUI representable that wraps native NSTextView/UITextView to display the highlighted text while preserving cursor position. The existing TextEditor in EditUserListView is replaced with this new custom view. A review comment highlights that the htmlFiltering color is defined using a magic number and suggests using a named constant or system color for better maintainability.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1df5f4515

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@0xCUB3
Copy link
Owner Author

0xCUB3 commented Feb 23, 2026

Fixed both in b233375.

Gemini: extracted the amber color to private static let amberColor on Theme. We use custom amber instead of systemYellow because yellow washes out on light backgrounds.

Codex: good catch. UITextView.selectedRange is in UTF-16 units but the bounds check compared against String.count (grapheme clusters). Fixed both spots to use (text as NSString).length.

The two comments on the design doc are about the plan file, not the actual code.

@0xCUB3 0xCUB3 merged commit 7a4c2f3 into main Feb 23, 2026
2 checks passed
@0xCUB3 0xCUB3 deleted the feature/adguard-syntax-highlighting branch February 23, 2026 15:27
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.

[Feature Request] Adguard Syntax Highlighter

1 participant