Skip to content

Commit e287183

Browse files
committed
Switching to different approach. Revert changes in Operations.ts.
1 parent f7b4363 commit e287183

File tree

3 files changed

+21
-133
lines changed

3 files changed

+21
-133
lines changed

src/Operations.ts

Lines changed: 18 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import {
2222
ParsingErrorVertex,
2323
SheetMapping,
2424
SparseStrategy,
25-
ValueCellVertex,
25+
ValueCellVertex
2626
} from './DependencyGraph'
2727
import { FormulaVertex } from './DependencyGraph/FormulaCellVertex'
28-
import { RawAndParsedValue, ValueCellVertexValue } from './DependencyGraph/ValueCellVertex'
28+
import { RawAndParsedValue } from './DependencyGraph/ValueCellVertex'
2929
import { AddColumnsTransformer } from './dependencyTransformers/AddColumnsTransformer'
3030
import { AddRowsTransformer } from './dependencyTransformers/AddRowsTransformer'
3131
import { CleanOutOfScopeDependenciesTransformer } from './dependencyTransformers/CleanOutOfScopeDependenciesTransformer'
@@ -51,7 +51,7 @@ import {
5151
NamedExpressions
5252
} from './NamedExpressions'
5353
import { NamedExpressionDependency, ParserWithCaching, ParsingErrorType, RelativeDependency } from './parser'
54-
import { AstNodeType, ErrorWithRawInputAst, ParsingError } from './parser/Ast'
54+
import { ParsingError } from './parser/Ast'
5555
import { ParsingResult } from './parser/ParserWithCaching'
5656
import { findBoundaries, Sheet } from './Sheet'
5757
import { ColumnsSpan, RowsSpan } from './Span'
@@ -245,66 +245,11 @@ export class Operations {
245245
this.columnSearch.removeSheet(sheetId)
246246
}
247247

