Skip to content

Commit

Permalink
Re-format & remove un-used code.
Browse files Browse the repository at this point in the history
  • Loading branch information
anmcgrath committed Mar 1, 2024
1 parent c521f4b commit 6cdbc10
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 47 deletions.
58 changes: 17 additions & 41 deletions src/BlazorDatasheet.Core/Selecting/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace BlazorDatasheet.Core.Selecting;

public class Selection
{
private Sheet _sheet;
private readonly Sheet _sheet;

/// <summary>
/// The region that is active for accepting user input, usually the most recent region added
/// </summary>
public IRegion? ActiveRegion { get; private set; }

private List<IRegion> _regions = new();
private readonly List<IRegion> _regions = new();

/// <summary>
/// All regions in the selection.
Expand Down Expand Up @@ -145,31 +145,24 @@ public void ClearSelections()
{
_regions.Clear();
ActiveRegion = null;
emitSelectionChange();
EmitSelectionChange();
}

/// <summary>
/// Adds the cell position to the selection
/// </summary>
/// <param name="row"></param>
/// <param name="col"></param>
internal void Add(int row, int col) => Add(new Region(row, col));

/// <summary>
/// Adds the region to the selection
/// </summary>
/// <param name="region"></param>
internal void Add(IRegion region) => Add(new List<IRegion>() { region });
private void Add(IRegion region) => Add(new List<IRegion>() { region });

/// <summary>
/// Adds the region to the selection
/// </summary>
/// <param name="regions"></param>
internal void Add(List<IRegion> regions)
private void Add(List<IRegion> regions)
{
_regions.AddRange(regions);
ActiveRegion = ExpandRegionOverMerged(regions.LastOrDefault());
emitSelectionChange();
EmitSelectionChange();
}

/// <summary>
Expand Down Expand Up @@ -213,23 +206,6 @@ internal void Add(List<IRegion> regions)
return boundedRegion;
}

/// <summary>
/// Removes the region from the selection
/// </summary>
/// <param name="region"></param>
private void Remove(IRegion region)
{
_regions.Remove(region);
var newActiveRegion = _regions.LastOrDefault();
if (newActiveRegion != null)
{
ActiveRegion = newActiveRegion;
ActiveCellPosition = newActiveRegion.Start;
}

emitSelectionChange();
}

/// <summary>
/// Extends the active region to the row/col specified
/// </summary>
Expand Down Expand Up @@ -334,7 +310,7 @@ public void MoveActivePositionByRow(int rowDir)
this.ActiveCellPosition = new CellPosition(offsetPosn.row, offsetPosn.col);
this.Add(newRegion);

emitSelectionChange();
EmitSelectionChange();
return;
}

Expand All @@ -348,7 +324,7 @@ public void MoveActivePositionByRow(int rowDir)
newRow = activeRegionFixed.Top;
if (newCol > activeRegionFixed.Right)
{
var newActiveRegion = getRegionAfterActive();
var newActiveRegion = GetRegionAfterActive();
var newActiveRegionFixed = newActiveRegion.GetIntersection(_sheet.Region);
newCol = newActiveRegionFixed.Left;
newRow = newActiveRegionFixed.Top;
Expand All @@ -361,7 +337,7 @@ public void MoveActivePositionByRow(int rowDir)
newRow = activeRegionFixed.Bottom;
if (newCol < activeRegionFixed.Left)
{
var newActiveRegion = getRegionAfterActive();
var newActiveRegion = GetRegionAfterActive();
var newActiveRegionFixed = newActiveRegion.GetIntersection(_sheet.Region);
newCol = newActiveRegionFixed.Right;
newRow = newActiveRegionFixed.Bottom;
Expand All @@ -371,7 +347,7 @@ public void MoveActivePositionByRow(int rowDir)
}

ActiveCellPosition = new CellPosition(newRow, newCol);
emitSelectionChange();
EmitSelectionChange();
}

/// <summary>
Expand Down Expand Up @@ -415,7 +391,7 @@ public void MoveActivePositionByCol(int colDir)
this.ActiveCellPosition = new CellPosition(offsetPosn.row, offsetPosn.col);
this.Add(newRegion);

emitSelectionChange();
EmitSelectionChange();
return;
}

