Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -22,7 +22,13 @@ |
23 | 23 | }; |
24 | 24 | this.keyboard = { |
25 | 25 | 'selecting': false, |
26 | | - 'keydownTimeout': null |
| 26 | + 'keydownTimeout': null, |
| 27 | + 'keys': { |
| 28 | + 'shift': false, |
| 29 | + 'control': false, |
| 30 | + 'command': false, |
| 31 | + 'alt': false |
| 32 | + } |
27 | 33 | }; |
28 | 34 | |
29 | 35 | // MouseDown on surface |
— | — | @@ -122,7 +128,7 @@ |
123 | 129 | es.Surface.prototype.onKeyDown = function( e ) { |
124 | 130 | switch ( e.keyCode ) { |
125 | 131 | case 16: // Shift |
126 | | - this.shiftDown = true; |
| 132 | + this.keyboard.keys.shift = true; |
127 | 133 | if ( !this.keyboard.selecting ) { |
128 | 134 | this.keyboard.selecting = true; |
129 | 135 | if ( !this.selection.to ) { |
— | — | @@ -132,18 +138,18 @@ |
133 | 139 | } |
134 | 140 | break; |
135 | 141 | case 17: // Control |
136 | | - this.ctrlDown = true; |
| 142 | + this.keyboard.keys.control = true; |
137 | 143 | break; |
138 | 144 | case 18: // Alt |
139 | | - this.altDown = true; |
| 145 | + this.keyboard.keys.alt = true; |
140 | 146 | break; |
141 | 147 | case 91: // Command |
142 | | - this.commandDown = true; |
| 148 | + this.keyboard.keys.command = true; |
143 | 149 | break; |
144 | 150 | case 37: // Left arrow |
145 | 151 | this.initialHorizontalCursorPosition = null; |
146 | 152 | this.moveCursorLeft(); |
147 | | - if ( this.shiftDown && this.keyboard.selecting ) { |
| 153 | + if ( this.keyboard.keys.shift && this.keyboard.selecting ) { |
148 | 154 | this.selection.to = this.location; |
149 | 155 | } else { |
150 | 156 | this.selection = new es.Selection(); |
— | — | @@ -152,7 +158,7 @@ |
153 | 159 | break; |
154 | 160 | case 38: // Up arrow |
155 | 161 | this.moveCursorUp(); |
156 | | - if ( this.shiftDown && this.keyboard.selecting ) { |
| 162 | + if ( this.keyboard.keys.shift && this.keyboard.selecting ) { |
157 | 163 | this.selection.to = this.location; |
158 | 164 | } else { |
159 | 165 | this.selection = new es.Selection(); |
— | — | @@ -162,7 +168,7 @@ |
163 | 169 | case 39: // Right arrow |
164 | 170 | this.initialHorizontalCursorPosition = null; |
165 | 171 | this.moveCursorRight(); |
166 | | - if ( this.shiftDown && this.keyboard.selecting ) { |
| 172 | + if ( this.keyboard.keys.shift && this.keyboard.selecting ) { |
167 | 173 | this.selection.to = this.location; |
168 | 174 | } else { |
169 | 175 | this.selection = new es.Selection(); |
— | — | @@ -171,7 +177,7 @@ |
172 | 178 | break; |
173 | 179 | case 40: // Down arrow |
174 | 180 | this.moveCursorDown(); |
175 | | - if ( this.shiftDown && this.keyboard.selecting ) { |
| 181 | + if ( this.keyboard.keys.shift && this.keyboard.selecting ) { |
176 | 182 | this.selection.to = this.location; |
177 | 183 | } else { |
178 | 184 | this.selection = new es.Selection(); |
— | — | @@ -186,7 +192,7 @@ |
187 | 193 | this.handleDelete(); |
188 | 194 | break; |
189 | 195 | default: |
190 | | - if ( this.ctrlDown || this.altDown || this.commandDown ) { |
| 196 | + if ( this.keyboard.keys.control || this.keyboard.keys.alt || this.keyboard.keys.command ) { |
191 | 197 | break; |
192 | 198 | } |
193 | 199 | this.initialHorizontalCursorPosition = null; |
— | — | @@ -242,21 +248,21 @@ |
243 | 249 | es.Surface.prototype.onKeyUp = function( e ) { |
244 | 250 | switch ( e.keyCode ) { |
245 | 251 | case 16: // Shift |
246 | | - this.shiftDown = false; |
| 252 | + this.keyboard.keys.shift = false; |
247 | 253 | if ( this.keyboard.selecting ) { |
248 | 254 | this.keyboard.selecting = false; |
249 | 255 | } |
250 | 256 | break; |
251 | 257 | case 17: // Control |
252 | | - this.ctrlDown = false; |
| 258 | + this.keyboard.keys.control = false; |
253 | 259 | break; |
254 | 260 | case 18: // Alt |
255 | | - this.altDown = false; |
| 261 | + this.keyboard.keys.alt = false; |
256 | 262 | break; |
257 | 263 | case 91: // Command |
258 | | - this.commandDown = false; |
| 264 | + this.keyboard.keys.command = false; |
259 | 265 | break; |
260 | | - default: |
| 266 | + default: |
261 | 267 | break; |
262 | 268 | } |
263 | 269 | return true; |
— | — | @@ -317,8 +323,12 @@ |
318 | 324 | this.location = this.getLocationFromEvent( e ); |
319 | 325 | switch ( this.mouse.clicks ) { |
320 | 326 | case 1: |
321 | | - // Clear selection and move cursor to nearest offset |
322 | | - this.selection = new es.Selection( this.location ); |
| 327 | + if ( this.keyboard.keys.shift ) { |
| 328 | + this.selection = new es.Selection( this.selection.from, this.location ); |
| 329 | + } else { |
| 330 | + // Clear selection and move cursor to nearest offset |
| 331 | + this.selection = new es.Selection( this.location ); |
| 332 | + } |
323 | 333 | var cursorPosition = this.location.block.getPosition( this.location.offset ); |
324 | 334 | this.cursor.show( cursorPosition, this.location.block.$.offset() ); |
325 | 335 | this.$input.css( 'top', cursorPosition.top ); |