mirror of
https://github.com/google/blockly.git
synced 2026-01-12 11:27:14 +01:00
Fix cursor rendering (#2932)
* Fixes rendering bugs for cursor and marker
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user