How to insert a linebreak in a EditText-widget?

Is there a way to insert linebreak/newline by code into a text in a EditText-widget?
I tried [charcode[10]] and [charcode[13]], but none of those worked. Insertion of \n doesn’t work, either.

Maybe I could find the right character if there would be some sort of asc[]-Operator (the opposite of charcode[], which prints out ASCII/UTF-8 code of a char).

The text is not so much in the “edit text widget” but the field it is using to edit. Are you editing a simple field or the text field (which is a text area field).

Regular fields can contain a new line, however if you edit them in the default field editor the newlines are removed. You need to set up different handling to use fields other than the text field.

  • One way to deal with this is actually store content in another tiddlers text field and transclude that in the first tiddler.

If you use the full text (area) editor you can manually insert new lines, or have a button to insert them.

\define new-line() """

"""
\end

Something like this has being suggested before, search here for “insert new line”

Perhaps you can share a minimal example that will work, or not work on tiddlywiki and someone can give you back a working solution?

1 Like

My actual setup is a edit-text-widget surrounded with a keyboard-widget:

<$keyboard actions=<<getkey>> key=<<[fn.allowedkeys>> ><$edit-text tiddler="source.lines" field="text" class="monospaced" /></$keyboard>

getkey processes event-key, which separates input into blocks and should insert a new line when event-key matches return or enter.
I will try your suggestion tomorrow, it’s rather late here and I should better go to bed :wink:
Thank you for your quick reply!

Best of luck, so Far I have found the keyboard widget verbose and hard to follow. :sleeping:

Do you want to insert it with a toolbar-button, or how do you intend to activate your “code”?

Thanks, but it isn’t really that hard - or at least it does what I want.
What I don’t know about is the scope of event-key. In my opinion, a construct like

<$keyboard actions=<<getkey>> key=<<[fn.allowedkeys>> >
<$edit-text tiddler="source.lines" field="text" class="monospaced" />
key:<<event-key>>
</$keyboard>

should print out the pressed event-key after the text-area. But it doesn’t.
even-key is available inside the macro getkey, so I write the value into a field and retrieve the field value:

`<$keyboard actions=<<getkey>> key=<<fn.allowedkeys>> >
<$edit-text tiddler="source.lines" field="text" class="monospaced" />
key:{{!!keypress}}
</$keyboard>`

I also use a refresh-tiddler to make things work, but that isn’t reflected in the sample code above.

I’d like to do it inside a macro, which should append a newline after the existing text whenever the enter-/return-key is being pressed - like [[SomeTiddler]get[text]addsuffix[newline]]

A toolbar button can be a fallback-option, when I can’t manipulate the text in the way mentioned above.

Either I misunderstood something or it doesn’t work this way for me :wink:
Tiddler output (TW5-format):

new line
here

Text-edit:

new line"""

"""here
1 Like

I may be ignorant but I do not understand that. The Enter-key already does add a new-line. You can click CTRL-End Enter - and you have all the flexibility which users usually want.

If the Enter key does go to the end of the text and add a new line that’s an absolute surprise to everyone who ever used an editor.

So I think I need even more context.

The scope of the $keyboard-widget is the “body” of the keyboard widget. So outside the even cannot be seen.

Hm, you are right. I think that there is some vital information missing here. I actually thought more than I was writing :wink:

I discovered the keyboard widget for doing some text formatting on the fly. First a command is expected, which is checked against a list of known commands. If the command match, a space is automatically inserted and the (internal) input mode switches from letters (=command) to arguments (digits). When the line is finished (enter/return), the internal input mode is being resetted to accept letters (command).

The macro adds each key to the text and therefore I need to append a newline also. Unfortunately the keyboard widget translates this into a string and the event-key contains enter or return and not an appropriate char sequence (which could append a new line to the captured text).
I hope this explanation can clarify my requirement? Below is a simplified version of my code (only for digits).

Regarding the scope of the event-key:
In my first example it is placed inside the $keyboard-tag. So it should work this way, if I understand it right? But it does not.
It captures the keys right, but it is only visible inside the scope of the macro.

\procedure getkey()
<$action-setfield $field="keypress" $value=<<event-key>> />
<$let source={{{ [{sourcetext!!text}] }}} newtext={{{ [<source>addsuffix<event-key>] }}} >
<$action-setfield $tiddler="sourcetext" $field="text" $value=<<newtext>> />
<$action-setfield $tiddler="$:/temp/refreshtitle" text="new"/>
\end

<$keyboard actions=<<getkey>> key="1 2 3 4 5 6 7 8 9 0" >
<$edit-text tiddler="sourcetext" field="text" refreshTitle="$:/temp/refreshtitle" class="monospaced" /><br>
key:<<event-key>><br>field:{{!!keypress}}
</$keyboard>