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

Ctrl + d keyboard shortcut interferes with macOS functionality #1200

Closed
terasakisatoshi opened this issue May 28, 2021 · 3 comments · Fixed by #1208
Closed

Ctrl + d keyboard shortcut interferes with macOS functionality #1200

terasakisatoshi opened this issue May 28, 2021 · 3 comments · Fixed by #1208

Comments

@terasakisatoshi
Copy link
Contributor

I prefer to use Ctrl-P/N/F/B/D/K/Y/D/A/E on macOS to control the cursor on text. On Pluto notebook, It seems Ctrl-P/N/F/B/K/A/E works as described in Document shortcuts section of Mac keyboard shortcuts: https://support.apple.com/en-us/HT201236.

Unfortunately Ctrl-D does not work as Control-D: Delete the character to the right of the insertion point..

Since line in KeyboardShortcuts.js tries to replace Ctrl-blah-blah in with Cmd-blah-blah in keymap, one may think this is fine.

keymap_with_cmd[key.replace(/Ctrl/g, "Cmd")] = handler

However, this lines assigns Ctrl-D shortcut to do something (selecting some words ???)

keys["Ctrl-D"] = () => {
if (cm.somethingSelected()) {
const sels = cm.getSelections()
if (all_equal(sels)) {
// TODO
}
} else {
const cursor = cm.getCursor()
const token = cm.getTokenAt(cursor)
cm.setSelection({ line: cursor.line, ch: token.start }, { line: cursor.line, ch: token.end })
}
}

If I remove this lines above, I can use Ctrl-D to delete the character to the right, which is what I expect on macOS.

Note that if one would like to use Ctrl-D functionality that Pluto.jl provides on macOS, one only have to do use Cmd+D (due to this line

keymap_with_cmd[key.replace(/Ctrl/g, "Cmd")] = handler
) .

Do we need insert conditional branch something like ?

if (!is_mac_keyboard){
  keys["Ctrl-D"] = () => {
  // do something
  }
}

Any thoughts about this issue ?

@terasakisatoshi
Copy link
Contributor Author

using delete to remove Ctrl-... key from keymap_with_cmd works.

export let map_cmd_to_ctrl_on_mac = (keymap) => {
    if (!is_mac_keyboard) {
        return keymap
    }

    let keymap_with_cmd = { ...keymap }
    for (let [key, handler] of Object.entries(keymap)) {
        keymap_with_cmd[key.replace(/Ctrl/g, "Cmd")] = handler
        delete keymap_with_cmd[key] // delete Ctrl-blah-blah e.g. Ctrl-D or Ctrl-M etc ...
    }
    return keymap_with_cmd
}

@fonsp
Copy link
Owner

fonsp commented May 31, 2021

Thanks! Feel free to make a PR, but note that removing the Ctrl- shortcuts will break other shortcuts, e.g. Ctrl-M for md""" (i am not sure if there are others), so take that into account.

@likanzhan
Copy link

As Ctrl + d has been removed, is there a shortcut to stop the Pluto in the terminal? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants