1 /**
2  * Index module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.common.index;
8 
9 /**
10  * These are common commands that apply to all widgets that have them injected.
11  */
12 mixin template Index()
13 {
14 	/**
15 	 * Get the length of the text.
16 	 *
17 	 * Returns:
18 	 *     The length of the text.
19 	 */
20 	public int getTextLength()
21 	{
22 		this._tk.eval("%s index end", this.id);
23 		return this._tk.getResult!(int);
24 	}
25 
26 	/**
27 	 * Get the index where the insert cursor is.
28 	 *
29 	 * Returns:
30 	 *     An int of the index where the insert cursor is.
31 	 */
32 	public int getCursorIndex()
33 	{
34 		this._tk.eval("%s index insert", this.id);
35 		return this._tk.getResult!(int);
36 	}
37 
38 	/**
39 	 * Get the start and end indexes of the text selection if there is one.
40 	 *
41 	 * Returns:
42 	 *     An array holding the start and end indexes of a text selection.
43 	 */
44 	public int[] getSelectedTextIndices()
45 	{
46 		int[] result;
47 
48 		this._tk.eval("%s index sel.first", this.id);
49 		result ~= this._tk.getResult!(int);
50 
51 		this._tk.eval("%s index sel.last", this.id);
52 		result ~= this._tk.getResult!(int);
53 
54 		return result;
55 	}
56 
57 }