-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The plugin's current matching and replacement logic processes rules sequentially, which can cause issues when multiple rules have overlapping search patterns. This can lead to unpredictable text corruption and an unreliable user experience.
Symptoms
When a portion of the text is a valid match for more than one rule, the following problems can occur:
- Unexpected Output: The final text does not match what the user would expect. One rule's transformation may be applied, but a subsequent rule might then alter the already-modified text in an unintended way.
- Text Corruption: Text can become mangled or nonsensical, especially with rules that apply formatting or complex string manipulation.
- UI Instability: Rapid, sequential replacements can cause flickering or slow down the editor, as the UI attempts to re-render changes from multiple, competing rules.
Steps to Reproduce
- Create a rule (e.g.,
boldify) with the pattern(word). The replacement code isreturn **${occurrence.original}**. - Create a second rule (e.g.,
italicize) with the pattern(a word). The replacement code isreturn *${occurrence.original}*. - Type the phrase "this is a word" in the editor.
Expected behavior: The user expects the phrase to become bold or italicized based on rule priority, or perhaps a more complex combined format if the rules are designed for it.
Actual behavior: The text becomes this is a **word** (from the first rule), and then the second rule runs on the newly formatted text, causing an unpredictable result.
Proposed Solution
The core problem lies in the sequential application of replacements. A robust solution would involve a single-pass approach where all matches are identified first, and then a strategy is applied to resolve any overlaps before the changes are committed to the editor.
This could involve:
- Match Prioritization: Give rules a priority level, so only the highest-priority match is applied.
- Non-Overlapping Match Selection: Filter the list of matches to ensure no two matches overlap. This would prevent two rules from trying to change the same piece of text.
- Combined Transformations: A more complex solution would be to allow certain rules to combine their transformations, though this requires a more sophisticated rule definition system.