Skip to content

Commit

Permalink
Add a url parameter that, when set to 1, will add block ids to the to…
Browse files Browse the repository at this point in the history
…oltip text for each block. (#9803)

This adds the tooltipBlockIds URL parameter. When set to 1 in the URL (?tooltipBlockIds=1), blocks will include their block id in the tooltip when you hover over them.
  • Loading branch information
thsparks authored Jan 18, 2024
1 parent fe3f3b4 commit 3751b5a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pxtblocks/blocklyloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ namespace pxt.blocks {
block.setPreviousStatement(!(hasHandlers && !fn.attributes.handlerStatement) && fn.retType == "void");
block.setNextStatement(!(hasHandlers && !fn.attributes.handlerStatement) && fn.retType == "void");

block.setTooltip(/^__/.test(fn.namespace) ? "" : fn.attributes.jsDoc);
block.setTooltip((/^__/.test(fn.namespace) ? "" : fn.attributes.jsDoc) + (pxt.blocks.showBlockIdInTooltip ? " (id: '" + fn.attributes.blockId + "')" : ""));

function buildBlockFromDef(def: pxtc.ParsedBlockDef, expanded = false) {
let anonIndex = 0;
let firstParam = !expanded && !!comp.thisParameter;
Expand Down
17 changes: 17 additions & 0 deletions pxtlib/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace pxt.blocks {
const THIS_NAME = "this";

export let showBlockIdInTooltip: boolean = false;

// The JS Math functions supported in the blocks. The order of this array
// determines the order of the dropdown in the math_js_op block
export const MATH_FUNCTIONS = {
Expand Down Expand Up @@ -806,5 +808,20 @@ namespace pxt.blocks {
)
})
}

if (pxt.blocks.showBlockIdInTooltip) {
for (const id of Object.keys(_blockDefinitions)) {
const tooltip = _blockDefinitions[id].tooltip;
if (typeof tooltip === "object" && tooltip !== null) {
for (const innerKey in tooltip) {
if (tooltip.hasOwnProperty(innerKey)) {
(_blockDefinitions[id].tooltip as any)[innerKey] = `${tooltip[innerKey]} (id: ${id})`;
}
}
} else {
_blockDefinitions[id].tooltip = `${_blockDefinitions[id].tooltip} (id: ${id})`;
}
}
}
}
}
3 changes: 3 additions & 0 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5750,6 +5750,9 @@ document.addEventListener("DOMContentLoaded", async () => {
} else if (optsQuery["consoleticks"] == "2" || optsQuery["consoleticks"] == "short") {
pxt.analytics.consoleTicks = pxt.analytics.ConsoleTickOptions.Short;
}
if (optsQuery["tooltipblockids"] == "1") {
pxt.blocks.showBlockIdInTooltip = true;
}

initGitHubDb();

Expand Down

0 comments on commit 3751b5a

Please sign in to comment.