I am using the following macro to edit text in my presentation using a text cursor from getCurrentSelection(). For example, it will let you edit the text inside a rectangle object.
' First select some text in a text object (like a rectangle), then run this:
Sub Main
' Get an XTextCursor for the selected text in your text object.
' NOTE: If it gives an error, you likely did not have any text selected.
dim oSel as Object, oTextCursor as Object
oSel = ThisComponent.getCurrentSelection()
oTextCursor = oSel.getText().CreateTextCursorByRange(oSel.getStart())
' Insert into the text object a new string.
dim oText as Object
oText = oSel.getText()
oText.insertString(oTextCursor, " [Hi] ", false)
End Sub
However, this code has two problems:
- If the user has edited the text since they last clicked out of the object, the TextCursor does not correctly access the current text.
- The Impress UI does not refresh and show the edited text (after the macro runs) until after the user clicks out of the text box.
How can both access the correct currently selected text (even if there was an edit), and update the UI without clicking out of the object?
Brian