Tuesday, November 1, 2011

Error Code When Deleting a Range and Some Buggy Behavior

If you attempt to delete a range that is beyond what exists in the document, you get an error code as is appropriate.

var doc = app.ActiveDoc;
var mainflow = doc.MainFlowInDoc;
var tframe = mainflow.FirstTextFrameInFlow;
var pgf = tframe.FirstPgf;

var tRange= new TextRange();
tRange.beg.obj = pgf;
tRange.beg.offset = 2;
tRange.end.obj = pgf;
tRange.end.offset = 100; // END OFFSET OUT OF BOUNDS

As the ending offset is out of range and I get the error code -21 (FE_OffsetNotFound) for the document shown. No text gets deleted.

If I change the code to tRange.end.offset = 10;, the following happens:

In summary, the "345" and the end of paragraph marker get deleted from the first paragraph and the "abcd" from the line that follows. That is eight characters in all as line ends and start paragraphs do not have offset (at least not in the FDK). The error code is now back to 0 (FE_Success).

I have two problems with this behavior:
  • The delete should not have gone beyond the paragraph specified.
  • The offset calculation is incorrect.

No comments:

Post a Comment