Text Editor

My new TextEditor for Snap! 7 - dev!

the code is here:
https://snap.berkeley.edu/versions/dev/snap.html#present:Username=wdstudios_llc121&ProjectName=Keyboard&editMode&noRun

This is super cool!

Nice. For me it sometimes misses the first character I type after the green flag.

Now you need selection via mouse clicks, Emacs commands, etc. ;~)

To me, this kinda looks like command prompt. (Ah, the days of DOS.)

I know right

He will need to start using a list of items (each letter/character being an item), instead of a one giant string stored in a variable, to be able to do location selection via mouse clicks.

Currently there is no arrow-keys support for location/letter selection (which even the DOS command prompt has) to enable a letter to be inserted into the text.

This version is more a Typewriter than a Text Editor; but kids probably have no experience with typewriters anymore to know the difference.

I still remember the sound of my Dad's mechanical typewriter, though. I have even found, when I was preparing my SnapCon presentation this summer, that some people have YouTube channels dedicated to mechanical typewriters, and there was also the type that my father bought when I was a kid.

No, you can do substring selection using the Strings library. (Out in the real world, they write text editors without using lists of letters! Sometimes you see lists of lines in text editor implementation.)

I like it !

Improve it:

  1. add a blinking cursor
  2. add function to move into the text with arrow
  3. try to not always redraw all the text
  4. when we pressed "enter" on the last line, scroll the text
  5. more tricky: add bold, underline and italic

It's work smoothly than my tests :slight_smile:
I recommend!

Add pasting- would be cool and there is a library with that in it

If a whole line of text (more then one letter) is WRITE-en at once, how can you tell which individual letter is at the mouse's position, when mouse is pressed? After all, a letter's screen position can't be calculated in advance unless the letters are equally wide (or the widths of different letters are pre-calculated).

Here is a start:

[scratchblocks]
when (join [ctrl c] @addInput ::operators) key pressed
...
[/scratchblocks]

The letters of a monospace font (which Snap! uses) are, in fact, equally wide.
I would think what letter the mouse is on would be calculated on the fly when the stage is clicked.

How would maintaining a list of letters help?

What would help is making a letter sprite and displaying each letter on the stage with a clone of that sprite. It could then use variants of the WHEN I AM CLICKED hat block to detect the mouse entering or leaving its position on the stage. It'd be interesting to see how many letters could be represented as clones before the program got to be too slow.

Oh wait, you wrote an editor project -- how did you do it? (I should remember from your presentation but I've forgotten, sorry. I plead old age.)

PS: Using a monospace font, as the current project does, also allows computing the letter from its position, as helicoptur suggests.

but since snap uses the browsers monospace font, you can change it to a non-monospace font in the browser's settings, so not everyone's monospace font is the same. Mine is Consolas.

I think that if you set your browser's monospace font to one that isn't in fact monospace, and as a result the text editor doesn't work, that's your problem rather than a fault in the project!

The WHEN I AM MOUSE-ENTERED and MOUSE-DEPARTED?

I'll try my best!
If you look in the code you will see a write block that writes a blob of text.

You could use a project-local clipboard. But then how would you copy something from elsewhere...

Could not fetch project ClassTime DEMO
This project does not exist or is private