Can't select text in TinyMCE

Hi everybody

I’m trying to use the Addon "
Vaadin wrapper for TinyMCE
".
In my Application there is the editor and a button. After click on the button i want select a range of the text in the editor. Here are an example:

VerticalLayout layout = new VerticalLayout();

textArea = new TinyMCETextField();
textArea.setImmediate(true);
textArea.setValue("Hi everybody<br>Welcome");

layout.addComponent(textArea);

Button bu = new Button();
bu.addListener(new ClickListener() {

	@Override
	public void buttonClick(ClickEvent event) {
	        textArea.setSelectionRange(0, 3);
	}
});

layout.addComponent(bu);

Unfortunately it doesn’t work. I’ve even tried the selectAll()-method but it doesn’t work too.

Is there are a refresh problem? If i use the SetValue()-methed of the TinyMCE in the Listener the text value change without any problems.
Hope anyone give me a hint.

Greets

Hi,

I think the TinyMCE wrapper don’t support text selection API. The api is much newer then the add-on and I haven’ found time to update it. I guess it might be rather easy to implement such a feature though.

cheers,
matti

Hi

inspired from this sentence, i tried the following. :slight_smile:
I create a new Class which extends the TinyMCETextField.

public class EditorTiny extends TinyMCETextField {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String pos;
	private String length;

	public EditorTiny() {
		
	}
	
	public void setPosForSelection(int pos) {
		this.pos = String.valueOf(pos);
	}
	
	public void setLengthForSelection(int length){
		this.length = String.valueOf(length);
	}
	
	@Override
	public void paintContent(PaintTarget target) throws PaintException {
		super.paintContent(target);
		if (pos != null) {
			target.addAttribute("selpos", pos);
		}
		if (length != null) {
			target.addAttribute("sellen", length);
		}
	}
}

Within my Clicklistener I set the attributes pos and length:

textArea.setPosForSelection(0);
textArea.setLengthForSelection(3);

I thought this will help but it didn’t. What I do wrong?

Greets

Hi,

The client side implementation (probably same name but start with “V”) should also use those attributes that you send to browser. On the client side you also probably also need a small extension to the TinyMCE wrapper, which practically means JSNI api for the javascript API provided by TinyMCE library.

cheers,
matti

Hi

i’ve tried it many times and in different ways but i still don’t get it. I hope this feature will be in your next update. thx

Greets