Skip to content

Allow Alt-based navigation on macOS#207

Merged
lhecker merged 4 commits intomicrosoft:mainfrom
diabloproject:alt-arrows-should-jump-one-word
May 27, 2025
Merged

Allow Alt-based navigation on macOS#207
lhecker merged 4 commits intomicrosoft:mainfrom
diabloproject:alt-arrows-should-jump-one-word

Conversation

@diabloproject
Copy link
Contributor

@diabloproject diabloproject commented May 22, 2025

Closes #180

@diabloproject diabloproject changed the title read literal forward/back-word and allow alt-based navigation on macOS (#180) Read literal forward/back-word and allow alt-based navigation on macOS (#180) May 22, 2025
@lhecker lhecker added the E-needs-discussion Needs discussion between maintainers. label May 24, 2025
@lhecker lhecker removed the E-needs-discussion Needs discussion between maintainers. label May 27, 2025
Comment on lines +164 to +165
const KBMOD_FOR_WORD_NAV: InputKeyMod =
if cfg!(target_os = "macos") { kbmod::ALT } else { kbmod::CTRL };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the name a bit more specific so it's easier to remember what it stands for in future reviews.

}
_ => return false,
},
vk::F => match modifiers {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressing Alt+RightArrow opens top menu (File), instead of moving cursor one word to the right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing panic! in this case does not result in the program crashing, making me think that program never reaches Alt-F

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, because Alt+F is the shortcut for the "File" menu. The menubar shortcuts are global and so they steal it before it arrives here. This also means that your PR likely broke Alt+F for opening the "File" menu, right?

Not sure how to resolve this conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did not know that edit had this feature...
We probably can reassign the Alt-F to Alt-Shift-F on mac, but at this point we actually need to start thinking about separating actions and shortcuts, so we can define two separate layouts for mac and win/linux

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently menubar shortcuts aren't even a thing on macOS? I'll just disable them for now. You can use F10 to focus the menubar alternatively. (In the future we could add a different way to focus it on macOS.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should abandon this PR in favour of making more general input system. I can do it today/tomorrow, if it can be included in the release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think this PR is fine. Building a generalized system would be greatly appreciated though of course. I do think it would be a rather complex PR though, as it would need to be a full input-to-action mapper with knowledge of the context, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like to test the latest state, please let me know if it works for you. 🙂
Otherwise, I'll merge it as-is, because this logic is better than nothing for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it works, just tested in iTerm and Terminal.app

@lhecker lhecker changed the title Read literal forward/back-word and allow alt-based navigation on macOS (#180) Allow Alt-based navigation on macOS May 27, 2025
let keyboard_focus = !contains_focus
let keyboard_focus = accelerator != '\0'
&& !contains_focus
&& self.consume_shortcut(kbmod::ALT | InputKey::new(accelerator as u32));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lhecker it's safe to consume_shortcut(alt|0)? don't we still want the accelerator != '\0' bit? we did expressly set it to \0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe your diff viewer swallowed it, because I actually added that check!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think I am blind or broken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange question, but does && guarantee sequential checks? I am asking because it is a known problem in languages like C/C++

Copy link
Member

@lhecker lhecker May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're referring to short-circuit evaluation. Both C++ and Rust support it to my knowledge. In this case it guarantees that the function is not executed on macOS, because accelerator will be 0.

@lhecker lhecker merged commit b8459f9 into microsoft:main May 27, 2025
1 check passed
Lou32Verbose pushed a commit to Lou32Verbose/edit that referenced this pull request Jan 11, 2026
Closes microsoft#180

---------

Co-authored-by: Leonard Hecker <leonard@hecker.io>
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 this pull request may close these issues.

macOS: Alt-Left/Right should jump one word

3 participants