1
$\begingroup$

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])}]]
$\endgroup$
1
$\begingroup$

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]]
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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