Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 381
- Log:
Radiant is now packaged as a Gem - see Changeset #373, Changeset #374,
Changeset #375, Changeset #376, Changeset #377, Changeset #378,
Changeset #379 and Changeset #380. The application part of Radiant is
now mostly empty; it exists to provide a structure which hooks into the
gem and which provides a framework for extensions. Included in this big
changeset are all the deletions, additions and changes needed to go from
the old ROOL customised Radiant to a new ROOL customised Radiant, which
includes several custom extensions adapted from the old Radiant
modifications and requires Radiant 0.9.1 to be installed as a gem.
- Author:
- rool
- Date:
- Mon Mar 21 14:01:18 +0000 2011
- Size:
- 5966 Bytes
1 | // Originally based on code from: |
2 | // http://ajaxian.com/archives/handling-tabs-in-textareas |
3 | |
4 | var CodeAreaBehavior = Behavior.create({ |
5 | initialize: function() { |
6 | new CodeArea(this.element); |
7 | } |
8 | }); |
9 | |
10 | var CodeArea = Class.create({ |
11 | initialize: function(element) { |
12 | this.element = $(element); |
13 | this.element.observe('keydown', this.onkeydown.bind(this)); |
14 | }, |
15 | |
16 | onkeydown: function(event) { |
17 | // Set desired tab - defaults to two space softtab |
18 | var tab = " "; |
19 | var tabStop = tab.length; |
20 | |
21 | var t = this.element; |
22 | |
23 | if (Prototype.Browser.IE) { |
24 | // Very limited support for IE |
25 | |
26 | if (event.keyCode == Event.KEY_TAB && !event.shiftKey) { |
27 | event.preventDefault(); |
28 | document.selection.createRange().text = tab; |
29 | } |
30 | |
31 | } else { |
32 | // Safari and Firefox |
33 | |
34 | // If this is the tab key, make the selection start at the begining and end of lines for |
35 | // multi-line selections |
36 | if (event.keyCode == Event.KEY_TAB) this.normalizeSelection(t); |
37 | |
38 | var ss = t.selectionStart; |
39 | var se = t.selectionEnd; |
40 | |
41 | if (event.keyCode == Event.KEY_TAB) { |
42 | // Tab key |
43 | |
44 | event.preventDefault(); |
45 | |
46 | if (event.shiftKey) { |
47 | // Shift + Tab |
48 | |
49 | if (t.value.slice(ss,se).indexOf("\n") != -1) { |
50 | // Special case of multi line selection |
51 | |
52 | var pre = t.value.slice(0, ss) |
53 | var sel = t.value.slice(ss, se) |
54 | var post = t.value.slice(se, t.value.length); |
55 | |
56 | // Back off one tab |
57 | sel = sel.replace(new RegExp("^" + tab, "gm"), '') |
58 | |
59 | // Put everything back together |
60 | t.value = pre.concat(sel).concat(post); |
61 | |
62 | // Readjust the selection |
63 | t.selectionStart = pre.length; |
64 | t.selectionEnd = pre.length + sel.length; |
65 | |
66 | } else { |
67 | // "Normal" case (no selection or selection on one line only) |
68 | |
69 | if (t.value.slice(ss - tabStop, ss) == tab) { |
70 | // Only unindent if there is a tab before the cursor |
71 | |
72 | t.value = t.value.slice(0, ss - tabStop).concat(t.value.slice(ss, t.value.length)); |
73 | t.selectionStart = ss - tabStop; |
74 | t.selectionEnd = se - tabStop; |
75 | } |
76 | } |
77 | } else { |
78 | // Tab |
79 | |
80 | if (ss != se && t.value.slice(ss, se).indexOf("\n") != -1) { |
81 | // Special case of multi line selection |
82 | |
83 | // In case selection was not of entire lines (e.g. selection begins in the middle of a line) |
84 | // we ought to tab at the beginning as well as at the start of every following line. |
85 | var pre = t.value.slice(0, ss); |
86 | var sel = t.value.slice(ss, se); |
87 | var post = t.value.slice(se, t.value.length); |
88 | |
89 | // Indent one tab |
90 | sel = sel.replace(/^/gm, tab) |
91 | |
92 | // Put everything back together |
93 | t.value = pre.concat(sel).concat(post); |
94 | |
95 | // Readjust the selection |
96 | t.selectionStart = pre.length; |
97 | t.selectionEnd = pre.length + sel.length; |
98 | |
99 | } else { |
100 | // "Normal" case (no selection or selection on one line only) |
101 | |
102 | t.value = t.value.slice(0, ss).concat(tab).concat(t.value.slice(ss, t.value.length)); |
103 | if (ss == se) { |
104 | t.selectionStart = t.selectionEnd = ss + tabStop; |
105 | } else { |
106 | t.selectionStart = ss + tabStop; |
107 | t.selectionEnd = se + tabStop; |
108 | } |
109 | } |
110 | } |
111 | |
112 | } else if (event.keyCode == Event.KEY_BACKSPACE && ss == se && t.value.slice(ss - tabStop, ss) == tab) { |
113 | // Backspace - delete preceding tab expansion, if it exists and nothing is selected |
114 | |
115 | event.preventDefault(); |
116 | t.value = t.value.slice(0, ss - tabStop).concat(t.value.slice(ss, t.value.length)); |
117 | t.selectionStart = ss - tabStop; |
118 | t.selectionEnd = se - tabStop; |
119 | |
120 | } else if (event.keyCode == Event.KEY_DELETE && t.value.slice(se, se + tabStop) == tab) { |
121 | // Delete key - delete following tab expansion, if exists |
122 | |
123 | event.preventDefault(); |
124 | t.value = t.value.slice(0, ss).concat(t.value.slice(ss + tabStop ,t.value.length)); |
125 | t.selectionStart = t.selectionEnd = ss; |
126 | |
127 | } else if (event.keyCode == Event.KEY_LEFT && t.value.slice(ss - tabStop, ss) == tab) { |
128 | // Left arrow - move across the tab in one go |
129 | |
130 | event.preventDefault(); |
131 | t.selectionStart = t.selectionEnd = ss - tabStop; |
132 | } else if (event.keyCode == Event.KEY_RIGHT && t.value.slice(ss, ss + tabStop) == tab) { |
133 | // Left/right arrow - move across the tab in one go |
134 | |
135 | event.preventDefault(); |
136 | t.selectionStart = t.selectionEnd = ss + tabStop; |
137 | |
138 | } |
139 | } |
140 | }, |
141 | |
142 | normalizeSelection: function(textarea) { |
143 | var b = 0; |
144 | var value = textarea.value; |
145 | var e = textarea.length; |
146 | var ss = textarea.selectionStart; |
147 | var se = textarea.selectionEnd; |
148 | |
149 | if (ss != se && textarea.value.slice(ss, se).indexOf("\n") != -1) { |
150 | // If multi-line adjust the selection |
151 | |
152 | // If the end of the line is selected back off one character |
153 | if (textarea.value.slice(se - 1, se) == "\n") se = se - 1; |
154 | |
155 | // If the selection does not end with a new line or the end of the document increment until it does |
156 | while ((se < e) && (textarea.value.slice(se, se + 1) != "\n")) se += 1; |
157 | |
158 | // If the selection does not begin at a new line or the begining of the document back off until it does |
159 | while ((ss > b) && (textarea.value.slice(ss - 1, ss) != "\n")) ss -= 1; |
160 | |
161 | textarea.selectionStart = ss; |
162 | textarea.selectionEnd = se; |
163 | } |
164 | } |
165 | }); |