fix editor search focus layout error
This commit is contained in:
1 parent
4a2116dd4f
commit
645a88f661
7 files changed
+62
-39
No files matched your search
+1
-1
Submodule src/behavior3 updated: f45acd9d30...d6e3f08950.
@@ -44,7 +44,6 @@ interface FilterOption {
|
|||||||
filterFocus: boolean;
|
filterFocus: boolean;
|
||||||
filterType: "content" | "id";
|
filterType: "content" | "id";
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
isFocused: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createTreeData = (node: NodeModel, parent?: string) => {
|
const createTreeData = (node: NodeModel, parent?: string) => {
|
||||||
@@ -227,7 +226,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterFocus: true,
|
filterFocus: true,
|
||||||
filterType: "content",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
isFocused: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSearchChange = (option: FilterOption) => {
|
const onSearchChange = (option: FilterOption) => {
|
||||||
@@ -710,10 +708,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createNode = () => {
|
const createNode = () => {
|
||||||
if (filterOption.isFocused) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!editor.selectedId) {
|
if (!editor.selectedId) {
|
||||||
message.warning(t("node.noNodeSelected"));
|
message.warning(t("node.noNodeSelected"));
|
||||||
return;
|
return;
|
||||||
@@ -1391,8 +1385,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
index: 0,
|
index: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onFocus={() => setFilterOption({ ...filterOption, isFocused: true })}
|
|
||||||
onBlur={() => setFilterOption({ ...filterOption, isFocused: false })}
|
|
||||||
onKeyDownCapture={handleKeyDown}
|
onKeyDownCapture={handleKeyDown}
|
||||||
suffix={
|
suffix={
|
||||||
<Flex gap="2px" style={{ alignItems: "center" }}>
|
<Flex gap="2px" style={{ alignItems: "center" }}>
|
||||||
@@ -1421,12 +1413,12 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterOption.filterFocus && "b3-editor-filter-selected"
|
filterOption.filterFocus && "b3-editor-filter-selected"
|
||||||
)}
|
)}
|
||||||
icon={<RiFocus3Line />}
|
icon={<RiFocus3Line />}
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
onSearchChange({
|
onSearchChange({
|
||||||
...filterOption,
|
...filterOption,
|
||||||
filterFocus: !filterOption.filterFocus,
|
filterFocus: !filterOption.filterFocus,
|
||||||
})
|
});
|
||||||
}
|
}}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
}
|
}
|
||||||
@@ -1471,7 +1463,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterType: "content",
|
filterType: "content",
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
isFocused: false,
|
|
||||||
});
|
});
|
||||||
keysRef.current?.focus();
|
keysRef.current?.focus();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import {
|
|||||||
isNodeArgOptional,
|
isNodeArgOptional,
|
||||||
isValidVariableName,
|
isValidVariableName,
|
||||||
isVariadic,
|
isVariadic,
|
||||||
loadVarDef,
|
|
||||||
parseExpr,
|
parseExpr,
|
||||||
usingGroups,
|
usingGroups,
|
||||||
usingVars,
|
usingVars,
|
||||||
@@ -259,7 +258,6 @@ const TreeInspector: FC = () => {
|
|||||||
|
|
||||||
// set form values
|
// set form values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadVarDef(workspace.editingTree.import);
|
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
form.setFieldValue("name", workspace.editingTree.name);
|
form.setFieldValue("name", workspace.editingTree.name);
|
||||||
form.setFieldValue("desc", workspace.editingTree.desc);
|
form.setFieldValue("desc", workspace.editingTree.desc);
|
||||||
@@ -624,7 +622,10 @@ const NodeInspector: FC = () => {
|
|||||||
form.setFieldValue("debug", data.debug);
|
form.setFieldValue("debug", data.debug);
|
||||||
form.setFieldValue("disabled", data.disabled);
|
form.setFieldValue("disabled", data.disabled);
|
||||||
form.setFieldValue("path", data.path);
|
form.setFieldValue("path", data.path);
|
||||||
form.setFieldValue("group", def.group);
|
form.setFieldValue(
|
||||||
|
"group",
|
||||||
|
def.group?.map((g) => ({ label: g, value: g }))
|
||||||
|
);
|
||||||
if (def.children === undefined || def.children === -1) {
|
if (def.children === undefined || def.children === -1) {
|
||||||
form.setFieldValue("children", t("node.children.unlimited"));
|
form.setFieldValue("children", t("node.children.unlimited"));
|
||||||
} else {
|
} else {
|
||||||
@@ -872,12 +873,13 @@ const NodeInspector: FC = () => {
|
|||||||
labelCol={{ span: "auto" }}
|
labelCol={{ span: "auto" }}
|
||||||
onFinish={finish}
|
onFinish={finish}
|
||||||
>
|
>
|
||||||
<Form.Item name="id" label={t("node.id")}>
|
<Form.Item name="type" label={t("node.type")}>
|
||||||
<Input disabled={true} />
|
<Input disabled={true} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
{workspace.groupDefs.length > 0 && def.group?.length && (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="type"
|
name="group"
|
||||||
label={t("node.type")}
|
label={t("node.group")}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
validator() {
|
validator() {
|
||||||
@@ -891,11 +893,12 @@ const NodeInspector: FC = () => {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Input disabled={true} />
|
<Select
|
||||||
</Form.Item>
|
style={{ fontSize: "13px" }}
|
||||||
{workspace.groupDefs.length > 0 && def.group?.length && (
|
mode="multiple"
|
||||||
<Form.Item name="group" label={t("node.group")}>
|
suffixIcon={null}
|
||||||
<GroupDefItem disabled={true} />
|
disabled={true}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
)}
|
)}
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -445,6 +445,7 @@ export const Workspace: FC = () => {
|
|||||||
showSaveDialog(editor);
|
showSaveDialog(editor);
|
||||||
} else {
|
} else {
|
||||||
workspace.close(path);
|
workspace.close(path);
|
||||||
|
keysRef.current?.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ export type WorkspaceStore = {
|
|||||||
close: (path: string) => void;
|
close: (path: string) => void;
|
||||||
find: (path: string) => EditorStore | undefined;
|
find: (path: string) => EditorStore | undefined;
|
||||||
relative: (path: string) => string;
|
relative: (path: string) => string;
|
||||||
refresh: (path: string) => void;
|
refresh: (path: string) => boolean;
|
||||||
|
|
||||||
save: () => void;
|
save: () => void;
|
||||||
saveAs: () => void;
|
saveAs: () => void;
|
||||||
@@ -592,9 +592,9 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
const workspace = get();
|
const workspace = get();
|
||||||
const editor = workspace.editors.find((v) => v.path === path);
|
const editor = workspace.editors.find((v) => v.path === path);
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
b3util.refreshDeclare(editor.root, editor.data.group, editor.declare);
|
return b3util.refreshDeclare(editor.root, editor.data.group, editor.declare);
|
||||||
},
|
},
|
||||||
|
|
||||||
save: () => {
|
save: () => {
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ body {
|
|||||||
text-align: end;
|
text-align: end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.b3-inspector .ant-form-item-explain {
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.b3-inspector-vars-item .ant-input-group-addon {
|
.b3-inspector-vars-item .ant-input-group-addon {
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
|
|||||||
+36
-12
@@ -859,7 +859,7 @@ export const isTreeFile = (path: string) => {
|
|||||||
return path.toLocaleLowerCase().endsWith(".json");
|
return path.toLocaleLowerCase().endsWith(".json");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadVarDef = (list: ImportDef[]) => {
|
const loadVarDef = (list: ImportDef[], arr: Array<VarDef>) => {
|
||||||
for (const entry of list) {
|
for (const entry of list) {
|
||||||
if (!files[entry.path]) {
|
if (!files[entry.path]) {
|
||||||
console.warn(`file not found:${workdir}/${entry.path}`);
|
console.warn(`file not found:${workdir}/${entry.path}`);
|
||||||
@@ -905,7 +905,7 @@ export const loadVarDef = (list: ImportDef[]) => {
|
|||||||
load(v);
|
load(v);
|
||||||
depends.add(v);
|
depends.add(v);
|
||||||
});
|
});
|
||||||
console.log(`load var: ${path}`);
|
console.debug(`load var: ${path}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alertError(`parsing error: ${path}`);
|
alertError(`parsing error: ${path}`);
|
||||||
}
|
}
|
||||||
@@ -921,9 +921,7 @@ export const loadVarDef = (list: ImportDef[]) => {
|
|||||||
modified: entry.modified,
|
modified: entry.modified,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const all: Set<VarDef> = new Set();
|
list.forEach((entry) => arr.push(...entry.vars));
|
||||||
list.forEach((entry) => entry.vars.forEach((v) => all.add(v)));
|
|
||||||
return Array.from(all);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const collectSubtree = (data: TreeGraphData | NodeModel, list: string[] = []) => {
|
const collectSubtree = (data: TreeGraphData | NodeModel, list: string[] = []) => {
|
||||||
@@ -941,18 +939,44 @@ export const refreshDeclare = (
|
|||||||
group: string[],
|
group: string[],
|
||||||
declare: FileVarDecl
|
declare: FileVarDecl
|
||||||
) => {
|
) => {
|
||||||
const vars: Set<VarDef> = new Set(declare.declvar.slice());
|
const filter: Record<string, boolean> = {};
|
||||||
|
const vars: Array<VarDef> = new (class extends Array {
|
||||||
|
push(...items: VarDef[]): number {
|
||||||
|
for (const v of items) {
|
||||||
|
if (filter[v.name]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filter[v.name] = true;
|
||||||
|
super.push(v);
|
||||||
|
}
|
||||||
|
return this.length;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
vars.push(...declare.declvar);
|
||||||
parsingStack.length = 0;
|
parsingStack.length = 0;
|
||||||
declare.subtree = collectSubtree(root).map((v) => ({
|
declare.subtree = collectSubtree(root).map((v) => ({
|
||||||
path: v,
|
path: v,
|
||||||
vars: [],
|
vars: [],
|
||||||
depends: [],
|
depends: [],
|
||||||
}));
|
}));
|
||||||
loadVarDef(declare.import).forEach((v) => vars.add(v));
|
loadVarDef(declare.import, vars);
|
||||||
loadVarDef(declare.subtree).forEach((v) => {
|
loadVarDef(declare.subtree, vars);
|
||||||
vars.add(v);
|
|
||||||
});
|
let changed = false;
|
||||||
|
const lastGroup = Array.from(Object.keys(usingGroups)).sort();
|
||||||
|
group.sort();
|
||||||
|
if (lastGroup.length !== group.length || lastGroup.some((v, i) => v !== group[i])) {
|
||||||
|
changed = true;
|
||||||
|
console.debug("refresh group:", lastGroup, group);
|
||||||
updateUsingGroups(group);
|
updateUsingGroups(group);
|
||||||
updateUsingVars(Array.from(vars));
|
}
|
||||||
console.debug("refresh declare", group, vars);
|
|
||||||
|
const lastVars = Array.from(Object.keys(usingVars ?? {})).sort();
|
||||||
|
vars.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
if (lastVars.length !== vars.length || lastVars.some((v, i) => v !== vars[i].name)) {
|
||||||
|
changed = true;
|
||||||
|
console.debug("refresh vars:", lastVars, vars);
|
||||||
|
updateUsingVars(vars);
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user