File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
app/src/core/stage/stageManager/concreteMethods Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,14 @@ export class ReferenceManager {
9494
9595 /**
9696 * 处理引用按钮点击事件
97- * 这个函数需要性能优化,鼠标每次点击都会调用这个函数
97+ * O(N) 需要查找每一个引用的Section
9898 * @param clickLocation 点击位置
9999 */
100100 public onClickReferenceNumber ( clickLocation : Vector ) {
101- //
101+ if ( Object . keys ( this . project . references . sections ) . length === 0 ) return ;
102+ const sectionNameMap = this . buildSectionName2SectionMap ( Object . keys ( this . project . references . sections ) ) ;
102103 for ( const sectionName in this . project . references . sections ) {
103- const section = this . findSectionBySectionName ( sectionName ) ;
104+ const section = sectionNameMap [ sectionName ] ;
104105 if ( section ) {
105106 if ( section . isMouseInReferenceButton ( clickLocation ) ) {
106107 // 打开这个详细信息的引用弹窗
@@ -111,6 +112,17 @@ export class ReferenceManager {
111112 }
112113 }
113114
115+ private buildSectionName2SectionMap ( sectionNames : string [ ] ) : Record < string , Section > {
116+ const res : Record < string , Section > = { } ;
117+ const sectionNameSet = new Set ( sectionNames ) ;
118+ for ( const section of this . project . stage . filter ( ( obj ) => obj instanceof Section ) ) {
119+ if ( sectionNameSet . has ( section . text ) ) {
120+ res [ section . text ] = section ;
121+ }
122+ }
123+ return res ;
124+ }
125+
114126 /**
115127 * 更新当前项目的引用信息
116128 * (清理无效的引用)
You can’t perform that action at this time.
0 commit comments