diff --git a/src/BlazorDatasheet.Core/Edit/Editor.cs b/src/BlazorDatasheet.Core/Edit/Editor.cs index 0dd1f372..b20002b2 100644 --- a/src/BlazorDatasheet.Core/Edit/Editor.cs +++ b/src/BlazorDatasheet.Core/Edit/Editor.cs @@ -85,6 +85,7 @@ public Editor(Sheet sheet) /// /// If true, the editor should hold on to the edit when arrow keys are pressed. /// Details on the method that was used to begin the edit. + /// Details on the method that was used to begin the edit. /// The key that was used to begin the edit, if the entry mode was using the keyboard public void BeginEdit(int row, int col, bool isSoftEdit = true, EditEntryMode mode = EditEntryMode.None, string? key = null) @@ -155,7 +156,7 @@ public bool AcceptEdit() } var formulaResult = isFormula ? Sheet.FormulaEngine.Evaluate(parsedFormula) : CellValue.Empty; - var editValue = isFormula ? formulaResult : new CellValue(this.EditValue); + var editValue = isFormula ? formulaResult : GetValueAsCellValue(EditCell.Row, EditCell.Col, EditValue); var beforeAcceptEdit = new BeforeAcceptEditEventArgs(EditCell, editValue, parsedFormula, formulaString); BeforeEditAccepted?.Invoke(this, beforeAcceptEdit); @@ -196,6 +197,18 @@ public bool AcceptEdit() return false; } + private CellValue GetValueAsCellValue(int row, int col, string editValue) + { + var type = Sheet.Cells.GetCellType(row, col); + switch (type) + { + case "text": + return CellValue.Text(editValue); + } + + return new CellValue(editValue); + } + private void ClearEdit() { IsEditing = false; diff --git a/src/BlazorDatasheet/DatasheetRow.razor b/src/BlazorDatasheet/DatasheetRow.razor index 1520197c..f7559699 100644 --- a/src/BlazorDatasheet/DatasheetRow.razor +++ b/src/BlazorDatasheet/DatasheetRow.razor @@ -73,6 +73,7 @@ @switch (visualCell.CellType) { case "default": + case "text": case "datetime":
@visualCell.FormattedString @@ -145,5 +146,4 @@ } -} - +} \ No newline at end of file diff --git a/test/BlazorDatasheet.Test/Edit/EditTests.cs b/test/BlazorDatasheet.Test/Edit/EditTests.cs index 9ab7dca5..fd0de8c2 100644 --- a/test/BlazorDatasheet.Test/Edit/EditTests.cs +++ b/test/BlazorDatasheet.Test/Edit/EditTests.cs @@ -1,4 +1,5 @@ using BlazorDatasheet.Core.Data; +using FluentAssertions; using NUnit.Framework; namespace BlazorDatasheet.Test.Edit; @@ -70,4 +71,15 @@ public void Accept_Edit_Is_Undoable() sheet.Commands.Undo(); Assert.AreEqual(null, sheet.Cells.GetValue(0, 0)); } + + [Test] + public void Do_Not_Do_Conversion_If_Cell_Type_Is_Set_To_Text() + { + var sheet = new Sheet(10, 10); + sheet.Cells[0, 0].Type = "text"; + sheet.Editor.BeginEdit(0, 0); + sheet.Editor.EditValue = "04-10-1"; + sheet.Editor.AcceptEdit(); + sheet.Cells[0,0].Value.Should().Be("04-10-1"); + } } \ No newline at end of file