Skip to content

fix(format): strip same-type inner formatting when toggling on visual selection#166

Merged
YousefHadder merged 4 commits intomainfrom
fix/strip-inner-formatting-on-toggle
Dec 21, 2025
Merged

fix(format): strip same-type inner formatting when toggling on visual selection#166
YousefHadder merged 4 commits intomainfrom
fix/strip-inner-formatting-on-toggle

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

@YousefHadder YousefHadder commented Dec 21, 2025

Summary

  • When visually selecting text that contains existing formatting of the same type being toggled, the inner formatting is now stripped before wrapping the selection
  • This matches the behavior of Obsidian and Typora

Before: hello **world** + select all + toggle bold → **hello **world****

After: hello **world** + select all + toggle bold → **hello world**

Closes #165

Testing

  • Tested manually
  • Added/updated tests (if applicable)

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex logic
  • Updated documentation (if needed)
  • No new warnings generated

Copilot AI review requested due to automatic review settings December 21, 2025 18:20
Copy link
Copy Markdown
Contributor

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

This PR fixes issue #165 by implementing Obsidian/Typora-like behavior when toggling formatting on visual selections that contain existing same-type formatting. When applying bold to "hello world", the plugin now strips the inner bold markers before wrapping, resulting in "hello world" instead of "hello world".

Key Changes

  • Added contains_formatting() function to detect formatting anywhere within text (not just wrapping)
  • Added strip_format_type() function to remove all instances of a specific format type while preserving other formatting
  • Modified toggle_format() to strip same-type inner formatting before wrapping selections

Reviewed changes

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

File Description
lua/markdown-plus/format/init.lua Implements two new helper functions (contains_formatting and strip_format_type) and modifies toggle_format to strip same-type formatting before wrapping visual selections
spec/markdown-plus/format_spec.lua Adds comprehensive test coverage for the new helper functions and integration tests verifying the new toggle behavior with various format types

Copilot AI review requested due to automatic review settings December 21, 2025 18:51
Copy link
Copy Markdown
Contributor

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

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

@YousefHadder YousefHadder merged commit 8bee4c4 into main Dec 21, 2025
15 checks passed
@YousefHadder YousefHadder deleted the fix/strip-inner-formatting-on-toggle branch December 21, 2025 19:04
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] Clear same type of existing formats in the visual region if exists

2 participants