Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New lines in InputField

57 views
Skip to first unread message

Chris Degnen

unread,
Mar 30, 2011, 5:11:13 AM3/30/11
to
Can anyone suggest how to enter new lines in input text,
preferably using the return key?
In the example below I can paste into an input field a piece
of text which includes new lines, such as these two sentences,
but new lines can't be typed straight in to the input field,
as users are wont to do.


CreateDialog[{TextCell["Enter your text here:"],
InputField[Dynamic[input], String, FieldSize -> {50, 12}],
DefaultButton[
DialogReturn[CreateDocument[TextCell[input, "Print"]]]]},
NotebookEventActions -> {}];


Chris Degnen

unread,
Mar 30, 2011, 5:11:45 AM3/30/11
to
Aha, got it.

CreateDialog[{TextCell["Enter your text here:"],
InputField[Dynamic[input], String, FieldSize -> {50, 12}],
DefaultButton[
DialogReturn[CreateDocument[TextCell[input, "Print"]]]]},

NotebookEventActions -> {"ReturnKeyDown" :>
FrontEndTokenExecute["HandleShiftReturn"]}];

Chris Degnen

unread,
Mar 30, 2011, 5:12:41 AM3/30/11
to
I spoke too soon. Using the front end token HandleShiftReturn
doesn't replicate the correct effect of a pasted-in carriage return,
as becomes apparent when text justification is applied.
Is there another front end token that will do the trick? Thanks


CreateDialog[{TextCell["Enter your text here:"],
InputField[Dynamic[input], String, FieldSize -> {50, 12}],
DefaultButton[
DialogReturn[
CreateDocument[

Graphics[{Yellow, Rectangle[{0, 0}, {300, 200}], Black,
Inset[TextCell[input, 12, LineSpacing -> {0, 16},
TextJustification -> 1], {0, 200}, {Left, Top}, {300,
Automatic}]}, PlotRange -> {{0, 300}, {0, 200}},
ImageSize -> {300, 200}]]]]},

Chris Degnen

unread,
Mar 30, 2011, 5:14:21 AM3/30/11
to
This seems to be the solution. FrontEndExecute clues gleaned from
perdalum's post of January 2010.


CreateDialog[{TextCell["Enter your text here:"],
InputField[Dynamic[input], String, FieldSize -> {50, 12}],
DefaultButton[
DialogReturn[
CreateDocument[
Graphics[{Yellow, Rectangle[{0, 0}, {300, 200}], Black,
Inset[TextCell[input, 12, LineSpacing -> {0, 16},
TextJustification -> 1], {0, 200}, {Left, Top}, {300,
Automatic}]}, PlotRange -> {{0, 300}, {0, 200}},
ImageSize -> {300, 200}]]]]},
NotebookEventActions -> {"ReturnKeyDown" :>

FrontEndExecute[{NotebookWrite[InputNotebook[], "\n", After]}]}];

Alexey

unread,
Mar 31, 2011, 5:00:19 AM3/31/11
to
Chris,

Thank you for publishing the solution. I thought more than two years
that it was impossible.

Alexey

0 new messages