1414 * limitations under the License.
1515 */
1616
17+ import type { IUnitRange } from '@univerjs/core' ;
1718import type { FormulaCurrentConfigService } from '@univerjs/engine-formula' ;
1819import { createIdentifier , isFormulaId , isFormulaString } from '@univerjs/core' ;
1920import { IFormulaCurrentConfigService , IFormulaDependencyGenerator } from '@univerjs/engine-formula' ;
@@ -29,7 +30,7 @@ export interface IFormulaCellAndFeatureItem {
2930}
3031
3132export interface IRemoteFormulaDependencyGenerator {
32- generate ( ) : Promise < Array < IFormulaCellAndFeatureItem > > ;
33+ generate ( range ?: IUnitRange ) : Promise < Array < IFormulaCellAndFeatureItem > > ;
3334}
3435
3536export const RemoteFormulaDependencyGeneratorServiceName = 'sheets-formula.remote-formula-dependency-generator.service' ;
@@ -44,7 +45,7 @@ export class RemoteFormulaDependencyGeneratorService implements IRemoteFormulaDe
4445 @IFormulaCurrentConfigService private readonly _currentConfigService : IFormulaCurrentConfigService
4546 ) { }
4647
47- async generate ( ) : Promise < Array < IFormulaCellAndFeatureItem > > {
48+ async generate ( range ?: IUnitRange ) : Promise < Array < IFormulaCellAndFeatureItem > > {
4849 const configService = this . _currentConfigService as FormulaCurrentConfigService ;
4950 const originalForceCalculate = configService . isForceCalculate ( ) ;
5051 configService . setForceCalculate ( true ) ;
@@ -54,15 +55,29 @@ export class RemoteFormulaDependencyGeneratorService implements IRemoteFormulaDe
5455 for ( let i = 0 ; i < trees . length ; i ++ ) {
5556 const tree = trees [ i ] ;
5657 if ( ( isFormulaString ( tree . formula ) || isFormulaId ( tree . formulaId ) ) || tree . featureId != null ) {
57- result . push ( {
58- unitId : tree . unitId ,
59- subUnitId : tree . subUnitId ,
60- row : tree . row ,
61- column : tree . column ,
62- featureId : tree . featureId || undefined ,
63- formula : tree . formula || undefined ,
64- formulaId : tree . formulaId || undefined ,
65- } ) ;
58+ let include = true ;
59+ if ( range ) {
60+ if ( tree . unitId !== range . unitId || tree . subUnitId !== range . sheetId ) {
61+ include = false ;
62+ } else if ( tree . row != null && tree . column != null ) {
63+ const r = range . range ;
64+ if ( tree . row < r . startRow || tree . row > r . endRow || tree . column < r . startColumn || tree . column > r . endColumn ) {
65+ include = false ;
66+ }
67+ }
68+ // For features without row/column, include if unitId and subUnitId match
69+ }
70+ if ( include ) {
71+ result . push ( {
72+ unitId : tree . unitId ,
73+ subUnitId : tree . subUnitId ,
74+ row : tree . row ,
75+ column : tree . column ,
76+ featureId : tree . featureId || undefined ,
77+ formula : tree . formula || undefined ,
78+ formulaId : tree . formulaId || undefined ,
79+ } ) ;
80+ }
6681 }
6782 }
6883 return result ;
0 commit comments