Skip to content

Commit e1f3a11

Browse files
LiuTeiTeiliujuping
authored andcommitted
fix: trigger onFilterResultChanged when filtered
1 parent 173978f commit e1f3a11

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

packages/plugin-outline-pane/src/views/filter-tree.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export const matchTreeNode = (
7777
return matchTreeNode(childNode, keywords, filterOps);
7878
}).find(Boolean);
7979

80+
// 如果命中了子节点,需要将该节点展开
81+
if (matchChild && treeNode.expandable) {
82+
treeNode.setExpanded(true);
83+
}
84+
8085
treeNode.setFilterReult({
8186
filterWorking: true,
8287
matchChild,

packages/plugin-outline-pane/src/views/tree-node.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ModalTreeNodeView extends PureComponent<{
3434
}
3535

3636
componentDidMount(): void {
37-
const rootTreeNode = this.rootTreeNode;
37+
const { rootTreeNode } = this;
3838
rootTreeNode.onExpandableChanged(() => {
3939
this.setState({
4040
treeChildren: rootTreeNode.children,
@@ -53,7 +53,7 @@ class ModalTreeNodeView extends PureComponent<{
5353
}
5454

5555
render() {
56-
const rootTreeNode = this.rootTreeNode;
56+
const { rootTreeNode } = this;
5757
const { expanded } = rootTreeNode;
5858

5959
const hasVisibleModalNode = !!this.modalNodesManager?.getVisibleModalNode();
@@ -98,6 +98,9 @@ export default class TreeNodeView extends PureComponent<{
9898
conditionFlow: boolean;
9999
expandable: boolean;
100100
treeChildren: TreeNode[] | null;
101+
filterWorking: boolean;
102+
matchChild: boolean;
103+
matchSelf: boolean;
101104
} = {
102105
expanded: false,
103106
selected: false,
@@ -110,6 +113,9 @@ export default class TreeNodeView extends PureComponent<{
110113
conditionFlow: false,
111114
expandable: false,
112115
treeChildren: [],
116+
filterWorking: false,
117+
matchChild: false,
118+
matchSelf: false,
113119
};
114120

115121
eventOffCallbacks: Array<IPublicTypeDisposable | undefined> = [];
@@ -154,6 +160,10 @@ export default class TreeNodeView extends PureComponent<{
154160
treeChildren: treeNode.children,
155161
});
156162
});
163+
treeNode.onFilterResultChanged(() => {
164+
const { filterWorking: newFilterWorking, matchChild: newMatchChild, matchSelf: newMatchSelf } = treeNode.filterReult;
165+
this.setState({ filterWorking: newFilterWorking, matchChild: newMatchChild, matchSelf: newMatchSelf });
166+
});
157167
this.eventOffCallbacks.push(
158168
doc?.onDropLocationChanged(() => {
159169
this.setState({
@@ -216,7 +226,7 @@ export default class TreeNodeView extends PureComponent<{
216226
let shouldShowModalTreeNode: boolean = this.shouldShowModalTreeNode();
217227

218228
// filter 处理
219-
const { filterWorking, matchChild, matchSelf } = treeNode.filterReult;
229+
const { filterWorking, matchChild, matchSelf } = this.state;
220230
if (!isRootNode && filterWorking && !matchChild && !matchSelf) {
221231
// 条件过滤生效时,如果未命中本节点或子节点,则不展示该节点
222232
// 根节点始终展示

packages/plugin-outline-pane/src/views/tree-title.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ export default class TreeTitle extends PureComponent<{
2929
title: string;
3030
condition?: boolean;
3131
visible?: boolean;
32+
filterWorking: boolean;
33+
keywords: string;
34+
matchSelf: boolean;
3235
} = {
3336
editing: false,
3437
title: '',
38+
filterWorking: false,
39+
keywords: '',
40+
matchSelf: false,
3541
};
3642

3743
private lastInput?: HTMLInputElement;
@@ -100,6 +106,10 @@ export default class TreeTitle extends PureComponent<{
100106
visible: !hidden,
101107
});
102108
});
109+
treeNode.onFilterResultChanged(() => {
110+
const { filterWorking: newFilterWorking, keywords: newKeywords, matchSelf: newMatchSelf } = treeNode.filterReult;
111+
this.setState({ filterWorking: newFilterWorking, keywords: newKeywords, matchSelf: newMatchSelf });
112+
});
103113
}
104114
deleteClick = () => {
105115
const { treeNode } = this.props;
@@ -109,7 +119,7 @@ export default class TreeTitle extends PureComponent<{
109119
render() {
110120
const { treeNode, isModal } = this.props;
111121
const { pluginContext } = treeNode;
112-
const { editing } = this.state;
122+
const { editing, filterWorking, matchSelf, keywords } = this.state;
113123
const isCNode = !treeNode.isRoot();
114124
const { node } = treeNode;
115125
const { componentMeta } = node;
@@ -125,11 +135,9 @@ export default class TreeTitle extends PureComponent<{
125135
marginLeft: -indent,
126136
};
127137
}
128-
const { filterWorking, matchSelf, keywords } = treeNode.filterReult;
129138
const Extra = pluginContext.extraTitle;
130139
const { intlNode, common, config } = pluginContext;
131-
const Tip = common.editorCabin.Tip;
132-
const Title = common.editorCabin.Title;
140+
const { Tip, Title } = common.editorCabin;
133141
const couldHide = availableActions.includes('hide');
134142
const couldLock = availableActions.includes('lock');
135143
const couldUnlock = availableActions.includes('unlock');
@@ -253,7 +261,7 @@ class RenameBtn extends PureComponent<{
253261
}> {
254262
render() {
255263
const { intl, common } = this.props.treeNode.pluginContext;
256-
const Tip = common.editorCabin.Tip;
264+
const { Tip } = common.editorCabin;
257265
return (
258266
<div
259267
className="tree-node-rename-btn"
@@ -274,7 +282,7 @@ class LockBtn extends PureComponent<{
274282
render() {
275283
const { treeNode, locked } = this.props;
276284
const { intl, common } = this.props.treeNode.pluginContext;
277-
const Tip = common.editorCabin.Tip;
285+
const { Tip } = common.editorCabin;
278286
return (
279287
<div
280288
className="tree-node-lock-btn"
@@ -300,7 +308,7 @@ class HideBtn extends PureComponent<{
300308
render() {
301309
const { treeNode, hidden } = this.props;
302310
const { intl, common } = treeNode.pluginContext;
303-
const Tip = common.editorCabin.Tip;
311+
const { Tip } = common.editorCabin;
304312
return (
305313
<div
306314
className="tree-node-hide-btn"

0 commit comments

Comments
 (0)