Talk:LOM
From LMNLWiki
Mutating LOMs
The main problem that I ran into when attempting to implement something like this a little while ago was managing insertion in the content of a limen. Take the example
[p}...{p][p}[b}...{b]...{p]
Say I call
doc.insertText(3, 'new')
Which of these is the result?
[p}...new{p][p}[b}...{b]...{p]
[p}...{p]new[p}[b}...{b]...{p]
[p}...{p][p}new[b}...{b]...{p]
[p}...{p][p}[b}new...{b]...{p]
There's obviously a choice about how insertText() and its companions are specified, and the LOM needs to be clear about which choice is made. The person using the LOM can then modify the starts and ends of the ranges to give the final result that they're after.
It would help, I think, to have insertText() et al. provide methods for handling those cases where the point at which the text is inserted is adjacent to a tag. Something like
method insertTextBefore(Range range, String newtext) # inserts just before the range starts method insertTextAfter(Range range, String newtext) # inserts just after the range ends method insertTextAtStart(Range range, String newtext) # inserts just after the range starts method insertTextAtEnd(Range range, String newtext) # inserts just before the range ends
— Jeni 04:33, 23 September 2006 (EDT)
Ranges and Sets
Since tags can overlap and the two ranges [b} and [p} start at the same text position, from the example above there is also another valid LMNL possibility:
[p}...{p][b}new[p}...{b]...{p]
In fact, there are several other possiblities too (although less obvious). The LOM doesn't say whether [p} or [b} are first, and indeed there is no meaningful order to them. Serialising the LOM forces us to place one before another, but nothing should be read into that order. In fact, the LOM as it stands cannot deal with more than one range at the same character position at all: Range method getRange(integer i).
So I guess we need something like RangeSet method getRanges(integer i), which would return all ranges ending just before, or starting at that position. The insert api could then specify which ranges the text was inside. You could have any arbitrary combination - maybe something like this, using sets of ranges:
method insertTextAtPositionInsideRanges( String newText, int position, RangeSet insideRanges)
[p}...{p]new[p}[b}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { } )
[p}...new{p][p}[b}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { {p] } )
[p}...[p}new{p][p}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { {p],[p} } )
[p}...[b}new{p][p}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { {p],[b} } )
[p}...{p][p}new[b}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { [p} } )
[p}...{p][b}new[p}...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { [b} } )
[p}...{p][p}[b}new...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { [p},[b} } )
[p}...[b}[p}new{p]...{b]...{p] insertTextAtPositionInsideRanges( 'new', 3, { {p], [b}, [p} } )
(Note: in the example above, I distinguish between the two possible p tags using either the end or the start tag. I should use a tag identifier to do this syntactically correctly - but the idea should be clear).
— User:Matt Palmer 9:38 31 August 2008
