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

feat: Add CodeMirror editor to control panel #1656

Conversation

sum117
Copy link
Contributor

@sum117 sum117 commented May 29, 2024

Code Mirror Editor for Control Panel

image

This PR adds CodeMirror to YAGPDB bot, by implementing the unused vendor package CodeMirror. There are style inconsistencies, but an admin told me it was alright, as users wouldn't care. I included a CSS file of a theme that I like, downloaded from their website directly. It should function as reference if someone ever wants to write the CSS to match the style of the highlight.js that is already included in this page Permalink.

Why did I alter spongebob.js

I had to alter this file because I used a go template inside my code to access the keywords, and since a new textarea is created every time a button is clicked, I removed the jquery from spongebob.js and rewrote it in modern syntax, implementing the code mirror instance every click.

About themes

I think it'll take a while for the team to decide which theme should be used, or maybe not, idk. In case you guys didn't like the theme I chose, just pick one from here and i'll update the code.

My Discord is currently shar_alter.

}
</style>
<script type="text/javascript">
let keywords = ["for", "range", "if", "else", "template", "end", "true", "false", "nil", "gt", "lt", "len", "index"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why specifically these keywords? Why lt and not le and the same for gt not le. What are we classing as "keywords" because there's several other operators or control modifiers we could use here too

Copy link
Contributor Author

@sum117 sum117 May 29, 2024

Choose a reason for hiding this comment

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

Hi.

I got those keywords from the HLJS implementation that already exists. You can check the contents in the Permalink that I provided in the description of the PR. As for why they made the decision to not include the keywords you mentioned, I don't know.

Copy link
Contributor

@galen8183 galen8183 May 29, 2024

Choose a reason for hiding this comment

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

The existing implementation also includes all of templates.StandardFuncMap
Nevermind, I missed that they're added below

The other missing block actions and functions from text/template were probably just an oversight and should be added here.

@Ranger-4297
Copy link
Contributor

Ranger-4297 commented May 29, 2024

Currently loaded up this PR on my selfhost why implement a "syntax highlighting" that doesn't make a distinguishable barrier between functions and operators that are present in the code and random characters?
Obviously I assume this is one issue that will be fixed over time but I hope you at least noticed this when testing before submitting the PR

The only "highlight" in the PR here is the de-highlighting of variables (???) and changing the look of quoted text
image

@sum117
Copy link
Contributor Author

sum117 commented May 29, 2024

Yes, @Ranger-4297 .

That distinction can be added easily, and I did test it.

Judging by the image I included and comparing it to what existed before, I'd say it's a lot more helpful than just using "mode": "go", for example (it's what you'd get for using go <code> in discord, for reference).

I'm aware improvements can be made, but this isn't broken.

As for the operators, I agree, and I'll add a different color for them tomorrow, once I wake up.

@Ranger-4297
Copy link
Contributor

Ok, cool. Just glad we're on the same page
I think it's just as important as having this highlighting to be able to distinguish between what is what
I don't mind helping out provided you can give me a pointer on what, either

…ered vanilla go codeMirror tokenizer (rangers suggestion)
@sum117
Copy link
Contributor Author

sum117 commented May 29, 2024

Please, @Ranger-4297 , try it now:

image

@sum117
Copy link
Contributor Author

sum117 commented May 29, 2024

@ashishjh-bst ashishjh-bst merged commit 22ed700 into botlabs-gg:dev May 30, 2024
1 check passed
l-zeuch added a commit to l-zeuch/yag-nord that referenced this pull request May 31, 2024
Prepare for the upcoming CodeMirror addition to the CC edit page in
light of botlabs-gg/yagpdb#1656.

The CSS is blatantly copied from https://codemirror.net/5/theme/ with a
few removals to make it work with the implementation.

If you're reading this and use this theme do let me know of any visual
bugs.

Signed-off-by: Luca Zeuch <[email protected]>
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.

4 participants