Expand All @@ -429,7 +405,7 @@ public void MoveActivePositionByCol(int colDir)
newRow++;
if (newRow > activeRegionFixed.Bottom)
{
var newActiveRegion = getRegionAfterActive();
var newActiveRegion = GetRegionAfterActive();
var newActiveRegionFixed = newActiveRegion.GetIntersection(_sheet.Region);
newCol = newActiveRegionFixed.Left;
newRow = newActiveRegionFixed.Top;
Expand All @@ -442,7 +418,7 @@ public void MoveActivePositionByCol(int colDir)
newRow--;
if (newRow < activeRegionFixed.Top)
{
var newActiveRegion = getRegionAfterActive();
var newActiveRegion = GetRegionAfterActive();
var newActiveRegionFixed = newActiveRegion.GetIntersection(_sheet.Region);
newCol = newActiveRegionFixed.Right;
newRow = newActiveRegionFixed.Bottom;
Expand All @@ -452,7 +428,7 @@ public void MoveActivePositionByCol(int colDir)
}

ActiveCellPosition = new CellPosition(newRow, newCol);
emitSelectionChange();
EmitSelectionChange();
}

/// <summary>
Expand All @@ -470,7 +446,7 @@ internal void SetActivePosition(int row, int col)
ActiveCellPosition = new CellPosition(row, col);
}

private IRegion getRegionAfterActive()
private IRegion GetRegionAfterActive()
{
var activeRegionIndex = _regions.IndexOf(ActiveRegion!);
if (activeRegionIndex == -1)
Expand All @@ -481,7 +457,7 @@ private IRegion getRegionAfterActive()
return _regions[activeRegionIndex];
}

private IRegion getRegionBeforeActive()
private IRegion GetRegionBeforeActive()
{
var activeRegionIndex = _regions.IndexOf(ActiveRegion!);
if (activeRegionIndex == -1)
Expand All @@ -492,7 +468,7 @@ private IRegion getRegionBeforeActive()
return _regions[activeRegionIndex];
}

private void emitSelectionChange()
private void EmitSelectionChange()
{
SelectionChanged?.Invoke(this, _regions);
CellsSelected?.Invoke(this, new CellsSelectedEventArgs(_sheet.Cells.GetCellsInRegions(_regions)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BlazorDatasheet.Core.Data;
using BlazorDatasheet.Core.Util;
using BlazorDatasheet.DataStructures.Geometry;
using BlazorDatasheet.SharedPages.ObjectEditor;

namespace BlazorDatasheet.Core.ObjectEditor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using System.Reflection;

namespace BlazorDatasheet.Core.Util;
namespace BlazorDatasheet.SharedPages.ObjectEditor;

public static class Properties
{
Expand Down
7 changes: 5 additions & 2 deletions src/BlazorDatasheet/Datasheet.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private async Task<bool> HandleWindowKeyDown(KeyboardEventArgs e)
var direction = KeyUtil.GetKeyMovementDirection(e.Key);
if (!Sheet.Editor.IsEditing || (_editorManager.IsSoftEdit && AcceptEdit()))
{
this.collapseAndMoveSelection(direction.Item1, direction.Item2);
this.CollapseAndMoveSelection(direction.Item1, direction.Item2);
return true;
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ private async Task<bool> HandleWindowKeyDown(KeyboardEventArgs e)
return false;
}

private void collapseAndMoveSelection(int drow, int dcol)
private void CollapseAndMoveSelection(int drow, int dcol)
{
if (Sheet?.Selection?.ActiveRegion == null)
return;
Expand Down Expand Up @@ -656,6 +656,9 @@ public async Task CopySelectionToClipboard()

// Can only handle single selections for now
var region = Sheet.Selection.ActiveRegion;
if (region == null)
return;

await _clipboard.Copy(region, Sheet);
}

Expand Down
2 changes: 1 addition & 1 deletion src/BlazorDatasheet/Render/VisualCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public VisualCell(int row, int col, Sheet sheet)
Format = format;
}

internal VisualCell()
private VisualCell()
{
}

Expand Down
7 changes: 5 additions & 2 deletions src/BlazorDatasheet/Render/VisualSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

namespace BlazorDatasheet.Render;

public class VisualSheet
/// <summary>
/// Stores a cache of sheet cell's that are within the render viewport.
/// </summary>
internal class VisualSheet
{
private readonly Sheet _sheet;
private readonly Dictionary<CellPosition, VisualCell> _visualCache = new();
private CellFormat _defaultFormat = new CellFormat();
private Viewport? _currentViewport = null;

public event EventHandler<VisualSheetInvalidateArgs> Invalidated;

public VisualSheet(Sheet sheet)
{
_sheet = sheet;
Expand Down

0 comments on commit 6cdbc10

Please sign in to comment.