View Javadoc
1   package org.vaadin.aceeditor;
2   
3   import org.vaadin.aceeditor.client.AceRange;
4   import org.vaadin.aceeditor.client.Util;
5   
6   public class TextRange extends AceRange {
7   
8   	private final String text;
9   	int start = -1;
10  	int end = -1;
11  	
12  	public TextRange(String text, int row1, int col1, int row2, int col2) {
13  		super(row1, col1, row2, col2);
14  		this.text = text;
15  	}
16  	
17  	public TextRange(String text, AceRange range) {
18  		this(text, range.getStartRow(), range.getStartCol(), range.getEndRow(), range.getEndCol());
19  	}
20  	
21  	public TextRange(String text, int start, int end) {
22  		this(text, AceRange.fromPositions(start, end, text));
23  	}
24  
25  	public int getStart() {
26  		if (start==-1) {
27  			start = Util.cursorPosFromLineCol(text, getStartRow(), getStartCol(), 0);
28  		}
29  		return start;
30  	}
31  
32  	public int getEnd() {
33  		if (end==-1) {
34  			end = Util.cursorPosFromLineCol(text, getEndRow(), getEndCol(), 0);
35  		}
36  		return end;
37  	}
38  	
39  	public int getCursorPosition() {
40  		return getEnd();
41  	}
42  	
43  	public TextRange withNewText(String newText) {
44  		return new TextRange(newText, getStart(), getEnd());
45  	}
46  	
47  }