Giter Club home page Giter Club logo

Comments (11)

1gravity avatar 1gravity commented on July 18, 2024

I don't know what you mean with "caret position"? Do you want to insert a caret into HTML or what?

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

Hi,

I what to get the position of the cursor in HTML.

For example, if i have this text:

This is a text

If my cursor is before the word 'is' (This |is a text) the position of the cursor is 5 in plain text. But if i had the same sentence but with some HTML tags like this:

<b><u>This</u></b> is my text

And i put the cursor in the same position i will get position 5 in plain text, but i want to get the position in HTML which is 19 in this example.

So i want to get this position.

Thanks =D

from android-rteditor.

1gravity avatar 1gravity commented on July 18, 2024

Why would you want the position in the html text? The html is simply used as an format to persist the text and it could be any format that supports the formatting (rtf, markdown, xml...). Spanned text as used by Android is not a good format to persist and thus the conversion from/to html.
I'm asking this question because I think you're trying to do something and I'm fairly certain that something might not be necessary or might have a much easier solution.
If you elaborate on what you're ultimately trying to achieve I might be able to point out a different approach.

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

Oh Thanks! I'm trying to insert a image inside the text. I have the image path and i'm doing like this:

mRTMessageField.setRichTextEditing(true, rtHtmlBefore.getText() + "<img src=\"" + url +"\">" + rtHtmlAfter.getText());

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

I tried but did not work =(

from android-rteditor.

1gravity avatar 1gravity commented on July 18, 2024

You can't insert an image from a url into the rich text editor. Android's ImageSpan doesn't support images that aren't stored locally so even if you could insert the image like that, it wouldn't render. You need to download the image first or else rewrite the ImageSpan class.

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

Oh sorry, the image is stored locally.

I was doing this:

    Editable str = mRTMessageField.getText();
    str.insert(mRTMessageField.getSelectionStart(), "\uFFFC");
    ImageSpan imageSpan = new ImageSpan(new RTImageImpl(imagePath), false);
    str.setSpan(imageSpan, mRTMessageField.getSelectionStart(), mRTMessageField.getSelectionStart(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

from android-rteditor.

1gravity avatar 1gravity commented on July 18, 2024

That's how the editor itself inserts an image:
EventBus.getDefault().post( new MediaEvent(RTMedia) );

RTMedia can be an RTImageImpl:
new RTImageImpl(url)

If you want more information about storage scenarios, please read this: https://github.com/1gravity/Android-RTEditor/blob/master/STORAGE.md

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

It's not working =( Which method is called with this post? It's onEventMainThread(MediaEvent event) from the RTManager?

from android-rteditor.

1gravity avatar 1gravity commented on July 18, 2024

Don't even think of calling the onEventMainThread directly ;-).

You're right though, the method I mention above wouldn't work since it's using mActiveEditor to determine in what editor to insert the image. mActiveEditor is usually null though and is only set when the user does the insert manually.

The way to go is to use the insertImage(RTEditText, RTImage) method. It's currently private but can be made public. I tested it but it didn't work and I don't have the time to look into this atm but this is the way to go.

from android-rteditor.

arthursz avatar arthursz commented on July 18, 2024

No problem ;) Thank you very much!

from android-rteditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.