Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to make the Return Key move the insertion point to the end of the input field's text. Please see the example below for the problem I am facing. Namely, when the return key is pressed, the input field's text is updated but the insertion point is not moved.

DynamicModule[{thing = "foo"}, nb = EvaluationNotebook[];EventHandler[InputField[Dynamic@thing,String], {"ReturnKeyDown" :> (thing = thing <> "bar";SelectionMove[nb, Next, Word])}]]
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Figured this one out. It is basically the same problem described here and essentially answered here.

The actions in the EventHandler are calculated on the preemptive link. In order to make the EventHandler act as a Button when Method->"Queued", DynamicWrapper can be used:

DynamicModule[{thing="foo",returnkeydown=False},nb = EvaluationNotebook[];DynamicWrapper[EventHandler[InputField[Dynamic[thing],String],{"ReturnKeyDown":>(thing= thing<>"bar";returnkeydown=True)}],If[returnkeydown,returnkeydown=False;SelectionMove[nb,Next,Word]],SynchronousUpdating->False]]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.