mirror of
https://github.com/google/blockly.git
synced 2026-01-05 08:00:09 +01:00
Move marker creation to the workspace (#2742)
* Move marker creation to the workspace
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user