Skip to content

Commit

Permalink
Merge branch 'bug-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
anmcgrath committed Feb 27, 2024
2 parents 6d36ccc + 699f39f commit 192e50d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/BlazorDatasheet.Core/Commands/MergeCellsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public MergeCellsCommand(IRegion region)

public bool Execute(Sheet sheet)
{
sheet.Cells.BatchChanges();
_overridenMergedRegions.Clear();
_mergesPerformed.Clear();

Expand Down Expand Up @@ -53,16 +54,14 @@ public bool Execute(Sheet sheet)
// Store the merge that we are doing and perform the actual merge
_mergesPerformed.Add(region);
sheet.Cells.MergeImpl(region);
sheet.Cells.EndBatchChanges();
return true;
}

private CellValueChange getValueChangeOnClear(int row, int col, Sheet sheet)
{
return new CellValueChange(row, col, sheet.Cells.GetValue(row, col));
}

public bool Undo(Sheet sheet)
{
sheet.Cells.BatchChanges();

// Undo the merge we performed
foreach (var merge in _mergesPerformed)
sheet.Cells.UnMergeCellsImpl(merge);
Expand All @@ -72,6 +71,7 @@ public bool Undo(Sheet sheet)

// Restore all the cell values that were lost when merging
sheet.Cells.Restore(_restoreData);
sheet.Cells.EndBatchChanges();

return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/BlazorDatasheet.Core/Data/Cells/CellStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ internal CellStoreRestoreData CopyImpl(IRegion fromRegion, IRegion toRegion, Cop
{
restoreData.ValueRestoreData = _dataStore.Copy(fromRegion, toRegion);
restoreData.ValidRestoreData = _validStore.Copy(fromRegion, toRegion);
restoreData.FormulaRestoreData = _formulaStore.Clear(toRegion);
}

if (options.CopyFormula)
Expand Down
4 changes: 3 additions & 1 deletion src/BlazorDatasheet.Core/FormulaEngine/FormulaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BlazorDatasheet.Core.Data.Cells;
using BlazorDatasheet.Core.Events;
using BlazorDatasheet.Core.Events.Edit;
using BlazorDatasheet.Core.Events.Layout;
using BlazorDatasheet.DataStructures.Geometry;
using BlazorDatasheet.DataStructures.Graph;
using BlazorDatasheet.DataStructures.References;
Expand Down Expand Up @@ -29,7 +30,7 @@ public class FormulaEngine
/// This should ideally keep track of the formula that reference the range also,
/// but for now it's just whether it's referenced or not.
/// </summary>
private RegionDataStore<bool> _observedRanges = new();
private readonly RegionDataStore<bool> _observedRanges;

public bool IsCalculating { get; private set; }

Expand All @@ -43,6 +44,7 @@ public FormulaEngine(Sheet sheet)
_environment = new SheetEnvironment(sheet);
_evaluator = new Evaluator(_environment);
_dependencyGraph = new DependencyGraph();
_observedRanges = new RegionDataStore<bool>();

RegisterDefaultFunctions();
}
Expand Down
10 changes: 7 additions & 3 deletions src/BlazorDatasheet/Datasheet.razor
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@
var mergesInView = Sheet.Cells.GetMerges(this.Viewport.VisibleRegion);
@foreach (var merge in mergesInView)
{
var row = merge.Top;
var col = merge.Left;
var constrainedMerge = merge.GetIntersection(_sheetLocal.Region);
if (constrainedMerge == null)
continue;

var row = constrainedMerge.Top;
var col = constrainedMerge.Left;
var cell = _visualSheet.GetVisualCell(row, col);

<div id="merge"
style="@GetAbsoluteCellPositionStyles(row, col, merge.Height, merge.Width)"
style="@GetAbsoluteCellPositionStyles(row, col, constrainedMerge.Height, constrainedMerge.Width)"
class="sheet-cell"
@onmouseup="e => HandleCellMouseUp(row, col, e.MetaKey, e.CtrlKey, e.ShiftKey)"
@ondblclick="e => HandleCellDoubleClick(row, col, e.MetaKey, e.CtrlKey, e.ShiftKey)"
Expand Down
24 changes: 12 additions & 12 deletions src/BlazorDatasheet/Edit/EditorOverlayRenderer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@

@code {

[Parameter, EditorRequired]
public Sheet Sheet { get; set; }
[Parameter, EditorRequired] public Sheet Sheet { get; set; }

[Parameter, EditorRequired]
public Dictionary<string, CellTypeDefinition> CustomCellTypes { get; set; }
[Parameter, EditorRequired] public Dictionary<string, CellTypeDefinition> CustomCellTypes { get; set; }

[Parameter, EditorRequired]
public Dictionary<string, CellTypeDefinition> DefaultCellTypes { get; set; }
[Parameter, EditorRequired] public Dictionary<string, CellTypeDefinition> DefaultCellTypes { get; set; }

private Sheet? _sheet;

[Parameter, EditorRequired]
public CellLayoutProvider CellLayoutProvider { get; set; }
[Parameter, EditorRequired] public CellLayoutProvider CellLayoutProvider { get; set; }

/// The type of the active editor, which is an ICellEditor
private Type? ActiveEditorType { get; set; } = typeof(TextEditorComponent);
Expand Down Expand Up @@ -75,11 +71,13 @@
_sheet.Editor.EditFinished -= EditorOnEditFinished;
_sheet.Editor.EditValueChanged -= EditorOnEditValueChanged;
}

_sheet = Sheet;
_sheet.Editor.EditBegin += EditorOnEditBegin;
_sheet.Editor.EditFinished += EditorOnEditFinished;
_sheet.Editor.EditValueChanged += EditorOnEditValueChanged;
}

base.OnParametersSet();
}

Expand Down Expand Up @@ -138,9 +136,9 @@
{
if (!EqualityComparer<ElementReference>.Default.Equals(_activeCellEditor.InputRef, default(ElementReference)))
{
// Request focus with a delay so that it the field doesn't capture any oninput events
// from the text field that is just rendered. If not, there's inconsistent behaviour between
// WASM and Server.
// Request focus with a delay so that it the field doesn't capture any oninput events
// from the text field that is just rendered. If not, there's inconsistent behaviour between
// WASM and Server.
await JS.InvokeVoidAsync("setFocusWithTimeout", _activeCellEditor.InputRef, 0);
}
}
Expand Down Expand Up @@ -190,7 +188,9 @@
var left = CellLayoutProvider.ComputeLeftPosition(EditCell.Col);
var top = CellLayoutProvider.ComputeTopPosition(EditCell.Row);

var mergedPosn = Sheet.Cells.GetMerge(EditCell.Row, EditCell.Col);
var mergedPosn = Sheet.Cells.GetMerge(EditCell.Row, EditCell.Col)?
.GetIntersection(Sheet.Region);

int colSpan = 1;
int rowSpan = 1;

Expand Down

0 comments on commit 192e50d

Please sign in to comment.