248-
/**
249-
* TODO
250-
*/
251-
public addSheet(name?: string): string {
248+
public addSheet(name?: string) {
252249
const sheetId = this.sheetMapping.addSheet(name)
253-
const addedSheetName = this.sheetMapping.fetchDisplayName(sheetId)
254-
this.dependencyGraph.addressMapping.autoAddSheet(sheetId, findBoundaries([]))
255-
this.reparseFormulasDependingOnSheet(addedSheetName)
256-
return addedSheetName
257-
}
258-
259-
/**
260-
* TODO
261-
*/
262-
private reparseFormulasDependingOnSheet(sheetName: string): void {
263-
const quotedSheetName = `'${sheetName.replace(/'/g, "''")}'`
264-
265-
const containsSheetName = (formulaText: string): boolean => {
266-
const lowerInput = formulaText.toLowerCase()
267-
return lowerInput.includes(`${sheetName}!`)
268-
|| lowerInput.includes(`${quotedSheetName}!`)
269-
}
270-
271-
for (const node of this.dependencyGraph.formulaNodes()) {
272-
const oldAst = node.getFormula(this.dependencyGraph.lazilyTransformingAstService)
273-
if (oldAst.type === AstNodeType.ERROR_WITH_RAW_INPUT && containsSheetName(oldAst.rawInput)) {
274-
this.reparseFormulaNode(node, oldAst)
275-
}
276-
}
277-
}
278-
279-
/**
280-
* TODO
281-
*/
282-
private reparseFormulaNode(node: FormulaCellVertex, ast: ErrorWithRawInputAst): void {
283-
const address = node.getAddress(this.dependencyGraph.lazilyTransformingAstService)
284-
const formulaText = `=${ast.rawInput}`
285-
const parserResult = this.parser.parse(formulaText, address)
286-
const { ast: newAst, errors } = parserResult
287-
288-
if (errors.length > 0) {
289-
this.setParsingErrorToCell(formulaText, errors, address)
290-
} else {
291-
try {
292-
const size = this.arraySizePredictor.checkArraySize(newAst, address)
293-
294-
if (size.width <= 0 || size.height <= 0) {
295-
throw Error('Incorrect array size')
296-
}
297-
298-
this.setFormulaToCell(address, size, parserResult)
299-
} catch (error) {
300-
if (!(error as Error).message) {
301-
throw error
302-
}
303-
304-
const parsingError: ParsingError = { type: ParsingErrorType.InvalidRangeSize, message: 'Invalid range size.' }
305-
this.setParsingErrorToCell(formulaText, [parsingError], address)
306-
}
307-
}
250+
const sheet: Sheet = []
251+
this.dependencyGraph.addressMapping.autoAddSheet(sheetId, findBoundaries(sheet))
252+
return this.sheetMapping.fetchDisplayName(sheetId)
308253
}
309254

310255
public renameSheet(sheetId: number, newName: string) {
@@ -514,6 +459,8 @@ export class Operations {
514459

515460
/**
516461
* Restores a single cell.
462+
* @param {SimpleCellAddress} address
463+
* @param {ClipboardCell} clipboardCell
517464
*/
518465
public restoreCell(address: SimpleCellAddress, clipboardCell: ClipboardCell): void {
519466
switch (clipboardCell.type) {
@@ -623,6 +570,7 @@ export class Operations {
623570

624571
this.setFormulaToCell(address, size, parserResult)
625572
} catch (error) {
573+
626574
if (!(error as Error).message) {
627575
throw error
628576
}
@@ -650,66 +598,45 @@ export class Operations {
650598
}
651599
}
652600

653-
/**
654-
* Sets cell content to an instance of parsing error.
655-
* Creates a ParsingErrorVertex and updates the dependency graph and column search index.
656-
*/
657601
public setParsingErrorToCell(rawInput: string, errors: ParsingError[], address: SimpleCellAddress) {
658-
this.removeCellValueFromColumnSearch(address)
659-
602+
const oldValue = this.dependencyGraph.getCellValue(address)
660603
const vertex = new ParsingErrorVertex(errors, rawInput)
661604
const arrayChanges = this.dependencyGraph.setParsingErrorToCell(address, vertex)
662-
605+
this.columnSearch.remove(getRawValue(oldValue), address)
663606
this.columnSearch.applyChanges(arrayChanges.getChanges())
664607
this.changes.addAll(arrayChanges)
665608
this.changes.addChange(vertex.getCellValue(), address)
666609
}
667610

668-
/**
669-
* Sets cell content to a formula.
670-
* Creates a FormulaCellVertex and updates the dependency graph and column search index.
671-
*/
672611
public setFormulaToCell(address: SimpleCellAddress, size: ArraySize, {
673612
ast,
674613
hasVolatileFunction,
675614
hasStructuralChangeFunction,
676615
dependencies
677616
}: ParsingResult) {
678-
this.removeCellValueFromColumnSearch(address)
679-
617+
const oldValue = this.dependencyGraph.getCellValue(address)
680618
const arrayChanges = this.dependencyGraph.setFormulaToCell(address, ast, absolutizeDependencies(dependencies, address), size, hasVolatileFunction, hasStructuralChangeFunction)
681-
619+
this.columnSearch.remove(getRawValue(oldValue), address)
682620
this.columnSearch.applyChanges(arrayChanges.getChanges())
683621
this.changes.addAll(arrayChanges)
684622
}
685623

686-
/**
687-
* Sets cell content to a value.
688-
* Creates a ValueCellVertex and updates the dependency graph and column search index.
689-
*/
690624
public setValueToCell(value: RawAndParsedValue, address: SimpleCellAddress) {
691-
this.changeCellValueInColumnSearch(address, value.parsedValue)
692-
625+
const oldValue = this.dependencyGraph.getCellValue(address)
693626
const arrayChanges = this.dependencyGraph.setValueToCell(address, value)
694-
627+
this.columnSearch.change(getRawValue(oldValue), getRawValue(value.parsedValue), address)
695628
this.columnSearch.applyChanges(arrayChanges.getChanges().filter(change => !equalSimpleCellAddress(change.address, address)))
696629
this.changes.addAll(arrayChanges)
697630
this.changes.addChange(value.parsedValue, address)
698631
}
699632

700-
/**
701-
* Sets cell content to an empty value.
702-
* Creates an EmptyCellVertex and updates the dependency graph and column search index.
703-
*/
704633
public setCellEmpty(address: SimpleCellAddress) {
705634
if (this.dependencyGraph.isArrayInternalCell(address)) {
706635
return
707636
}
708-
709-
this.removeCellValueFromColumnSearch(address)
710-
637+
const oldValue = this.dependencyGraph.getCellValue(address)
711638
const arrayChanges = this.dependencyGraph.setCellEmpty(address)
712-
639+
this.columnSearch.remove(getRawValue(oldValue), address)
713640
this.columnSearch.applyChanges(arrayChanges.getChanges())
714641
this.changes.addAll(arrayChanges)
715642
this.changes.addChange(EmptyValue, address)
@@ -996,45 +923,6 @@ export class Operations {
996923
}
997924
return this.dependencyGraph.fetchCellOrCreateEmpty(expression.address).vertex
998925
}
999-
1000-
/**
1001-
* Removes a cell value from the columnSearch index.
1002-
* Ignores the non-computed formula vertices.
1003-
*/
1004-
private removeCellValueFromColumnSearch(address: SimpleCellAddress): void {
1005-
if (this.isNotComputed(address)) {
1006-
return
1007-
}
1008-
1009-
const oldValue = this.dependencyGraph.getCellValue(address)
1010-
this.columnSearch.remove(getRawValue(oldValue), address)
1011-
}
1012-
1013-
/**
1014-
* Changes a cell value in the columnSearch index.
1015-
* Ignores the non-computed formula vertices.
1016-
*/
1017-
private changeCellValueInColumnSearch(address: SimpleCellAddress, newValue: ValueCellVertexValue): void {
1018-
if (this.isNotComputed(address)) {
1019-
return
1020-
}
1021-
1022-
const oldValue = this.dependencyGraph.getCellValue(address)
1023-
this.columnSearch.change(getRawValue(oldValue), getRawValue(newValue), address)
1024-
}
1025-
1026-
/**
1027-
* Checks if the FormulaCellVertex or ArrayVertex at the given address is not computed.
1028-
*/
1029-
private isNotComputed(address: SimpleCellAddress): boolean {
1030-
const vertex = this.dependencyGraph.getCell(address)
1031-
1032-
if (!vertex) {
1033-
return false
1034-
}
1035-
1036-
return 'isComputed' in vertex && !vertex.isComputed()
1037-
}
1038926
}
1039927

1040928
export function normalizeRemovedIndexes(indexes: ColumnRowIndex[]): ColumnRowIndex[] {

test/unit/cruds/adding-sheet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('add sheet to engine', () => {
125125
expect(engine.getCellValue(adr('A1', engine.getSheetId(table1Name)))).toBe(10)
126126
})
127127

128-
it.only('recalculates formulas with range references and aggregate functions (#1116)', () => {
128+
it('recalculates formulas with range references and aggregate functions (#1116)', () => {
129129
const engine = HyperFormula.buildEmpty()
130130
const sheet1Name = 'Sheet1'
131131
const sheet2Name = 'Sheet2'

test/unit/undo-redo.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,8 @@ describe('UndoRedo - at the Operations layer', () => {
10051005

10061006
it('clearUndoStack should clear out all undo entries', () => {
10071007
expect(undoRedo.isUndoStackEmpty()).toBe(true)
1008-
undoRedo.saveOperation(new AddSheetUndoEntry('Sheet 1', 0))
1009-
undoRedo.saveOperation(new AddSheetUndoEntry('Sheet 2', 0))
1008+
undoRedo.saveOperation(new AddSheetUndoEntry('Sheet 1'))
1009+
undoRedo.saveOperation(new AddSheetUndoEntry('Sheet 2'))
10101010

10111011
expect(undoRedo.isUndoStackEmpty()).toBe(false)
10121012

0 commit comments

Comments
 (0)