Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set keyboard shortcuts for adding a cell below or above selected cell #2287

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/components/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ export const Cell = ({
const on_add_after = useCallback(() => {
pluto_actions.add_remote_cell(cell_id, "after")
}, [pluto_actions, cell_id, selected])
const on_add_before = useCallback(() => {
pluto_actions.add_remote_cell(cell_id, "before")
}, [pluto_actions, cell_id, selected])
const on_code_fold = useCallback(() => {
pluto_actions.fold_remote_cells(pluto_actions.get_selected_cells(cell_id, selected), !code_folded)
}, [pluto_actions, cell_id, selected, code_folded])
Expand Down Expand Up @@ -294,6 +297,7 @@ export const Cell = ({
on_submit=${on_submit}
on_delete=${on_delete}
on_add_after=${on_add_after}
on_add_before=${on_add_before}
on_change=${on_change_cell_input}
on_update_doc_query=${on_update_doc_query}
on_focus_neighbor=${on_focus_neighbor}
Expand Down
13 changes: 13 additions & 0 deletions frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export const CellInput = ({
on_submit,
on_delete,
on_add_after,
on_add_before,
on_change,
on_update_doc_query,
on_focus_neighbor,
Expand Down Expand Up @@ -411,6 +412,14 @@ export const CellInput = ({
on_submit()
return true
}
const keyMapAddAfter = () => {
on_add_after()
return true
}
const keyMapAddBefore = () => {
on_add_before()
return true
}
let run = async (fn) => await fn()
const keyMapRun = (/** @type {EditorView} */ cm) => {
run(async () => {
Expand Down Expand Up @@ -549,6 +558,10 @@ export const CellInput = ({
{ key: "Ctrl-Delete", run: keyMapDelete },
{ key: "Backspace", run: keyMapBackspace },
{ key: "Ctrl-Backspace", run: keyMapBackspace },
{ key: "Alt-B", run: keyMapAddAfter }, // B for Below
{ key: "Alt-b", run: keyMapAddAfter },
{ key: "Alt-A", run: keyMapAddBefore }, // A for Above
{ key: "Alt-a", run: keyMapAddBefore },
]

let DOCS_UPDATER_VERBOSE = false
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,8 @@ patch: ${JSON.stringify(

PageUp or fn+Up: select cell above
PageDown or fn+Down: select cell below
Alt+A: add cell above
Alt+B: add cell below

${ctrl_or_cmd_name}+Q: interrupt notebook
${ctrl_or_cmd_name}+S: submit all changes
Expand Down