From 72d73f779f6376aaf46f81da85b3ec7ef982db42 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 29 Aug 2019 16:10:11 -0700 Subject: [PATCH] Fix cursor rendering (#2932) * Fixes rendering bugs for cursor and marker --- core/keyboard_nav/cursor_svg.js | 29 +++++++++++++++++++++++++++-- core/keyboard_nav/navigation.js | 1 - 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/keyboard_nav/cursor_svg.js b/core/keyboard_nav/cursor_svg.js index 5a8534ce7..f1e6c7df3 100644 --- a/core/keyboard_nav/cursor_svg.js +++ b/core/keyboard_nav/cursor_svg.js @@ -94,6 +94,18 @@ Blockly.CursorSvg.CURSOR_COLOR = '#cc0a0a'; */ Blockly.CursorSvg.MARKER_COLOR = '#4286f4'; +/** + * The name of the css class for a cursor. + * @const {string} + */ +Blockly.CursorSvg.CURSOR_CLASS = 'blocklyCursor'; + +/** + * The name of the css class for a marker. + * @const {string} + */ +Blockly.CursorSvg.MARKER_CLASS = 'blocklyMarker'; + /** * Parent SVG element. * This is generally a block's SVG root, unless the cursor is on the workspace. @@ -120,7 +132,9 @@ Blockly.CursorSvg.prototype.getSvgRoot = function() { * @return {!Element} The cursor controls SVG group. */ Blockly.CursorSvg.prototype.createDom = function() { - var className = this.isMarker_ ? 'blocklyMarker' : 'blocklyCursor'; + var className = this.isMarker_ ? + Blockly.CursorSvg.MARKER_CLASS : Blockly.CursorSvg.CURSOR_CLASS; + this.svgGroup_ = Blockly.utils.dom.createSvgElement('g', { 'class': className @@ -142,9 +156,20 @@ Blockly.CursorSvg.prototype.setParent_ = function(newParent) { return; } var svgRoot = this.getSvgRoot(); + var cursorNode = null; if (newParent) { - newParent.appendChild(svgRoot); + if (this.isMarker_) { + // Put the marker before the cursor so the cursor does not get covered. + for (var i = 0, childNode; childNode = newParent.childNodes[i]; i++) { + if (Blockly.utils.dom.hasClass(childNode , Blockly.CursorSvg.CURSOR_CLASS)) { + cursorNode = childNode; + } + } + newParent.insertBefore(svgRoot, cursorNode); + } else { + newParent.appendChild(svgRoot); + } this.parent_ = newParent; } }; diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index 02958342d..3d042d1b5 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -132,7 +132,6 @@ Blockly.navigation.setMarker = function(marker) { * @package */ Blockly.navigation.markAtCursor = function() { - // TODO: bring the cursor (blinking) in front of the marker (solid) Blockly.navigation.marker_.setLocation( Blockly.navigation.cursor_.getCurNode()); };