On Sun, Nov 8, 2015 at 12:33 AM, Gunnar Hellström <
[email protected]> wrote:

> Den 2015-11-08 kl. 04:57, skrev Dumaine, Xander:
>
> Hi everyone, I'm also late to the party - I'm working on implementing this
> now. My only concern is about message editing *inside* the message. For
> example, if a user types 'hello orld', then focuses the cursor before
> `orld` to add a `w`, what is the strategy for transmitting that? It seems I
> could compare the strings and find the place position where they defer, use
> a series of erases, then a series of inserts, but that seems heavy,
> especially if there's a longer message and edits are made toward the
> beginning.
>
> There is a "p" attribute described in section 4.6.2 second bullet point as
> a position counted from the beginning of the message.
> Chapter 8 provides a good set of examples. Section 8.3 shows edits of the
> kind you are asking about.
>

Correct. It is not necessary to erase text to insert text mid-message.
Here's a (very rudimentary, simplified) example of an <rtt> payload to
insert one character:

Current message: "*Hello orld*"

 <rtt xmlns='urn:xmpp:rtt:0' seq='123'>
    <t p='6'>w</t>
 </rtt>

Updated message: "*Hello world*"

As you notice, the p attribute defines the position within the string, to
insert the new string of text at.  (Be noted to follow section 4.8.1
Unicode Character Counting, when translating 'p' into a string index for
string insertion).

I presume you are following section 7.3.1 to universal capture all possible
text modifications (including typing, AutoCorrect, pastes, AutoText, etc),
as most XEP-0301 implementations tend to do. For that, you want to do both
of this:
- Scan forward on both before-and-after strings to find first differing
character.
- Scan backwards on both before-and-after strings to find last differing
character.

This allows you to generate action elements for mid-text modifications,
without needing to erase backwards from the end of the string.

Thanks,
Mark Rejhon

Reply via email to