On Wed, Aug 10, 2011 at 14:37, Patrick Coleman <[email protected]> wrote:
> Nice demo!
Thanks!
Change my code to:
String text = DocHelper.getText(document, range.getStart(), range.getEnd());
document.deleteRange(range.getStart(), range.getEnd());
insertXml(range, "<p>" + text + "</p>");
But still do not understand how to keep doodads in the selected text.
There is already something ready for this?
> For some tools useful for getting information from a document, I'd recommend
> looking at DocHelpers:
> http://code.google.com/p/wave-protocol/source/browse/src/org/waveprotocol/wave/model/document/util/DocHelper.java
> - in particular, getText(doc, start, end) is likely useful if you can get
> the document's selected range.
>
> The code you had at first converted the entire document to an operation and
> tried to get a particular operation as a text op - for things like this,
> best to avoid operations unless you really need low-level stuff, but for
> most things, working with the DOM tree is much nicer, and hopefully there's
> a number of utility classes like DocHelper to make things easier
> (EditorAnnotationHelper and static Point methods also come to mind)
>
> On 10 August 2011 20:28, Anton Starcev <[email protected]> wrote:
>
>> Doodad insert code:
>>
>> Range range = toolbarUpdateListener.getSelectionRange();
>> final CMutableDocument document = harness.getEditor().getDocument();
>> final Point<ContentNode> point = document.locate(range.getStart());
>> document.insertXml(point, XmlStringBuilder.
>> createFromXmlString("<p>paragraph</p>"));
>> harness.getEditor().focus(false);
>>
>> I what to replace "paragraph" with current selected range's characters.
>>
>> Full source:
>>
>> http://code.google.com/p/wave-editor/source/browse/src/com/appspot/ast/client/layout/WaveEditor.java
>>
>> result looks like this:
>> http://ast.appspot.com/editor/
>>
>> On Wed, Aug 10, 2011 at 13:14, David Hearnden <[email protected]> wrote:
>> > Hi Anton,
>> >
>> > Could you please clarify what you're trying to do?
>> >
>> > Are you trying to insert a doodad programmatically into a document? Or
>> are
>> > you trying to add code to replace the current browser selection in a
>> > document being edited with a doodad? Or are you trying to make a doodad
>> > appear when a user makes a selection over some text?
>> >
>> > -Dave
>> >
>> > On Wed, Aug 10, 2011 at 6:33 PM, Anton Starcev <[email protected]
>> >wrote:
>> >
>> >> Hi all,
>> >>
>> >> How can I set doodad over selection?
>> >>
>> >> At first I tried to get text:
>> >>
>> >> Editor richEditor = harness.getRichEditor();
>> >> DocInitialization docInitialization =
>> >> richEditor.getContent().asOperation();
>> >> String string =
>> docInitialization.getCharactersString(range.getStart());
>> >>
>> >> but can't find proper method for that.
>> >>
>> >>
>> >> --
>> >> Anton Startsev
>> >>
>> >
>>
>>
>> --
>> Anton Startsev
>>
>
--
Антон Старцев
______________________________________________________________________
[email protected] | www.artlebedev.ru