General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › slow range.select() for large Document
-
lqian May 28, 2009 at 7:35 am
slow range.select() for large Document
May 28, 2009 at 7:35 amParticipants 3Replies 4Last Activity 13 years, 10 months agoI 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?
Derek Read May 29, 2009 at 12:57 am
Reply to: slow range.select() for large Document
May 29, 2009 at 12:57 amRange 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.
lqian June 4, 2009 at 4:53 am
Reply to: slow range.select() for large Document
June 4, 2009 at 4:53 amBy turning off the formatter, my semantic checker runs much faster while it checksĀ the document.
Thank you very much!
lqian June 5, 2009 at 6:27 am
Reply to: slow range.select() for large Document
June 5, 2009 at 6:27 amAfter 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?
Derek Read June 5, 2009 at 8:06 pm
Reply to: slow range.select() for large Document
June 5, 2009 at 8:06 pmIts 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.
-
AuthorPosts
- You must be logged in to reply to this topic.