[SOLVED]DirectEntry and adding line breaks with enter

I’m trying to use a DirectEntry for a large field where a use can input notes. I want the user to be able to push the enter key to start a new line of text within the field, and I’ve got that mostly working with the following code:

testEntry = DirectEntry( ... )
testEntry["command"] = addLineBreak
testEntry["extraArgs"] = testEntry

def addLineBreak(text, entry):
  text += "\n"
  entry.enterText(text)

The problem is that when you hit enter, you have to re-click the DirectEntry to start typing in it again. I tried adding entry.setFocus() to the addLineBreak function but that resulted in no change. Anyone have an idea on how to fix this?

def addLineBreak(txt,entry):
  curpos = entry.node().getCursorPosition()
  entry.set(txt[:curpos]+ "\n" + txt[curpos:])
  entry.node().setCursorPosition(curpos+1)
  entry['focus']=1

Thanks, that works.