From 9466c6b7df5b2372eeb2e99f1803c555a8a5363e Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 31 Jul 2019 09:04:53 -0700 Subject: [PATCH] Move marker creation to the workspace (#2742) * Move marker creation to the workspace --- core/keyboard_nav/cursor.js | 12 +++++++++++- core/keyboard_nav/cursor_svg.js | 10 +++++----- core/workspace.js | 15 +++++++++++++++ core/workspace_svg.js | 6 ------ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 1d42529ee..d54bb2a10 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -29,15 +29,25 @@ goog.provide('Blockly.Cursor'); /** * Class for a cursor. + * @param {boolean=} opt_marker True if the cursor is a marker. A marker is used + * to save a location and is an immovable cursor. False or undefined if the + * cursor is not a marker. * @constructor */ -Blockly.Cursor = function() { +Blockly.Cursor = function(opt_marker) { /* * The current location of the cursor. * @type {Blockly.Field|Blockly.Connection|Blockly.Block} * @private */ this.curNode_ = null; + + /** + * Whether or not the cursor is a marker. + * @type {boolean} True if the cursor is a marker. False otherwise. + * @private + */ + this.isMarker_ = !!opt_marker; }; /** diff --git a/core/keyboard_nav/cursor_svg.js b/core/keyboard_nav/cursor_svg.js index e291269a9..fc0f825ea 100644 --- a/core/keyboard_nav/cursor_svg.js +++ b/core/keyboard_nav/cursor_svg.js @@ -32,15 +32,15 @@ goog.require('Blockly.Cursor'); /** * Class for a cursor. * @param {!Blockly.Workspace} workspace The workspace to sit in. - * @param {boolean=} opt_isImmovable True if the cursor cannot be moved with - * calls to prev/next/in/out. This is called a marker. + * @param {boolean=} opt_marker True if the cursor is a marker. A marker is used + * to save a location and is an immovable cursor. False or undefined if the + * cursor is not a marker. * @extends {Blockly.Cursor} * @constructor */ -Blockly.CursorSvg = function(workspace, opt_isImmovable) { - Blockly.CursorSvg.superClass_.constructor.call(this); +Blockly.CursorSvg = function(workspace, opt_marker) { + Blockly.CursorSvg.superClass_.constructor.call(this, opt_marker); this.workspace_ = workspace; - this.isMarker_ = opt_isImmovable || false; }; goog.inherits(Blockly.CursorSvg, Blockly.Cursor); diff --git a/core/workspace.js b/core/workspace.js index 6de1a607d..1d0a8b3ee 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -122,6 +122,12 @@ Blockly.Workspace = function(opt_options) { */ this.cursor = this.createCursor(); + /** + * The marker that shows where a user has marked while navigating blocks. + * @type {!Blockly.Cursor} + */ + this.marker = this.createMarker(); + // 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()) { @@ -163,6 +169,15 @@ Blockly.Workspace.prototype.createCursor = function() { return new Blockly.Cursor(); }; +/** + * Adds marker for keyboard navigation. + * @return {!Blockly.Cursor} Cursor for keyboard navigation. + */ +Blockly.Workspace.prototype.createMarker = function() { + return new Blockly.Cursor(true); +}; + + /** * Dispose of this workspace. * Unlink from all DOM elements to prevent memory leaks. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index c6d9d3448..215dad9fa 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -123,12 +123,6 @@ Blockly.WorkspaceSvg = function(options, this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME, Blockly.Procedures.flyoutCategory); } - - /** - * The marker that shows where a user has marked while navigating blocks. - * @type {!Blockly.CursorSvg} - */ - this.marker = this.createMarker(); }; goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);