Basic Snap! Code Editor

Using the new Code Blocks to Code library, I made a simple, unfinished, proof of concept code editor with syntax highlighting and beautification.

Press ` to run the code, and Ctrl to beautify it

Oh, ok

Cool :astonished:

Interesting idea. I couldn't quite figure out how to start; am I supposed to put a script in TEXT, or am I supposed to type text into the program?

You're supposed to type the code into it, as if it was visual studio or something

?

The text editing is kind of buggy. I have to press backspace when I first load the project for any of my key pressed to work. I know it might be difficult, but being able to at least use the left and right arrow keys to move the cursor around would be nice (I don't expect you to figure out how to handle using the up and down arrow keys).

However, this isn't really a text editor, but more of a showcase of your syntax highlighting, which is pretty cool.

This is actually the easiest thing for me. I'm trying to figure out left and right, but I can't. Help would be appreciated

It's not finished and pretty buggy, and it took me a while to do

Oh, I just looked at your code, and I didn't realize you were storing the text as lines instead of a single string (plus, I didn't think about the fact that the font was monospace, negating the need ot figure out the character closest to where the cursor would end up).

In order to do that, you need to have a (cursor) variable, which is a number indicating where to insert characters into. As for inserting characters, just grab the characters from the start to the cursor, and the characters after the cursor, then add the new character in between.

Hm, good idea. For now, I'm working on an extension for another website, but this seems like a fun project to do tmr. Also, I tried adding a visual cursor, but since it renders the entire thing, the cursor would always be at the end of the text

I built a concept one a while back when v10 was in dev: Snap! Build Your Own Blocks

Click on the sprite to open the menu

Maybe this'll give some inspiration on how to improve yours

Keys

Tab - Insert 4* spaces
Insert - Add something behind cursor
Delete - Delete a character in front of cursor
PageUp - Go up one document
PageDown - Go down one document
Left Arrow - move cursor left
Right Arrow - move cursor right
Up Arrow - Go up one line
Down Arrow - Go down one line
F2 - Refresh code suggestions database
Home - Go to first line
End - Go to bottom

*default

this reminds me of my own code editor. maybe ill work on it again. maybe.

I like how 6 of the keys you mentioned aren't on most keyboards anymore, and if they are most people forgot about them lol

They wont exist on chromebooks because they are cheap, but they still exist on many keyboards.

Sorry, I meant most laptop keyboards. I had a Windows laptop a few years ago that didn't even have the numpad (sadly)

Coincidentally, I made my own fork of that back before the school year ended

If your keyboard has a numpad, then the keyboard most likely has those keys. I personally use them a lot.

I never knew I hated the insert [ V] at () in @list::list block but today has been a telling day
(i tried making a cursor thing but it doesnt work well because of the weird unexpected and inconsistent functionality of the block)

Oh, also, I forgot to say but I made this mainly to get people interested in the new library (and i think it worked)