mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
Minor cleanup in keyboard nav (#3264)
* Clean cursor code Some obvious inefficiencies that jumped out while randomly browsing the compiled code. * Typos * Multiplying by minus one.
This commit is contained in:
@@ -203,7 +203,7 @@ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function(width,
|
||||
// Bottom.
|
||||
path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1,
|
||||
-this.CORNER_RADIUS, this.CORNER_RADIUS);
|
||||
path.push('h', -1 * width);
|
||||
path.push('h', -width);
|
||||
// Left.
|
||||
path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1,
|
||||
-this.CORNER_RADIUS, -this.CORNER_RADIUS);
|
||||
|
||||
@@ -319,8 +319,8 @@ Blockly.CursorSvg.prototype.showWithStack_ = function(curNode) {
|
||||
var height = heightWidth.height + Blockly.CursorSvg.STACK_PADDING;
|
||||
|
||||
// Shift the rectangle slightly to upper left so padding is equal on all sides.
|
||||
var xPadding = -1 * Blockly.CursorSvg.STACK_PADDING / 2;
|
||||
var yPadding = -1 * Blockly.CursorSvg.STACK_PADDING / 2;
|
||||
var xPadding = -Blockly.CursorSvg.STACK_PADDING / 2;
|
||||
var yPadding = -Blockly.CursorSvg.STACK_PADDING / 2;
|
||||
|
||||
var x = xPadding;
|
||||
var y = yPadding;
|
||||
@@ -354,8 +354,8 @@ Blockly.CursorSvg.prototype.showCurrent_ = function() {
|
||||
* @param {number} cursorHeight The height of the cursor.
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.positionBlock_ = function(width, cursorOffset, cursorHeight) {
|
||||
var cursorPath = Blockly.utils.svgPaths.moveBy(-1 * cursorOffset, cursorHeight) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', -1 * cursorOffset) +
|
||||
var cursorPath = Blockly.utils.svgPaths.moveBy(-cursorOffset, cursorHeight) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', -cursorOffset) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('H', width + cursorOffset * 2) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', cursorHeight);
|
||||
this.cursorBlock_.setAttribute('d', cursorPath);
|
||||
@@ -375,7 +375,7 @@ Blockly.CursorSvg.prototype.positionInput_ = function(connection) {
|
||||
var x = connection.getOffsetInBlock().x;
|
||||
var y = connection.getOffsetInBlock().y;
|
||||
|
||||
var path = Blockly.utils.svgPaths.moveTo(0,0) +
|
||||
var path = Blockly.utils.svgPaths.moveTo(0, 0) +
|
||||
this.constants_.PUZZLE_TAB.pathDown;
|
||||
|
||||
this.cursorInput_.setAttribute('d', path);
|
||||
@@ -408,7 +408,7 @@ Blockly.CursorSvg.prototype.positionLine_ = function(x, y, width) {
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.positionOutput_ = function(width, height) {
|
||||
var cursorPath = Blockly.utils.svgPaths.moveBy(width, 0) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('h', -1 * (width - this.constants_.PUZZLE_TAB.width)) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('h', -(width - this.constants_.PUZZLE_TAB.width)) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('v', this.constants_.TAB_OFFSET_FROM_TOP) +
|
||||
this.constants_.PUZZLE_TAB.pathDown +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', height) +
|
||||
@@ -430,8 +430,8 @@ Blockly.CursorSvg.prototype.positionOutput_ = function(width, height) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.CursorSvg.prototype.positionPrevious_ = function(width, cursorOffset, cursorHeight) {
|
||||
var cursorPath = Blockly.utils.svgPaths.moveBy(-1 * cursorOffset, cursorHeight) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', -1 * cursorOffset) +
|
||||
var cursorPath = Blockly.utils.svgPaths.moveBy(-cursorOffset, cursorHeight) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('V', -cursorOffset) +
|
||||
Blockly.utils.svgPaths.lineOnAxis('H', this.constants_.NOTCH_OFFSET_LEFT) +
|
||||
this.constants_.NOTCH.pathLeft +
|
||||
Blockly.utils.svgPaths.lineOnAxis('H', width + cursorOffset * 2) +
|
||||
@@ -491,24 +491,24 @@ Blockly.CursorSvg.prototype.draw = function(curNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (curNode.getType() === Blockly.ASTNode.types.BLOCK) {
|
||||
if (curNode.getType() == Blockly.ASTNode.types.BLOCK) {
|
||||
var block = /** @type {Blockly.BlockSvg} */ (curNode.getLocation());
|
||||
this.showWithBlockPrevOutput_(block);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.OUTPUT) {
|
||||
} else if (curNode.getType() == Blockly.ASTNode.types.OUTPUT) {
|
||||
var outputBlock = /** @type {Blockly.BlockSvg} */ (curNode.getLocation().getSourceBlock());
|
||||
this.showWithBlockPrevOutput_(outputBlock);
|
||||
} else if (curNode.getLocation().type === Blockly.INPUT_VALUE) {
|
||||
} else if (curNode.getLocation().type == Blockly.INPUT_VALUE) {
|
||||
this.showWithInput_(curNode);
|
||||
} else if (curNode.getLocation().type === Blockly.NEXT_STATEMENT) {
|
||||
} else if (curNode.getLocation().type == Blockly.NEXT_STATEMENT) {
|
||||
this.showWithNext_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.PREVIOUS) {
|
||||
} else if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS) {
|
||||
var previousBlock = /** @type {Blockly.BlockSvg} */ (curNode.getLocation().getSourceBlock());
|
||||
this.showWithBlockPrevOutput_(previousBlock);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.FIELD) {
|
||||
} else if (curNode.getType() == Blockly.ASTNode.types.FIELD) {
|
||||
this.showWithField_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.WORKSPACE) {
|
||||
} else if (curNode.getType() == Blockly.ASTNode.types.WORKSPACE) {
|
||||
this.showWithCoordinates_(curNode);
|
||||
} else if (curNode.getType() === Blockly.ASTNode.types.STACK) {
|
||||
} else if (curNode.getType() == Blockly.ASTNode.types.STACK) {
|
||||
this.showWithStack_(curNode);
|
||||
}
|
||||
|
||||
@@ -545,12 +545,12 @@ Blockly.CursorSvg.prototype.createCursorSvg_ = function() {
|
||||
// A horizontal line used to represent a workspace coordinate or next connection.
|
||||
this.cursorSvgLine_ = Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'x': '0',
|
||||
'y': '0',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
'fill': colour,
|
||||
'width': Blockly.CursorSvg.CURSOR_WIDTH,
|
||||
'height': Blockly.CursorSvg.CURSOR_HEIGHT,
|
||||
'style': 'display: none;'
|
||||
'style': 'display: none'
|
||||
},
|
||||
this.cursorSvg_);
|
||||
|
||||
@@ -558,10 +558,10 @@ Blockly.CursorSvg.prototype.createCursorSvg_ = function() {
|
||||
this.cursorSvgRect_ = Blockly.utils.dom.createSvgElement('rect',
|
||||
{
|
||||
'class': 'blocklyVerticalCursor',
|
||||
'x': '0',
|
||||
'y': '0',
|
||||
'rx': '10', 'ry': '10',
|
||||
'style': 'display: none;',
|
||||
'x': 0,
|
||||
'y': 0,
|
||||
'rx': 10, 'ry': 10,
|
||||
'style': 'display: none',
|
||||
'stroke': colour
|
||||
},
|
||||
this.cursorSvg_);
|
||||
@@ -572,57 +572,42 @@ Blockly.CursorSvg.prototype.createCursorSvg_ = function() {
|
||||
{
|
||||
'width': Blockly.CursorSvg.CURSOR_WIDTH,
|
||||
'height': Blockly.CursorSvg.CURSOR_HEIGHT,
|
||||
'transform':'',
|
||||
'style':'display: none;',
|
||||
'transform': '',
|
||||
'style': 'display: none',
|
||||
'fill': colour
|
||||
},
|
||||
this.cursorSvg_);
|
||||
|
||||
// A path used to repreesent a previous connection and a block, an output
|
||||
// A path used to represent a previous connection and a block, an output
|
||||
// connection and a block, or a block.
|
||||
this.cursorBlock_ = Blockly.utils.dom.createSvgElement(
|
||||
'path',
|
||||
{
|
||||
'width': Blockly.CursorSvg.CURSOR_WIDTH,
|
||||
'height': Blockly.CursorSvg.CURSOR_HEIGHT,
|
||||
'transform':'',
|
||||
'style':'display: none;',
|
||||
'transform': '',
|
||||
'style': 'display: none',
|
||||
'fill': 'none',
|
||||
'stroke': colour,
|
||||
'stroke-width': '4'
|
||||
'stroke-width': 4
|
||||
},
|
||||
this.cursorSvg_);
|
||||
|
||||
// Markers and stack cursors don't blink.
|
||||
if (!this.isMarker_) {
|
||||
Blockly.utils.dom.createSvgElement('animate',
|
||||
{
|
||||
'attributeType': 'XML',
|
||||
'attributeName': 'fill',
|
||||
'dur': '1s',
|
||||
'values': Blockly.CursorSvg.CURSOR_COLOR + ';transparent;transparent;',
|
||||
'repeatCount': 'indefinite'
|
||||
},
|
||||
var properties = {
|
||||
'attributeType': 'XML',
|
||||
'attributeName': 'fill',
|
||||
'dur': '1s',
|
||||
'values': Blockly.CursorSvg.CURSOR_COLOR + ';transparent;transparent;',
|
||||
'repeatCount': 'indefinite'
|
||||
};
|
||||
Blockly.utils.dom.createSvgElement('animate', properties,
|
||||
this.cursorSvgLine_);
|
||||
|
||||
Blockly.utils.dom.createSvgElement('animate',
|
||||
{
|
||||
'attributeType': 'XML',
|
||||
'attributeName': 'fill',
|
||||
'dur': '1s',
|
||||
'values': Blockly.CursorSvg.CURSOR_COLOR + ';transparent;transparent;',
|
||||
'repeatCount': 'indefinite'
|
||||
},
|
||||
Blockly.utils.dom.createSvgElement('animate', properties,
|
||||
this.cursorInput_);
|
||||
|
||||
Blockly.utils.dom.createSvgElement('animate',
|
||||
{
|
||||
'attributeType': 'XML',
|
||||
'attributeName': 'stroke',
|
||||
'dur': '1s',
|
||||
'values': Blockly.CursorSvg.CURSOR_COLOR + ';transparent;transparent;',
|
||||
'repeatCount': 'indefinite'
|
||||
},
|
||||
properties['attributeName'] = 'stroke';
|
||||
Blockly.utils.dom.createSvgElement('animate', properties,
|
||||
this.cursorBlock_);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,8 +330,8 @@ Blockly.navigation.modify_ = function() {
|
||||
markerLoc = /** @type {!Blockly.Connection} */ (markerLoc);
|
||||
return Blockly.navigation.connect_(cursorLoc, markerLoc);
|
||||
} else if (markerNode.isConnection() &&
|
||||
(cursorType == Blockly.ASTNode.types.BLOCK ||
|
||||
cursorType == Blockly.ASTNode.types.STACK)) {
|
||||
(cursorType == Blockly.ASTNode.types.BLOCK ||
|
||||
cursorType == Blockly.ASTNode.types.STACK)) {
|
||||
cursorLoc = /** @type {!Blockly.Block} */ (cursorLoc);
|
||||
markerLoc = /** @type {!Blockly.Connection} */ (markerLoc);
|
||||
return Blockly.navigation.insertBlock(cursorLoc, markerLoc);
|
||||
@@ -374,7 +374,7 @@ Blockly.navigation.disconnectChild_ = function(movingConnection, destConnection)
|
||||
* @private
|
||||
*/
|
||||
Blockly.navigation.moveAndConnect_ = function(movingConnection, destConnection) {
|
||||
if (!movingConnection || ! destConnection) {
|
||||
if (!movingConnection || !destConnection) {
|
||||
return false;
|
||||
}
|
||||
var movingBlock = movingConnection.getSourceBlock();
|
||||
@@ -951,7 +951,8 @@ Blockly.navigation.ACTION_PREVIOUS = new Blockly.Action(
|
||||
* @type {!Blockly.Action}
|
||||
*/
|
||||
Blockly.navigation.ACTION_OUT = new Blockly.Action(
|
||||
Blockly.navigation.actionNames.OUT, 'Go to the parent of the current location.');
|
||||
Blockly.navigation.actionNames.OUT,
|
||||
'Go to the parent of the current location.');
|
||||
|
||||
/**
|
||||
* The next action.
|
||||
@@ -965,7 +966,8 @@ Blockly.navigation.ACTION_NEXT = new Blockly.Action(
|
||||
* @type {!Blockly.Action}
|
||||
*/
|
||||
Blockly.navigation.ACTION_IN = new Blockly.Action(
|
||||
Blockly.navigation.actionNames.IN, 'Go to the first child of the current location.');
|
||||
Blockly.navigation.actionNames.IN,
|
||||
'Go to the first child of the current location.');
|
||||
|
||||
/**
|
||||
* The action to try to insert a block.
|
||||
@@ -987,8 +989,8 @@ Blockly.navigation.ACTION_MARK = new Blockly.Action(
|
||||
* @type {!Blockly.Action}
|
||||
*/
|
||||
Blockly.navigation.ACTION_DISCONNECT = new Blockly.Action(
|
||||
Blockly.navigation.actionNames.DISCONNECT, 'Dicsonnect the block at the' +
|
||||
'current location from its parent.');
|
||||
Blockly.navigation.actionNames.DISCONNECT,
|
||||
'Disconnect the block at the current location from its parent.');
|
||||
|
||||
/**
|
||||
* The action to open the toolbox.
|
||||
@@ -1002,14 +1004,16 @@ Blockly.navigation.ACTION_TOOLBOX = new Blockly.Action(
|
||||
* @type {!Blockly.Action}
|
||||
*/
|
||||
Blockly.navigation.ACTION_EXIT = new Blockly.Action(
|
||||
Blockly.navigation.actionNames.EXIT, 'Close the current modal, such as a toolbox or field editor.');
|
||||
Blockly.navigation.actionNames.EXIT,
|
||||
'Close the current modal, such as a toolbox or field editor.');
|
||||
|
||||
/**
|
||||
* The action to toggle keyboard navigation mode on and off.
|
||||
* @type {!Blockly.Action}
|
||||
*/
|
||||
Blockly.navigation.ACTION_TOGGLE_KEYBOARD_NAV = new Blockly.Action(
|
||||
Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV, 'Turns on and off keyboard navigation.');
|
||||
Blockly.navigation.actionNames.TOGGLE_KEYBOARD_NAV,
|
||||
'Turns on and off keyboard navigation.');
|
||||
|
||||
/**
|
||||
* List of actions that can be performed in read only mode.
|
||||
|
||||
@@ -96,9 +96,9 @@ Blockly.zelos.ConstantProvider.prototype.makeHexagonal = function() {
|
||||
var width = height / 2;
|
||||
var forward = up ? -1 : 1;
|
||||
var direction = right ? -1 : 1;
|
||||
|
||||
return Blockly.utils.svgPaths.lineTo(-1 * direction * width, forward * height / 2) +
|
||||
Blockly.utils.svgPaths.lineTo(direction * width, forward * height / 2);
|
||||
var dy = forward * height / 2;
|
||||
return Blockly.utils.svgPaths.lineTo(-direction * width, dy) +
|
||||
Blockly.utils.svgPaths.lineTo(direction * width, dy);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user