Undo for text edit

Post here questions and problems related to oXygen frameworks/document types.
feherbbj
Posts: 3
Joined: Mon Mar 09, 2020 2:02 pm

Undo for text edit

Post by feherbbj » Mon Mar 09, 2020 5:37 pm

Dear Oxygen,

I am working on plugin for Oxygen Editor, which based on some user interaction it replaces text in a document. I done the text replacement logic based on some thread here on your forum ( i am working in author mode), so it looks something like this:

Code: Select all

	AuthorDocumentController docController = authorPageAccess.getDocumentController();
	...
	docController.beginCompoundEdit();
	docController.delete(startOffset, endOffSet); 
	docController.insertText(startOffset, replaceWith); 
	docController.endCompoundEdit();
	...
However the undo action does not appear even though beginCompoundEdit and endCompoundEdit is definitely called.

1) My question is that how can i make this work? Or what am i doing wrong here?
2) Another is question is that, can i do something similar in grid/text layout?

Thank you in advance,
Balazs Feher

Radu
Posts: 6923
Joined: Fri Jul 09, 2004 5:18 pm

Re: Undo for text edit

Post by Radu » Mon Mar 09, 2020 7:35 pm

Hi Balasz,
1) My question is that how can i make this work? Or what am i doing wrong here?
I cannot find anything wrong with your code. So the undo action does not appear enabled after the code is executed, right?
In what context is your code called? On what API callback method? Is it called inside a custom AuthorOperation or on some kind of listener?
2) Another is question is that, can i do something similar in grid/text layout?
We have no API at all for the Grid mode and we'll probably never add any.
For the Text editing mode we do have some API (not as evolved as the one for Author):

https://www.oxygenxml.com/InstData/Edit ... rPage.html

As I do not know exactly your overall plans I do not know if there is enough API or not for what you need.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

feherbbj
Posts: 3
Joined: Mon Mar 09, 2020 2:02 pm

Re: Undo for text edit

Post by feherbbj » Tue Mar 10, 2020 12:51 pm

I cannot find anything wrong with your code. So the undo action does not appear enabled after the code is executed, right?
In what context is your code called? On what API callback method? Is it called inside a custom AuthorOperation or on some kind of listener?
Yes, the undo action does not become enabled.
It has been called from another thread. I have a web service, which has been called from a thread, response of which can start this replace action.
We have no API at all for the Grid mode and we'll probably never add any.
For the Text editing mode we do have some API (not as evolved as the one for Author):
Regarding text mode, I am looking for something like the AuthorCaretListener in author mode. So some kind of event which occurs on user interaction (edit, caret movement...etc).
For grid layout, it is not that important. For text layout i found that there is no such event, but who knows, maybe it is on the road map, or i looked over something.

Thanks for the quick reply!

Balazs

Radu
Posts: 6923
Joined: Fri Jul 09, 2004 5:18 pm

Re: Undo for text edit

Post by Radu » Tue Mar 10, 2020 2:54 pm

Hi Balasz,

So:
It has been called from another thread. I have a web service, which has been called from a thread, response of which can start this replace action.
And are the changes actually made in the editing area?
I want to know the entire workflow of the operation, for example:

1. I add a caret listener
2. When the caret moves I start a thread
3. When that thread finishes I use the Author API to makes changes somewhere in the document.

I'm interested to know if you make changes in the Author editor directly on an AuthorDocumentListener callback which you should not.

Also if you are calling Author API from a Thread, the Author model is not thread safe, try to make all calls to methods in the AuthorDocumentController on the AWT thread. For example you can use "SwingUtilities.InvokeAndWait" with a runnable code which makes the changes.
Regarding text mode, I am looking for something like the AuthorCaretListener in author mode. So some kind of event which occurs on user interaction (edit, caret movement...etc).
You can gain access to the swing JTextArea used to implement the text editing mode:

https://www.oxygenxml.com/InstData/Edit ... omponent--

After this, you can cast the editing component to JTextArea and use the regular Swing API to add a caret listener or a document listener.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

feherbbj
Posts: 3
Joined: Mon Mar 09, 2020 2:02 pm

Re: Undo for text edit

Post by feherbbj » Tue Mar 10, 2020 7:05 pm

Hi,

Regarding the first part of the issue, you were right the problem was that the model is not thread safe. With SwingUtilities it worked fine.

Regarding the second part, thank you for this information, it was really helpful!

Thanks again for your help and for the quick reply

Bets regards,
Balazs

Post Reply