code menu hover时,提示具体的函数实现逻辑,方便选择是哪个函数

This commit is contained in:
xu_yanfeng
2025-02-11 17:11:07 +08:00
parent 0452694ee6
commit 246829f80c
5 changed files with 78 additions and 43 deletions

View File

@@ -1,4 +1,4 @@
import { TreeData } from "../../views/devtools/data";
import { FunctionInfo, TreeData } from "../../views/devtools/data";
import { ShowCode } from "./types";
declare const cc: any;
@@ -29,18 +29,30 @@ export function getCallbacks(node: any, code: ShowCode) {
if (!funArray || funArray.length === 0) {
return [];
}
if (funArray.length > 1) {
console.warn(`多个事件回调函数${funArray.length}`);
}
return funArray.map((fun) => {
// @ts-ignore
return fun.callback;
});
}
export function calcCodeHint(node: any, data: TreeData) {
data.codeTouchStart = getCallbacks(node, ShowCode.TouchStart).length;
data.codeTouchMove = getCallbacks(node, ShowCode.TouchMove).length;
data.codeTouchEnd = getCallbacks(node, ShowCode.TouchEnd).length;
data.codeTouchCancel = getCallbacks(node, ShowCode.TouchCancel).length;
data.codeButtonClick = getCallbacks(node, ShowCode.ButtonClick).length;
export const ANONYMOUS = "anonymous";
function functionInfo(node: any, type: ShowCode): FunctionInfo[] {
return getCallbacks(node, type).map((item) => {
let desc = item.toString();
const max = 50;
if (desc.length > max) {
// desc = desc.substr(0, max) + "...";
}
return {
name: item.name || ANONYMOUS,
desc,
} as FunctionInfo;
});
}
export function calcCodeHint(node: any, data: TreeData) {
data.codeTouchStart = functionInfo(node, ShowCode.TouchStart);
data.codeTouchMove = functionInfo(node, ShowCode.TouchMove);
data.codeTouchEnd = functionInfo(node, ShowCode.TouchEnd);
data.codeTouchCancel = functionInfo(node, ShowCode.TouchCancel);
data.codeButtonClick = functionInfo(node, ShowCode.ButtonClick);
}

View File

@@ -113,11 +113,11 @@ export class Inspector extends InjectEvent {
return;
}
const funArray = getCallbacks(node, data.code);
if (funArray && funArray.length) {
if (funArray && funArray.length && data.index < funArray.length) {
// @ts-ignore
const fn = funArray[0];
const fn = funArray[data.index];
this.target = fn;
if (funArray.length !== 1) {
if (!fn) {
debugger;
}
}