Skip to content
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

Revert "Merge middle click popup changes together" #11

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions addons/custom-block-shape/update-all-blocks.js

This file was deleted.

20 changes: 17 additions & 3 deletions addons/custom-block-shape/userscript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { updateAllBlocks } from "./update-all-blocks.js";

export default async function ({ addon, console }) {
var BlocklyInstance = await addon.tab.traps.getBlockly();

Expand All @@ -9,6 +7,22 @@ export default async function ({ addon, console }) {

const { GRID_UNIT } = BlockSvg;

function updateAllBlocks() {
const workspace = Blockly.getMainWorkspace();
if (workspace) {
if (vm.editingTarget) {
vm.emitWorkspaceUpdate();
}
const flyout = workspace.getFlyout();
if (flyout) {
const flyoutWorkspace = flyout.getWorkspace();
Blockly.Xml.clearWorkspaceAndLoadFromXml(Blockly.Xml.workspaceToDom(flyoutWorkspace), flyoutWorkspace);
workspace.getToolbox().refreshSelection();
workspace.toolboxRefreshEnabled_ = true;
}
}
}

function applyChanges(
paddingSize = addon.settings.get("paddingSize"),
cornerSize = addon.settings.get("cornerSize"),
Expand Down Expand Up @@ -238,7 +252,7 @@ export default async function ({ addon, console }) {

function applyAndUpdate(...args) {
applyChanges(...args);
updateAllBlocks(vm);
updateAllBlocks();
}

addon.settings.addEventListener("change", () => applyAndUpdate());
Expand Down
31 changes: 11 additions & 20 deletions addons/custom-block-text/addon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Customizable block text style",
"description": "Allows you to make a few adjustments to block text to make it easier to read.",
"description": "Changes the thickness of the text on blocks and optionally adds a text shadow.",
"tags": ["editor", "codeEditor", "featured"],
"credits": [
{
Expand All @@ -10,16 +10,18 @@
{
"name": "_nix",
"link": "https://github.com/towerofnix"
},
{
"name": "DNin01",
"link": "https://github.com/DNin01"
}
],
"userscripts": [
"userstyles": [
{
"url": "text-bold.css",
"matches": ["projects"],
"if": { "settings": { "bold": true } }
},
{
"url": "userscript.js",
"matches": ["projects"]
"url": "text-shadow.css",
"matches": ["projects"],
"if": { "settings": { "shadow": true } }
}
],
"settings": [
Expand All @@ -34,22 +36,11 @@
"id": "shadow",
"type": "boolean",
"default": false
},
{
"name": "Text size (%)",
"id": "size",
"type": "integer",
"min": 75,
"max": 200,
"default": 100
}
],
"dynamicEnable": true,
"dynamicDisable": true,
"updateUserstylesOnSettingsChange": true,
"versionAdded": "1.24.0",
"latestUpdate": {
"version": "1.33.0",
"newSettings": ["size"]
},
"enabledByDefault": false
}
4 changes: 4 additions & 0 deletions addons/custom-block-text/text-bold.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.blocklyText,
.blocklyHtmlInput {
font-weight: bold;
}
5 changes: 5 additions & 0 deletions addons/custom-block-text/text-shadow.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Makes block text a little easier to read. **/
.blocklyDraggable > .blocklyText,
.blocklyDraggable > g > text {
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}
93 changes: 0 additions & 93 deletions addons/custom-block-text/userscript.js

This file was deleted.

21 changes: 20 additions & 1 deletion addons/middle-click-popup/BlockRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { BlockShape, BlockInstance, BlockInputEnum, BlockInputBoolean, BlockInputBlock } from "./BlockTypeInfo.js";
import { getTextWidth } from "./module.js";

const SVG_NS = "http://www.w3.org/2000/svg";

Expand Down Expand Up @@ -177,6 +176,26 @@ function createTextComponent(text, fillVar, container) {
return new BlockComponent(textElement, 0, getTextWidth(textElement));
}

const textWidthCache = new Map();
const textWidthCacheSize = 1000;

/**
* Gets the width of an svg text element, with caching.
* @param {SVGTextElement} textElement
*/
function getTextWidth(textElement) {
let string = textElement.innerHTML;
if (string.length === 0) return 0;
let width = textWidthCache.get(string);
if (width) return width;
width = textElement.getBoundingClientRect().width;
textWidthCache.set(string, width);
if (textWidthCache.size > textWidthCacheSize) {
textWidthCache.delete(textWidthCache.keys().next());
}
return width;
}

/**
* Creates a DOM element to hold all the contents of a block.
* A block could be the top level block, or it could be a block like (() + ()) that's inside
Expand Down
37 changes: 0 additions & 37 deletions addons/middle-click-popup/module.js

This file was deleted.

3 changes: 0 additions & 3 deletions addons/middle-click-popup/userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import WorkspaceQuerier, { QueryResult } from "./WorkspaceQuerier.js";
import renderBlock, { BlockComponent, getBlockHeight } from "./BlockRenderer.js";
import { BlockInstance, BlockShape, BlockTypeInfo } from "./BlockTypeInfo.js";
import { onClearTextWidthCache } from "./module.js";

export default async function ({ addon, msg, console }) {
const Blockly = await addon.tab.traps.getBlockly();
Expand Down Expand Up @@ -70,8 +69,6 @@ export default async function ({ addon, msg, console }) {
mousePosition = { x: e.clientX, y: e.clientY };
});

onClearTextWidthCache(closePopup);

/**
* @typedef ResultPreview
* @property {BlockInstance} block
Expand Down