Skip to content

Added custom callback to transform a link before it is launched#2727

Open
Alspb wants to merge 3 commits into
singerdmx:masterfrom
Alspb:link_improvements
Open

Added custom callback to transform a link before it is launched#2727
Alspb wants to merge 3 commits into
singerdmx:masterfrom
Alspb:link_improvements

Conversation

@Alspb
Copy link
Copy Markdown
Collaborator

@Alspb Alspb commented May 5, 2026

Description

Added a transformLink callback to QuillEditorConfig that lets callers control how a link
is transformed before it is launched. This is used when tapping links within the editor.

Previously, the editor unconditionally prepended https:// to any link that didn't match a
known scheme. This is too rigid — it breaks workflows that rely on scheme-less links such as
local file paths.

When transformLink is null, the existing behavior is preserved, so this is a non-breaking
change.

Type of Change

  • Feature: New functionality without breaking existing features.
  • 🛠️ Bug fix: Resolves an issue without altering current behavior.
  • 🧹 Refactor: Code reorganization, no behavior change.
  • Breaking: Alters existing functionality and requires updates.
  • 🧪 Tests: New or modified tests
  • 📝 Documentation: Updates or additions to documentation.
  • 🗑️ Chore: Routine tasks, or maintenance.
  • Build configuration change: Build/configuration changes.

Copilot AI review requested due to automatic review settings May 5, 2026 07:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new editor configuration callback to allow callers to transform/normalize a link string immediately before it is launched from a tap inside the editor, enabling custom schemes or alternative prefixing logic.

Changes:

  • Added transformLink to QuillEditorConfig and QuillRawEditorConfig and wired it through QuillEditorQuillRawEditor → text widgets.
  • Updated link-tap handling in TextLine to apply transformLink (or fall back to the existing default https:// prefixing behavior).
  • Added widget tests verifying both custom transformation behavior and default prefix behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/editor/editor_test.dart Adds widget tests covering transformLink override and default https:// prefixing.
lib/src/editor/widgets/text/text_line.dart Applies transformLink (or default transform) before calling the URL launcher callback.
lib/src/editor/widgets/text/text_block.dart Plumbs transformLink through block rendering to TextLine.
lib/src/editor/raw_editor/raw_editor_state.dart Forwards transformLink from raw editor config into text widgets.
lib/src/editor/raw_editor/config/raw_editor_config.dart Introduces transformLink API on raw editor config with documentation.
lib/src/editor/editor.dart Wires QuillEditorConfig.transformLink into QuillRawEditorConfig.
lib/src/editor/config/editor_config.dart Introduces transformLink API on editor config + copyWith support and documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +692 to 696
final transformLink = widget.transformLink ?? _transformLink;
link = transformLink(link);

// TODO(EchoEllet): Refactor onLaunchUrl or add a new API to give full control of the launch? See https://github.com/singerdmx/flutter-quill/issues/1776
final launchUrl = widget.onLaunchUrl ?? _launchUrl;
launchUrl(link);
Comment on lines +433 to +438
/// Callback to transform a link before it is launched on tap in the editor.
///
/// Receives the trimmed link string and returns the final URL to launch.
/// When not set (`null`), the link is validated against known prefixes and
/// `https://` is prepended if no recognized prefix is found.
final String Function(String link)? transformLink;
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.

2 participants