From c533a0d943cee1fbc64a76dd7ddc9dd1e7752145 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 18 Sep 2019 11:55:01 -0700 Subject: [PATCH] Setting cursor and marker directly in Workspace and adding check to setCursor/setDrawer. --- core/keyboard_nav/cursor_svg.js | 3 +-- core/workspace.js | 8 ++------ core/workspace_svg.js | 25 ++++++++++++------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/core/keyboard_nav/cursor_svg.js b/core/keyboard_nav/cursor_svg.js index e0731da4a..1bf28459c 100644 --- a/core/keyboard_nav/cursor_svg.js +++ b/core/keyboard_nav/cursor_svg.js @@ -68,8 +68,7 @@ Blockly.CursorSvg = function(workspace, opt_marker) { * @type {Blockly.blockRendering.ConstantProvider} * @private */ - this.constants_ = new Blockly.blockRendering.ConstantProvider(); - this.constants_.init(); + this.constants_ = workspace.getRenderer().getConstants(); }; /** diff --git a/core/workspace.js b/core/workspace.js index dcc56b787..a858a11d7 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -122,24 +122,20 @@ Blockly.Workspace = function(opt_options) { * @type {Blockly.Cursor} * @protected */ - this.cursor_ = null; + this.cursor_ = new Blockly.Cursor(); /** * The marker used to mark a location for keyboard navigation. * @type {Blockly.MarkerCursor} * @protected */ - this.marker_ = null; + this.marker_ = new Blockly.MarkerCursor(); // Set the default theme. This is for headless workspaces. This will get // overwritten by the theme passed into the inject call for rendered workspaces. if (!Blockly.getTheme()) { Blockly.setTheme(Blockly.Themes.Classic); } - - this.setCursor(new Blockly.Cursor()); - - this.setMarker(new Blockly.MarkerCursor()); }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 630039bd1..b8648cb2f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -139,16 +139,16 @@ Blockly.WorkspaceSvg = function(options, this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME, Blockly.Procedures.flyoutCategory); } + + /** + * The block renderer used for rendering blocks on this workspace. + * @type {!Blockly.blockRendering.Renderer} + * @private + */ + this.renderer_ = Blockly.blockRendering.init(this.options.renderer || 'geras'); }; Blockly.utils.object.inherits(Blockly.WorkspaceSvg, Blockly.Workspace); -/** - * The block renderer used for rendering blocks on this workspace. - * @type {!Blockly.blockRendering.Renderer} - * @private - */ -Blockly.WorkspaceSvg.prototype.renderer_ = undefined; - /** * A wrapper function called when a resize event occurs. * You can pass the result to `unbindEvent_`. @@ -419,20 +419,17 @@ Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_ = true; * @return {!Blockly.blockRendering.Renderer} The renderer attached to this workspace. */ Blockly.WorkspaceSvg.prototype.getRenderer = function() { - if (!this.renderer_) { - this.renderer_ = - Blockly.blockRendering.init(this.options.renderer || 'geras'); - } return this.renderer_; }; /** * Sets the cursor for use with keyboard navigation. + * * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. * @override */ Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) { - if (this.cursor_) { + if (this.cursor_ && this.cursor_.getDrawer()) { this.cursor_.getDrawer().dispose(); } this.cursor_ = cursor; @@ -449,7 +446,7 @@ Blockly.WorkspaceSvg.prototype.setCursor = function(cursor) { * @override */ Blockly.WorkspaceSvg.prototype.setMarker = function(marker) { - if (this.marker_) { + if (this.marker_ && this.marker_.getDrawer()) { this.marker_.getDrawer().dispose(); } this.marker_ = marker; @@ -666,9 +663,11 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { } this.recordDeleteAreas(); + this.cursor_.setDrawer(this.getRenderer().makeCursorDrawer(this, false)); var svgCursor = this.cursor_.getDrawer().createDom(); this.svgGroup_.appendChild(svgCursor); + this.marker_.setDrawer(this.getRenderer().makeCursorDrawer(this, true)); var svgMarker = this.marker_.getDrawer().createDom(); this.svgGroup_.appendChild(svgMarker);