Skip to content

Commit

Permalink
Add excel like behavior #394
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Mar 4, 2024
1 parent 8f924d2 commit 1422b66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Client/MainComponents/KeyboardShortcuts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ let onKeydownEvent (dispatch: Messages.Msg -> unit) =
MoveSelectedCell Key.Right |> Messages.SpreadsheetMsg |> dispatch
| false, 40. -> // arrow down
MoveSelectedCell Key.Down |> Messages.SpreadsheetMsg |> dispatch
| false, key when key <= 90 && key >= 65 ->
SetActiveCellFromSelected |> Messages.SpreadsheetMsg |> dispatch
| false, _ ->
()
// Ctrl + c
Expand Down
1 change: 1 addition & 0 deletions src/Client/States/Spreadsheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Msg =
| UpdateSelectedCells of Set<int*int>
| MoveSelectedCell of Key
| UpdateActiveCell of (U2<int,(int*int)> * ColumnType) option
| SetActiveCellFromSelected
| RemoveTable of index:int
| RenameTable of index:int * name:string
| UpdateTableOrder of pre_index:int * new_index:int
Expand Down
12 changes: 11 additions & 1 deletion src/Client/Update/SpreadsheetUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module Spreadsheet =
/// </summary>
let updateHistoryStorageMsg (msg: Spreadsheet.Msg) (state: Spreadsheet.Model, model: Messages.Model, cmd) =
match msg with
| UpdateActiveView _ | UpdateHistoryPosition _ | Reset | UpdateSelectedCells _ | UpdateActiveCell _ | CopySelectedCell | CopyCell _ | MoveSelectedCell _ ->
| UpdateActiveView _ | UpdateHistoryPosition _ | Reset | UpdateSelectedCells _
| UpdateActiveCell _ | CopySelectedCell | CopyCell _ | MoveSelectedCell _ | SetActiveCellFromSelected ->
state.SaveToLocalStorage() // This will cache the most up to date table state to local storage.
state, model, cmd
| _ ->
Expand Down Expand Up @@ -175,6 +176,15 @@ module Spreadsheet =
let s = Set([nextIndex])
UpdateSelectedCells s |> SpreadsheetMsg |> Cmd.ofMsg
state, model, cmd
| SetActiveCellFromSelected ->
let cmd =
if state.SelectedCells.IsEmpty then
Cmd.none
else
let min = state.SelectedCells.MinimumElement
let cmd = (Fable.Core.U2.Case2 min, ColumnType.Main) |> Some |> UpdateActiveCell |> SpreadsheetMsg
Cmd.ofMsg cmd
state, model, cmd
| UpdateActiveCell next ->
let nextState = { state with ActiveCell = next }
nextState, model, Cmd.none
Expand Down

0 comments on commit 1422b66

Please sign in to comment.