From cfdcc38907b97773ab011895c9ce9005e8416a3f Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 15 Aug 2017 20:12:35 +0200 Subject: [PATCH] Remove vertical arrow positioning --- editor/modes/visual-editor/block.js | 50 +++-------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index 1fbeafc937ac00..e7cbf6768bf833 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -59,27 +59,7 @@ function FirstChild( { children } ) { return childrenArray[ 0 ] || null; } -function isVerticalEdge( { editor, reverse } ) { - const rangeRect = editor.selection.getBoundingClientRect(); - const buffer = rangeRect.height / 2; - const editableRect = editor.getBody().getBoundingClientRect(); - - isVerticalEdge.firstRect = isVerticalEdge.firstRect || rangeRect; - - // Too low. - if ( reverse && rangeRect.top - buffer > editableRect.top ) { - return false; - } - - // Too high. - if ( ! reverse && rangeRect.bottom + buffer < editableRect.bottom ) { - return false; - } - - return true; -} - -function isHorizontalEdge( { editor, reverse } ) { +function isEdge( { editor, reverse } ) { const position = reverse ? 'start' : 'end'; const order = reverse ? 'first' : 'last'; const range = editor.selection.getRng(); @@ -323,9 +303,6 @@ class VisualEditorBlock extends Component { } onPointerDown( event ) { - // Discard the arrow key position. - delete isVerticalEdge.firstRect; - // Not the main button (usually the left button on pointer device). if ( event.buttons !== 1 ) { return; @@ -358,9 +335,7 @@ class VisualEditorBlock extends Component { if ( editor ) { const reverse = up || left; - const horizontal = left || right; const followingBlock = reverse ? previousBlock : nextBlock; - const isEdge = horizontal ? isHorizontalEdge : isVerticalEdge; if ( ! isEdge( { editor, reverse } ) ) { return; @@ -380,30 +355,15 @@ class VisualEditorBlock extends Component { followingEditor.focus(); - if ( horizontal ) { - if ( reverse ) { - followingEditor.selection.select( followingEditor.getBody(), true ); - followingEditor.selection.collapse( false ); - } + if ( reverse ) { + followingEditor.selection.select( followingEditor.getBody(), true ); + followingEditor.selection.collapse( false ); } else { - const rect = isVerticalEdge.firstRect; - - window.setTimeout( () => { - const buffer = rect.height / 2; - const editorRect = followingEditor.getBody().getBoundingClientRect(); - const y = reverse ? editorRect.bottom - buffer : editorRect.top + buffer; - - followingEditor.selection.placeCaretAt( rect.left, y ); - } ); + followingEditor.selection.setCursorLocation(); } } } - if ( ! up && ! down ) { - // Discard the arrow key position if any other key is pressed. - delete isVerticalEdge.firstRect; - } - if ( ENTER === keyCode && target === this.node ) { event.preventDefault();