General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion slow range.select() for large Document

  • lqian

    slow range.select() for large Document

    Participants 3
    Replies 4
    Last Activity 13 years, 6 months ago

    I have a large XML document (around 950k). When I run range.select(), it takes about 3 to 4 seconds to excute. This causes a performance issue for my application.

    Does anybody knows why range.select() running so slow for large document? Is there any way I can work around it?

    Reply

    Derek Read

    Reply to: slow range.select() for large Document

    Range objects are normally hidden and do not cause the document to be updated when moving them around, however, as soon as you make a modification to the document the formatter (the code that draws the document on the screen) runs to update what the user is viewing.

    Range.Select() also forces the formatter to run because the selection is made visible.

    Depending on what you are doing you may wish to try turning off formatting entirely until whatever your script is doing has completed. This is done using the API ActiveDocument.FormattingUpdating=boolean

    Be careful with this API because if you leave it set to false XMetaL will continue to not update what the user sees on screen and they will see odd behaviour when they begin typing or interacting with the document. So, make sure you catch any exceptions and test your code well.

    Reply

    lqian

    Reply to: slow range.select() for large Document

    By turning off the formatter, my semantic checker runs much faster while it checksĀ  the document.

    Thank you very much!

    Reply

    lqian

    Reply to: slow range.select() for large Document

    After I turned off the formatter, the performance of the components like semantic checking improved dramatically.

    Now I have another situation related to the range.selection(). After pasting or inserting new content into the document, I need to find out cursor position and display it by using range.selection(). Setting FormattingUpdating to false does not help much in this case because turning on formatter takes approximately same time as running range.selection with FormattingUpdating set to true.

    May I know whether there is a way I can find out the cursor position WITHOUT using selection method?

    Reply

    Derek Read

    Reply to: slow range.select() for large Document

    Its not clear to me what you mean by this. Perhaps one of the following?

    • If you need to show the current position to the user (to allow them to continue to edit the document) then you must turn on formatting. There is no other way.
    • If your script needs to know what the current position is you already have it if you have stored the Range object in a variable (which you must have done if you are manipulating things using Range).

    Perhaps more detail about what your script currently does, and what it does not do (yet) would help clarify.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support