Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection of a "Begin String" phrase or "End String" phrase for syntax highlighting does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase #1686

Open
KSXia opened this issue Aug 28, 2024 · 2 comments
Labels
potential bug issues not yet tested rejected rejected requests

Comments

@KSXia
Copy link

KSXia commented Aug 28, 2024

Description

Start with a syntax highlighting rule similar to the following screenshot. For this demonstration, I will create the syntax highlighting rule in the String category, but this bug appears to occur regardless of the syntax highlighting category the syntax highlighting rule is created in. The syntax highlighting rule should have the Regular Expression option disabled, have a phrase set for the Begin String option, and have a phrase set for the End String option. I'll refer to the phrase set for the Begin String option as the Beginning Phrase and the phrase set for the End String option as the Ending Phrase.

The Beginning Phrase and Ending Phrase can either be a single character or a set of multiple characters. For this demonstration, I will set the Beginning Phrase to ab and Ending Phrase to xyz, but this bug appears to occur with any characters, including symbols and numbers. While I will set the Beginning Phrase and Ending Phrase to be different in this demonstration, this bug will still occur if the Beginning Phrase and Ending Phrase are the same.

For this demonstration, I will disable the Ignore Case option, but this bug still occurs when the Ignore Case option is enabled.

For this demonstration, I have set the Syntax Kind to Code, but this bug seems to still occur when the Syntax Kind is set to General.
image

If I type the Starting Phrase and Ending Phrase and add a \ before the Ending Phrase, the syntax highlighting seems not to detect the Ending Phrase, so there is no syntax highlighting. (In all of the screenshots, I have added some text after the string and in the next line after the string to show whether the syntax highlighting continues beyond the string, but this bug still occurs without these texts.)
image

If the \ is instead added before the Starting Phrase, a similar situation occurs in which there will be no syntax highlighting.
image

Normally, if I type the Ending Phrase twice, the syntax highlighting will end after the first instance of the Ending Phrase.
image

However, if there is a \ before the first instance of the Ending Phrase, that first instance of the Ending Phrase seems to be ignored, and the syntax highlighting will instead end after the second instance of the Ending Pharse.
image

This behavior also occurs if there is text between the Starting Phrase and the first instance of the Ending Phrase.
image

This behavior also occurs if there is text between the first and second instance of the Ending Phrase.
image

The syntax highlighting will also continue across lines.
image

Normally, if there are multiple instances of the Starting Phrase before the Ending Phrase, the syntax highlighting starts from the first instance of the Starting Phrase.
image

However, if a \ is added before the first instance of the Starting Phrase, that first instance of the Starting Pharse seems to be ignored, and the syntax highlighting will instead start from the second instance of the Starting Phrase.
image

To Reproduce

  1. Go to settings and create a new syntax. I'll refer to this new syntax as Demonstration Syntax.
  2. In any highlighting category, create a new highlighting rule. I will use the string highlighting rule, but this bug seems to occur with all of the highlighting categories.
  3. Ensure the Regular Expression option is disabled for this new highlighting rule.
  4. I disabled the Ignore Case option, but this bug still seems to occur when the Ignore Case option is enabled.
  5. Add a character or multiple characters in the Begin String option. I added the ab character, but this bug seems to occur with any singular character or set of multiple characters added to the Begin String option.
  6. Add a character or multiple characters in the End String option. I added the xyz character, but this bug seems to occur with any singular character or set of multiple characters added to the End String option.
  7. Create a new file.
  8. Set the syntax to Demonstration Syntax.
  9. Type in the phrase you set to the Begin String option.
  10. Type in the phrase you set to the End String option.
  11. Type in a \ before the phrase you set to the 'End String' option. (If you used the same settings for the Begin String and End String option as me, you should have typed in ab\xyz).
  12. You should be able to observe the bug now: the text you just typed in will not be highlighted.
  13. At the end of the text you already typed in, type in the phrase you set to the End String option. (If you used the same settings for the Begin String and End String option as me, you should have typed in ab\xyzxyz).
  14. Observe how the highlighting does not end at the first instance of the phrase you set to the End String option.
  15. Delete all of the text you have typed in.
  16. Type in the phrase you set to the Begin String option.
  17. Type in the phrase you set to the End String option.
  18. Type in a \ before the phrase you set to the 'Begin String' option. (If you used the same settings for the Begin String and End String option as me, you should have typed in \abxyz).
  19. Observe how the text you just typed in will not be highlighted.
  20. Right after the Begin String phrase you have typed in, type in the phrase you set to the Begin String option. (If you used the same settings for the Begin String and End String option as me, you should have typed in \ababxyz).
  21. Observe how the highlighting does not start at the first instance of the phrase you set to the Begin String option.

Expected behavior

The expected behavior is described in the description.

CotEditor version

4.8.7 (657)

macOS version

14.5

Additional context

I initially discovered this bug when writing strings that ended in a \.

@KSXia KSXia added the potential bug issues not yet tested label Aug 28, 2024
@KSXia KSXia changed the title Detection of Syntax Highlighting with a "Begin String" phrase and "End String" phrase does not work when there is a \ in front of the "Begin String" phrase or "End String" phrase Detection of Syntax Highlighting with a "Begin String" phrase and "End String" phrase does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase Aug 28, 2024
@KSXia KSXia changed the title Detection of Syntax Highlighting with a "Begin String" phrase and "End String" phrase does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase Detection of a "Begin String" phrase or "End String" phrase for Syntax Highlighting does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase Aug 28, 2024
@KSXia KSXia changed the title Detection of a "Begin String" phrase or "End String" phrase for Syntax Highlighting does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase Detection of a "Begin String" phrase or "End String" phrase for syntax highlighting does not work when there is a backslash in front of the "Begin String" phrase or "End String" phrase Aug 28, 2024
@1024jp
Copy link
Member

1024jp commented Sep 2, 2024

This behavior is by design.

@1024jp 1024jp added the rejected rejected requests label Sep 2, 2024
@KSXia
Copy link
Author

KSXia commented Sep 3, 2024

May I ask what the reasoning for this behavior is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential bug issues not yet tested rejected rejected requests
Development

No branches or pull requests

2 participants