question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cmd-Left and Cmd-Right not as expected on MacOS

See original GitHub issue

On MacOS, Cmd-Left and Cmd-Right are supposed to be basically the same as “Home” and “End.”

However, in QtConsole, Cmd-Left has a strange behavior: it literally brings you to the beginning of the line - aka before the prompt. Then, since the cursor is positioned at an “invalid” location, once you type anything it brings you right back to the end of the line.

Adding 8 lines of code to _event_filter_console_keypress(self, event) in console-widget.py yields the correct behavior:

...
    def _event_filter_console_keypress(self, event):
        """ Filter key events for the underlying text widget to create a
            console-like interface.
        """
        intercepted = False
        cursor = self._control.textCursor()
        position = cursor.position()
        key = event.key()
        ctrl_down = self._control_key_down(event.modifiers())
        alt_down = event.modifiers() & QtCore.Qt.AltModifier
        shift_down = event.modifiers() & QtCore.Qt.ShiftModifier

#### BEGIN INSERT
        cmd_down = \
            sys.platform == "darwin" and \
            self._control_key_down(event.modifiers(), include_command=True)
        if cmd_down:
            if key == QtCore.Qt.Key_Left:
                key = QtCore.Qt.Key_Home
            elif key == QtCore.Qt.Key_Right:
                key = QtCore.Qt.Key_End
#### END INSERT
        #------ Special modifier logic -----------------------------------------
...

You could also probably make a _cmd_down_remap similar to the _ctrl_down_remap that you already have, but this seemed simpler.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
battaglia01commented, May 5, 2021

Makes sense. OK, so forgetting that - it seems like the way I’m doing the cmd remapping is alright, so I’ll put these things together in a new PR.

@impact27, your thought about checking the line number is good; I don’t know the easiest way to do that though. Maybe best in a separate issue…

Mike

On Tue, May 4, 2021 at 11:15 PM Carlos Cordoba @.***> wrote:

How does this usually work on Windows, where Ctrl-C equals copy?

Yeah, that’s what it does.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jupyter/qtconsole/issues/483#issuecomment-832385850, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZFMTXXNQWTD2WPU4SCVDTMCZ3JANCNFSM43YZBM2A .

0reactions
battaglia01commented, Jun 9, 2021

OK, PR submitted in #488.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get Cmd-left/right working with iTerm2 and Vim ...
To mimic OS X's behavior of sending Cmd-left/right to the beginning/end of a line, I add the following mappings in iTerm2:.
Read more >
Apple terminal no home and end key - Use cmd left or cmd right
This keyboard shortcut works on most things on my mac book but not the Terminal. Usually I use the home and end keys...
Read more >
MacOS: Text navigation and highlighting w/keyboard ... - GitHub
If anyone wants to fix it for themselfs: In usekeymap.ts (line ~156+) change the following 4 lines: 'Cmd-Left': 'goGroupLeft', 'Cmd-Right': ' ...
Read more >
Cmd+left arrow on Mac behaviour - Technical Support
Hi, I am running build 2160 on Mac OS X 10.7.2. I am experiencing non-standard behavior for cmd+left arrow for long word wrapped...
Read more >
Wrong behavior of the "HOME" and "END" key on the macOS ...
I'm not sure if this is a Mac issue or an emacs issue, but on my Windows and Linux machines, the "HOME" and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found