Fun with cursors

0 views
Skip to first unread message

Ian C

unread,
Mar 30, 2016, 4:59:33 AM3/30/16
to CorinthiaTeam
Hi Peter,

flushed with the success of finding that function I went on to try some other cases.

For my test appending a paragraph I ended up doing as you suggeest and removing the Script before running. This seems strange to me since we are now running something that doesn't exist? Although it is the require which has done its job and will not be called again.

That being said I then have....

    var posRef = api.input.documentEndAnchor();
    posRef = api.input.positionRelativeTo(posRef, "backward", 1);
    api.input.setSelectedTextRange(posRef, posRef);

    api.cursor.enterPressed();
    api.cursor.insertCharacter("Puff, the magic dragon, lives by the sea.");

Using the end of document seems more logical for the test. And all works as desired.

I then went on to look at my prependParagraph test and to try the same logic,

What I find kind of works is...

function autoEdit(api) {
    var posRef = api.input.documentStartAnchor();
    api.input.setSelectedTextRange(posRef, posRef);
    api.cursor.enterPressed();
    api.cursor.moveLeft();
    api.cursor.insertCharacter("Puff the magic dragon lives by the sea.");
}

The reason I say kind of works is that the content of the orginal paragraph is replaced and the first is moved to the second paragraph (or at least its contents)

My framework shows me the pretty pictures of....

Inline image 2

Note I now get to see the cursor div too?

When the concrete document trees are merged we get...

Inline image 3
So we've not really inserted the paragraph but logically I guess its ok. I have dropped the STYLE though. I need to grab that as part of processing the html. If there is no style assume the previous? Or maybe in the test I need to get the paragraph attributes correctly. Copy the formatting?

The last part of the test extracts the above picture to some text.

Changed:
node: DOM_TEXT
seq: 18
from: "Hello world"
to: "Puff the magic dragon lives by the sea."
Added: 
node: TEXT_P
Added: 
node: DOM_TEXT
value: "Hello world"
Which is the equivalent of what I expect.but ideally I think a new paragraph should be inserted.
Unless there is more magic to be revealed.... :-)


--
Cheers,

Ian C
Reply all
Reply to author
Forward
0 new messages