Skip to content

Syntax Highlighting: JavaScript (Regular expression literal) #1185

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

Open
Lessica opened this issue Jun 4, 2021 · 5 comments
Open

Syntax Highlighting: JavaScript (Regular expression literal) #1185

Lessica opened this issue Jun 4, 2021 · 5 comments
Labels
better to fix unwanted behaviors not critical but better to fix syntax highlight issues related to syntax highlighting

Comments

@Lessica
Copy link

Lessica commented Jun 4, 2021

Regular expression literal are not properly rendered. If quotes " are included in a regex literal, all syntax highlights after that will fail.

Creating a regular expression

You construct a regular expression in one of two ways:

  • Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:
let re = /ab+c/;

Regular expression literals provide compilation of the regular expression when the script is loaded. If the regular expression remains constant, using this can improve performance.

  • Or calling the constructor function of the RegExp object, as follows:
let re = new RegExp('ab+c');

Using the constructor function provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.

Referenced from: Regular expressions - JavaScript | MDN

@Lessica
Copy link
Author

Lessica commented Jun 4, 2021

Screenshots

截屏2021-06-05 上午12 24 46

@1024jp 1024jp self-assigned this Jun 5, 2021
@1024jp 1024jp added the better to fix unwanted behaviors not critical but better to fix label Jun 5, 2021
@1024jp 1024jp added this to the 4.0.5 milestone Jun 5, 2021
@1024jp 1024jp closed this as completed in 7b1bbfa Jun 5, 2021
@1024jp
Copy link
Member

1024jp commented Jun 5, 2021

Thank you for the feedback.
I update the JavaScript syntax style definition to solve this issue.
The change will be shipped with the next version.

@JJHackimoto
Copy link

I believe this fix caused new issues when using forward slash as dividing operator or when using two forward slashes to comment. See included screenshots.
Skärmavbild 2021-06-11 kl  11 41 51
Skärmavbild 2021-06-11 kl  11 39 28

@1024jp 1024jp reopened this Jun 11, 2021
@1024jp 1024jp modified the milestones: 4.0.5, 4.0.6 Jun 11, 2021
@1024jp
Copy link
Member

1024jp commented Jun 16, 2021

Thank you for the report and sorry for the enbug.
I close this issue just because it is the same as issue #1187.
I'll fix it anyway in the next version.

@1024jp 1024jp closed this as completed Jun 16, 2021
1024jp added a commit that referenced this issue Jun 20, 2021
@1024jp 1024jp reopened this Jun 20, 2021
@1024jp 1024jp removed this from the 4.0.6 milestone Jun 20, 2021
@1024jp 1024jp removed their assignment Jun 20, 2021
@1024jp
Copy link
Member

1024jp commented Jun 20, 2021

Regrettably, I need to say I reopen this issue because the JavaScript syntax highlight definition will be restored in the next version to solve the further issue, which was reported by @JJHackimoto and in #1187.

I understand the current issue on the regex literal in CotEditor's JavaScript definition. However, by studying the source code, I realize this is the limit of the current syntax highlight mechanism in CotEditor, which is simple but originally designed aiming that users can modify it easily in GUI.

To solve this issue, I need to redesign CotEditor's syntax highlight system and definition format drastically. In other words, it takes time.

Sorry for that. I actually know for years I need to update this highlighting system and put in my to-do list, but not decided yet when I'll set about this task.

@1024jp 1024jp added the syntax highlight issues related to syntax highlighting label Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better to fix unwanted behaviors not critical but better to fix syntax highlight issues related to syntax highlighting
Development

No branches or pull requests

3 participants