Skip to content

Commit

Permalink
Fill to selected cells if single cell is copied #359#382:sparkles:
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Feb 26, 2024
1 parent edf6491 commit d1abaf1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Client/Spreadsheet/Clipboard.Controller.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ let pasteCellsIntoSelected (state: Spreadsheet.Model) : JS.Promise<Spreadsheet.M
if state.SelectedCells.IsEmpty then
promise {return state}
else
log "here"
let columnIndex = state.SelectedCells |> Set.toArray |> Array.minBy fst |> fst
let selectedSingleColumnCells = state.SelectedCells |> Set.filter (fun index -> fst index = columnIndex)
promise {
let! tab = navigator.clipboard.readText()
let header = state.ActiveTable.Headers.[columnIndex]
let cells = CompositeCell.fromTabTxt tab |> Array.map _.ConvertToValidCell(header)
let rowCount = selectedSingleColumnCells.Count
let cellsTrimmed = cells |> takeFromArray rowCount
let indicesTrimmed = (Set.toArray selectedSingleColumnCells).[0..cellsTrimmed.Length-1]
let indexedCellsTrimmed = Array.zip indicesTrimmed cellsTrimmed
state.ActiveTable.SetCellsAt indexedCellsTrimmed
return state
if cells.Length = 1 then
let cell = cells.[0]
let newCells = selectedSingleColumnCells |> Array.ofSeq |> Array.map (fun index -> index, cell)
state.ActiveTable.SetCellsAt newCells
return state
else
let rowCount = selectedSingleColumnCells.Count
let cellsTrimmed = cells |> takeFromArray rowCount
let indicesTrimmed = (Set.toArray selectedSingleColumnCells).[0..cellsTrimmed.Length-1]
let indexedCellsTrimmed = Array.zip indicesTrimmed cellsTrimmed
state.ActiveTable.SetCellsAt indexedCellsTrimmed
return state
}

0 comments on commit d1abaf1

Please sign in to comment.