-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Move clipboard functions to a separate namespace #5237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9612546
d58a878
714bb61
f7549f7
f72c5ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| goog.provide('Blockly'); | ||
|
|
||
| goog.require('Blockly.browserEvents'); | ||
| goog.require('Blockly.clipboard'); | ||
| goog.require('Blockly.ComponentManager'); | ||
| goog.require('Blockly.connectionTypes'); | ||
| goog.require('Blockly.constants'); | ||
|
|
@@ -91,27 +92,6 @@ Blockly.selected = null; | |
| */ | ||
| Blockly.draggingConnections = []; | ||
|
|
||
| /** | ||
| * Contents of the local clipboard. | ||
| * @type {Element} | ||
| * @private | ||
| */ | ||
| Blockly.clipboardXml_ = null; | ||
|
|
||
| /** | ||
| * Source of the local clipboard. | ||
| * @type {Blockly.WorkspaceSvg} | ||
| * @private | ||
| */ | ||
| Blockly.clipboardSource_ = null; | ||
|
|
||
| /** | ||
| * Map of types to type counts for the clipboard object and descendants. | ||
| * @type {Object} | ||
| * @private | ||
| */ | ||
| Blockly.clipboardTypeCounts_ = null; | ||
|
|
||
| /** | ||
| * Cached value for whether 3D is supported. | ||
| * @type {?boolean} | ||
|
|
@@ -136,9 +116,7 @@ Blockly.svgSize = function(svg) { | |
| // When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_ | ||
| // from setCachedParentSvgSize. | ||
| Blockly.utils.deprecation.warn( | ||
| 'Blockly.svgSize', | ||
| 'March 2021', | ||
| 'March 2022', | ||
| 'Blockly.svgSize', 'March 2021', 'March 2022', | ||
| 'workspace.getCachedParentSvgSize'); | ||
| svg = /** @type {?} */ (svg); | ||
| return new Blockly.utils.Size(svg.cachedWidth_, svg.cachedHeight_); | ||
|
|
@@ -220,7 +198,8 @@ Blockly.deleteBlock = function(selected) { | |
| Blockly.Events.setGroup(true); | ||
| Blockly.hideChaff(); | ||
| if (selected.outputConnection) { | ||
| // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) | ||
| // Do not attempt to heal rows | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang-format did this. |
||
| // (https://github.com/google/blockly/issues/4832) | ||
| selected.dispose(false, true); | ||
| } else { | ||
| selected.dispose(/* heal */ true, true); | ||
|
|
@@ -234,59 +213,22 @@ Blockly.deleteBlock = function(selected) { | |
| * @param {!Blockly.ICopyable} toCopy Block or Workspace Comment to be copied. | ||
| * @package | ||
| */ | ||
| Blockly.copy = function(toCopy) { | ||
| var data = toCopy.toCopyData(); | ||
| if (data) { | ||
| Blockly.clipboardXml_ = data.xml; | ||
| Blockly.clipboardSource_ = data.source; | ||
| Blockly.clipboardTypeCounts_ = data.typeCounts; | ||
| } | ||
| }; | ||
| Blockly.copy = Blockly.clipboard.copy; | ||
|
|
||
| /** | ||
| * Paste a block or workspace comment on to the main workspace. | ||
| * @return {boolean} True if the paste was successful, false otherwise. | ||
| * @package | ||
| */ | ||
| Blockly.paste = function() { | ||
| if (!Blockly.clipboardXml_) { | ||
| return false; | ||
| } | ||
| // Pasting always pastes to the main workspace, even if the copy | ||
| // started in a flyout workspace. | ||
| var workspace = Blockly.clipboardSource_; | ||
| if (workspace.isFlyout) { | ||
| workspace = workspace.targetWorkspace; | ||
| } | ||
| if (Blockly.clipboardTypeCounts_ && | ||
| workspace.isCapacityAvailable(Blockly.clipboardTypeCounts_)) { | ||
| Blockly.Events.setGroup(true); | ||
| workspace.paste(Blockly.clipboardXml_); | ||
| Blockly.Events.setGroup(false); | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
| Blockly.paste = Blockly.clipboard.paste; | ||
|
|
||
| /** | ||
| * Duplicate this block and its children, or a workspace comment. | ||
| * @param {!Blockly.ICopyable} toDuplicate Block or Workspace Comment to be | ||
| * copied. | ||
| * @package | ||
| */ | ||
| Blockly.duplicate = function(toDuplicate) { | ||
| // Save the clipboard. | ||
| var clipboardXml = Blockly.clipboardXml_; | ||
| var clipboardSource = Blockly.clipboardSource_; | ||
|
|
||
| // Create a duplicate via a copy/paste operation. | ||
| Blockly.copy(toDuplicate); | ||
| toDuplicate.workspace.paste(Blockly.clipboardXml_); | ||
|
|
||
| // Restore the clipboard. | ||
| Blockly.clipboardXml_ = clipboardXml; | ||
| Blockly.clipboardSource_ = clipboardSource; | ||
| }; | ||
| Blockly.duplicate = Blockly.clipboard.duplicate; | ||
|
|
||
| /** | ||
| * Cancel the native context menu, unless the focus is on an HTML input widget. | ||
|
|
@@ -402,9 +344,7 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { | |
| 'Block definition #' + i + ' in JSON array' + | ||
| ' overwrites prior definition of "' + typename + '".'); | ||
| } | ||
| Blockly.Blocks[typename] = { | ||
| init: Blockly.jsonInitFactory_(elem) | ||
| }; | ||
| Blockly.Blocks[typename] = {init: Blockly.jsonInitFactory_(elem)}; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang-format did this. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2021 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview Blockly's internal clipboard for managing copy-paste. | ||
| * @author fenichel@google.com (Rachel Fenichel) | ||
| */ | ||
| 'use strict'; | ||
|
|
||
| goog.module('Blockly.clipboard'); | ||
| goog.module.declareLegacyNamespace(); | ||
|
|
||
| const Events = goog.require('Blockly.Events'); | ||
| /* eslint-disable-next-line no-unused-vars */ | ||
| const ICopyable = goog.requireType('Blockly.ICopyable'); | ||
|
|
||
| /** | ||
| * Metadata about the object that is currently on the clipboard. | ||
| * @type {?ICopyable.CopyData} | ||
| */ | ||
| let copyData = null; | ||
|
|
||
| /** | ||
| * Copy a block or workspace comment onto the local clipboard. | ||
| * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. | ||
| */ | ||
| const copy = function(toCopy) { | ||
| copyData = toCopy.toCopyData(); | ||
| }; | ||
| /** @package */ | ||
| exports.copy = copy; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @Package is suppose to go above this line now.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| /** | ||
| * Paste a block or workspace comment on to the main workspace. | ||
| * @return {boolean} True if the paste was successful, false otherwise. | ||
| */ | ||
| const paste = function() { | ||
| if (!copyData.xml) { | ||
| return false; | ||
| } | ||
| // Pasting always pastes to the main workspace, even if the copy | ||
| // started in a flyout workspace. | ||
| var workspace = copyData.source; | ||
| if (workspace.isFlyout) { | ||
| workspace = workspace.targetWorkspace; | ||
| } | ||
| if (copyData.typeCounts && | ||
| workspace.isCapacityAvailable(copyData.typeCounts)) { | ||
| Events.setGroup(true); | ||
| workspace.paste(copyData.xml); | ||
| Events.setGroup(false); | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
| /** @package */ | ||
| exports.paste = paste; | ||
|
|
||
| /** | ||
| * Duplicate this block and its children, or a workspace comment. | ||
| * @param {!ICopyable} toDuplicate Block or Workspace Comment to be | ||
| * duplicated. | ||
| */ | ||
| const duplicate = function(toDuplicate) { | ||
| // Save the clipboard. | ||
| const oldCopyData = copyData; | ||
|
|
||
| // Create a duplicate via a copy/paste operation. | ||
| copy(toDuplicate); | ||
| // copy() replaced the value of copyData. | ||
| toDuplicate.workspace.paste(copyData.xml); | ||
|
|
||
| // Restore the clipboard. | ||
| copyData = oldCopyData; | ||
| }; | ||
| /** @package */ | ||
| exports.duplicate = duplicate; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format did this.