diff --git src/wp-includes/js/tinymce/plugins/wpview/plugin.js src/wp-includes/js/tinymce/plugins/wpview/plugin.js
index 48775f9..e284a21 100644
|
|
tinymce.PluginManager.add( 'wpview', function( editor ) { |
86 | 86 | editor.dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop ); |
87 | 87 | editor.dom.bind( selected, 'beforedeactivate focusin focusout', _stop ); |
88 | 88 | |
| 89 | // Make sure that the editor is focused. |
| 90 | // It is possible that the editor is not focused when the mouse event fires |
| 91 | // without focus, the selection will not work properly. |
| 92 | editor.getBody().focus(); |
| 93 | |
89 | 94 | // select the hidden div |
90 | 95 | editor.selection.select( clipboard, true ); |
91 | 96 | } |
… |
… |
tinymce.PluginManager.add( 'wpview', function( editor ) { |
156 | 161 | editor.selection.setCursorLocation( padNode, 0 ); |
157 | 162 | } |
158 | 163 | } |
159 | | |
160 | | // refreshEmptyContentNode(); |
161 | 164 | }); |
162 | 165 | |
163 | 166 | // Detect mouse down events that are adjacent to a view when a view is the first view or the last view |
… |
… |
tinymce.PluginManager.add( 'wpview', function( editor ) { |
188 | 191 | } |
189 | 192 | |
190 | 193 | if ( padNode ) { |
| 194 | // Make sure that a selected view is deselected so that focus and selection are handled properly |
| 195 | deselect(); |
| 196 | editor.getBody().focus(); |
191 | 197 | editor.selection.setCursorLocation( padNode, 0 ); |
192 | 198 | } |
193 | 199 | } |
… |
… |
tinymce.PluginManager.add( 'wpview', function( editor ) { |
298 | 304 | |
299 | 305 | editor.on( 'keydown', function( event ) { |
300 | 306 | var keyCode = event.keyCode, |
301 | | view; |
| 307 | body = editor.getBody(), |
| 308 | view, padNode; |
302 | 309 | |
303 | 310 | // If a view isn't selected, let the event go on its merry way. |
304 | 311 | if ( ! selected ) { |
… |
… |
tinymce.PluginManager.add( 'wpview', function( editor ) { |
323 | 330 | return; |
324 | 331 | } |
325 | 332 | |
| 333 | if ( keyCode === VK.LEFT || keyCode === VK.UP ) { |
| 334 | deselect(); |
| 335 | if ( isView( view.previousSibling ) ) { |
| 336 | select( view.previousSibling ); |
| 337 | } else if ( view.previousSibling === null ) { |
| 338 | padNode = createPadNode(); |
| 339 | body.insertBefore( padNode, body.firstChild ); |
| 340 | editor.selection.setCursorLocation( body.firstChild, 0 ); |
| 341 | } else { |
| 342 | editor.selection.select( view.previousSibling, true ); |
| 343 | editor.selection.collapse(); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { |
| 348 | deselect(); |
| 349 | if ( isView( view.nextSibling ) ) { |
| 350 | select( view.nextSibling ); |
| 351 | } else if ( view.nextSibling === null ) { |
| 352 | padNode = createPadNode(); |
| 353 | body.appendChild( padNode ); |
| 354 | editor.selection.setCursorLocation( body.lastChild, 0 ); |
| 355 | |
| 356 | } else { |
| 357 | editor.selection.setCursorLocation( view.nextSibling.firstChild, 0 ); |
| 358 | } |
| 359 | } |
| 360 | |
326 | 361 | // If delete or backspace is pressed, delete the view. |
327 | 362 | if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { |
328 | 363 | editor.dom.remove( selected ); |
… |
… |
tinymce.PluginManager.add( 'wpview', function( editor ) { |
331 | 366 | event.preventDefault(); |
332 | 367 | }); |
333 | 368 | |
| 369 | // Select and deselect views when arrow keys are used to navigate the content of the editor. |
| 370 | editor.on( 'keydown', function( event ) { |
| 371 | var keyCode = event.keyCode, |
| 372 | range = editor.selection.getRng(); |
| 373 | |
| 374 | if ( range.collapsed !== true ) { |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | if ( keyCode === VK.LEFT || keyCode === VK.UP ) { |
| 379 | if ( range.startOffset === 0 && isView( range.startContainer.parentNode.previousSibling ) ) { |
| 380 | select( range.startContainer.parentNode.previousSibling ); |
| 381 | event.preventDefault(); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) { |
| 386 | if ( range.startOffset === range.endContainer.length && isView( range.startContainer.parentNode.nextSibling ) ) { |
| 387 | select( range.endContainer.parentNode.nextSibling ); |
| 388 | event.preventDefault(); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | } |
| 393 | |
| 394 | |
| 395 | }); |
| 396 | |
334 | 397 | editor.on( 'keyup', function( event ) { |
335 | 398 | var padNode, |
336 | 399 | keyCode = event.keyCode, |