How to enter a 'new line' character into a text string

I tried things like say("Hello\nthere") and some variants with no success. I can copy and paste multi-line text into Snap! and that works fine.It seems If I press the 'Enter' key while in an input field it leaves the block.

Is there some way to do this without leaving Snap!?

2 Likes

Mulitline block.

You can make a "multiline input" in custom blocks.
multiline

Sorry I wasn't clear. What I want to do is have one of the inputs to join() be a new line.

untitled script pic (7)

2 Likes

In the Strings library is a MULTILINE block that you can put into an input slot of JOIN (or anything else). It will allow you to type a newline, or text containing newlines, whatever you like.

Ah, that works fine. As does dardoro's unicode 10.

So what is the design rationale for blocks like join() having only single-line input? What is the harm in allowing every textual input to be multi-line?

It seems both @18001767679 and @bh offered the same solution, Brian adding an explanation. But neither of them explained how can a newline be typed, so I tried the proven trial and error approach : ~)

Pressing the ENTER key has solved the mystery for me... (EDIT: rhyming here completely unintended).

The MULTILINE block needs a help popup; and in the unicode block's help there's still place to add the newline example.

I've considered making every text/any input multi-line, like I did in GP. But I'm afraid users will abuse newlines for layout attempts, which I want to discourage at this point, because we might/will change the automatic text layout rules for speech & thought balloons, result bubbles, variable watchers over time, which would and will break projects that hack together their own text formatting.

I see, thanks.

But any user who either uses the multi-line library, copies and pastes multi-line text into input fields, or uses unicode 10 will then suffer.

I guess you're minimising the chance that a non-expert user will encounter this.

Sure, there are pitfalls either way. My idea of what the code-/multi-line inputs are for is to, umm, input text. In the case of code it might make sense to actually write it outside of Snap in a "real" code editor and then copy and paste it into Snap. Likewise in a multi-line text input it might make sense to simply copy and paste some already existing text that's not too long altogether, e.g. some part of JSON/CSV that you find online (in Wikipedia, Stackoverflow, MDN etc.), where you don't get or don't want the whole file. Point is, this is more about data than about its representation and formatting. That's not to say we don't want to have better test formatting, just that I'd rather not establish a best practice of hacking your own custom text output format.

Side note: if you add a string to a list with a newline like Hello\nWorld the list watcher will display the newline

Whoa, that sounds like a bug. JS popping up above the abstraction barrier again.

Good idea about the help screen. On my list.

1 Like

Most of the time, I find it useful that hitting enter gets out from editing that input slot. Sort of like tab skipping to the next input slot. And, I'm in the habit of always hitting enter when I'm done with a text, and most of the time I don't want that redundant newline at the end of an input string.

But I could learn to live with it, if this changed; I'm not adamant about keeping it this way.

P.S. Then maybe instead of having a checkbox for multi-line we could have a checkbox for single-line.

No, just because somebody claims that using JS escape characters "works" inside Snap doesn't mean it's true.

Hello World

Right, I forgot Gorin's Law ("Never believe anything a user says") again. But maybe he meant the \n as just a forum shortcut for an actual multiline text and it was I who miunderstood.

yes

Actually, I think that only works when you return a JS string

Right. But that's point of \n - when embedded in a string it is replaced with unicode 10 / new line.

And why do so many languages support this? Because it is difficult to type a multi-line string in textual languages using the ENTER key.

Paradoxically, Snap! has no problem with users entering multi-line text using the ENTER key but chooses to disable it by default.

What are the roles of text in Snap!? Some uses are for speech balloons. As Jens has explained there is tension between text that is user-formatted and Snap!'s auto-formatting (as value balloons or speech bubbles). My use case that led to this thread was to generate text (a summary of some search results) to be exported and copy and pasted into a text file. This thread has revealed 3 or 4 ways to do this, but it was frustrating it wasn't apparent how to produce a multi-line text object. I even searched the manual for "new line" but didn't think to search for "multi-line".