Issue 115741 - Modify event fired before model modified when paragraph deleted
Summary: Modify event fired before model modified when paragraph deleted
Status: UNCONFIRMED
Alias: None
Product: Writer
Classification: Application
Component: programming (show other issues)
Version: OOo 3.3 RC6
Hardware: PC Windows, all
: P3 Trivial with 2 votes (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords: needhelp
Depends on:
Blocks:
 
Reported: 2010-11-23 14:20 UTC by zbyszeks
Modified: 2017-05-20 10:44 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Contains macros to observe document modifications (9.73 KB, application/vnd.oasis.opendocument.text)
2015-04-22 18:22 UTC, openofficebugs
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description zbyszeks 2010-11-23 14:20:34 UTC
when paragraph is deleted from document modified(EventObject event) method from 
XModifyListener is executed before model is changed.

Method to reproduce problem :

1)create document

<start of document>
1

3
<end of document>
(each line is a separate paragraph)

2) attach ModifyListener to document :

public class DocumentEventListener extends WeakBase implements XModifyListener {

    /***
     * @param model - model of document we want listen to
     */
    public DocumentEventListener(XModel model) {
        super();
        XModifiable xmod = (XModifiable) 
UnoRuntime.queryInterface(XModifiable.class, model);
        xmod.addModifyListener(this);

    }

    @Override
    public void modified(EventObject event) {

        System.out.println("----modify-start----");
        XTextDocument xtd = (XTextDocument) 
UnoRuntime.queryInterface(XTextDocument.class, event.Source);

        System.out.println(xtd.getText().getString());
        System.out.println("----modify-end------");

    }

    public void disposing(EventObject event) {
        XModifiable xmod = (XModifiable) 
UnoRuntime.queryInterface(XModifiable.class, event.Source);
        xmod.removeModifyListener(this);

    }
}


3) remove empty paragraph ("backspace it") from the empty line (or line below, 
does not matter).


output of listener will be :

----modification-start----
1 

3
----modification-end------

while I believe it should be :

----modification-start----
1 
3
----modification-end------

problem does not appear when deleting line from multi line paragraph.

Not tested on other OS/platforms
This also occurred on OO 3.2 and 3.2.1 (not tested on older versions)
Comment 1 michael.ruess 2010-11-30 15:40:56 UTC
MRU->OS: could please give a short evaluation on this?
Comment 2 eric.savary 2010-12-01 12:01:24 UTC
@TBO: as discussed with JJ, please take over.
Comment 3 b.osi.ooo 2010-12-02 14:53:43 UTC
I was promised a basic dialect problem.
This looks like some c code.

Passing on to OS: MRU->OS: could please give a short evaluation on this?
Comment 4 zbyszeks 2010-12-02 16:01:15 UTC
DocumentEventListener is a java class.
I forgot to write about it.
i'm sorry 
Comment 5 openofficebugs 2015-04-22 18:22:52 UTC
Created attachment 84685 [details]
Contains macros to observe document modifications

Run Initialize to set up listener
Modify the document and observe the captured text states
Check with GetString at the end
Comment 6 openofficebugs 2015-04-22 18:24:42 UTC
I'll confirm this right now running version 4.0.1.  Both in my C++ extension and in the attached document with Basic macros, the modified event is not sent after the modification is complete if there is a paragraph break among the deleted characters.  At times it is sent after some of the characters have been deleted, but while the paragraph marker is still present.  No event is sent at the end after all the modifications are complete.  If I manually query the text afterwards, I find that the remaining changes have been completed without notification.

This is a major problem for us, because we are trying to track changes to a document.  If the user makes a modification and we go to check what the text now is, we can't read it correctly if a paragraph break has been deleted.

For example, starting with text where \r means CR or paragraph break

1a\r
2\r
\r

if I delete a\r by selecting both characters and pressing DEL, the text read after the modify event occurs is 1\r2\r.  (actually \r\n because this is on a PC and the final \r or \r\n is never returned for getString()).  If I query the text afterwards, it is 12\r as expected.

In the attached document run the Initialize macro to set up the listener, then edit the document.  Run GetString to see what's in the document.
Comment 7 Marcus 2017-05-20 10:44:04 UTC
Reset the assignee to the default "issues@openoffice.apache.org".