imhoffd/jquery-textrange

ReplaceAt method

Closed this issue · 5 comments

First of all, thanks for this plugin, really useful!

Now I will suggest a feature that can help a lot of people. Now we can get the text between two positions, but we don't have a method to replace this.

Okay, have "replace", but this replaces based on text. Sometimes developers need replace text by position, like:

"The text between positions 3 and 10 will be replaced with 'foobar' ".

Understand what I want mean? My feature suggestion is that, make a method to replace at two given positions, like this:

replaceAt(startPosition, endPosition, newValue)

What you think?

You're welcome!

The replace method simply replaces selected text with a string. Right now you can do this by using set first and then replace. However, it might be useful to some people to have this.

Oh, when you use set and then replace it forces a set selection.
Are you hoping to replace text without modifying the selection?

In my project I have in one div:

blablabla here I want to change ahudshuasd

I get the data-start and data-end, and I want replace everything inside this tag, but in a textarea (because this I need use positions, in textarea can't use ). I already do that with a custom method, but I think it will be very useful if coded in this plugin.

It might be cool to extend the functionality of this beyond textareas and text input. I guess I never thought about that.