How To Neutralize Apple's Hijacking of Text Navigation and Selection Shortcuts in Numbers?

Here's a challenge that I have been unable to overcome for the past decade. I'd like to use KM to neutralize Apple's hijacking of text navigation and selection shortcuts in Numbers.

The shortcuts in question are option-Left, option-Right, option-shift-Left and option-shift-Right. I use them all the time in all macOS apps and they are part of my muscle memory, which means that I find myself unable to remember to refrain from using them in Numbers.

The problem is that, in Numbers, there are two ways to get the insertion point inside a cell. You can either A) double-click on the cell to make it editable and put you inside it or B) simply select the cell with a single click (or a cursor key) and start typing, which automatically puts you "inside" the cell.

Unfortunately, if you use method B, the option-Left, option-Right, option-shift-Left and option-shift-Right do not work as text navigation or selection shortcuts. These shortcuts retain the meaning that they have in Numbers when you are not inside a cell, which is to… insert a new column to the left or to the right of the current column. Very annoying!

There are no real workarounds. You can try and remember to always get inside the cell using method A (double-clicking on the cell or, if your hands are already on the keyboard, option-Return to enter the cell), but it's pretty much impossible to remember this all the time. There will always be times where you find yourself entering a cell using method B (simply selecting the cell and starting to type).

After you've entered a cell, there is, of course, no visual difference reminding you of the way you've entered the cell. Once you are inside it, the I-beam cursor is blinking in both cases, and that's it. You're just supposed to remember how you entered the cell, and to refrain from using option-Left, option-Right, option-shift-Left and option-shift-Right if you entered the cell using method B.

It is of course absurd, and means that your muscle memory, instead of helping you work faster, actually works against you.

So, I have been trying to find a way to get KM to intercept the option-Left, option-Right, option-shift-Left and option-shift-Right shortcuts and make them work as expected (i.e. as text selection and navigation shortcuts) at all times, regardless of the method used to enter the cell.

But I have been unable to do so. I have looked for anything in the Numbers UI that might be in a different state depending on whether you enter the cell with method A or with method B, but I cannot find anything.

There might be another way to do this, but everything that I have tried has done more harm than good.

Since Apple implemented this hijacking of the option-Left, option-Right, option-shift-Left and option-shift-Right shortcuts in Numbers (and in tables in Pages) a decade ago, I have absolutely no hope of them ever coming to their senses and realizing that this interferes with the muscle memory of users who, like me, use text navigation and selection shortcuts all the time in macOS.

Has anyone ever been able to successfully tackle this problem? Does anyone have any suggestions?

Thanks in advance.

Pierre

Hey Pierre,

I feel your pain on this one, but I don't think there's much to be done...

-Chris

Thanks. I am still hoping that someone really clever might have a trick :-).

Not a Numbers user, but try this. According to Number's Help you can use ⌥← or ⌃⌥B to move the insertion point one word left, ⌥→ or ⌃⌥F for one word right, and add a ⇧ for selection -- and the ⌃-based variants seem to work in either cell "state". So:

Override Numbers Keys.kmmacros (5.0 KB)

Image

I suggest you put the macro in a Numbers-only Group -- the alternates should work in any "standard" text-editing UI item, but why risk it?

I'd love to know if this actually works for you!

Wow. That is indeed very interesting… I had no idea there were alternate shortcuts for text navigation and selection. HOWEVER, right now, on my Mac, I can only get control-option-shift-B and control-option-shift-F to work as expected (with both methods of entering cells). Control-B moves one char to the left and Control-F moves one char to the right, but Control-option-B… inserts a quotation mark and control-option-F does nothing.

It must have to do with the fact that I am using a Canadian CSA (French Canadian keyboard) rather than the standard US keyboard layout. Indeed, if I switch to the US layout, all shortcuts work as indicated. But, as foreign users well know from many years of experience and suffering, Apple rarely makes sure that rarer shortcuts also work on non-US keyboard layouts. So I am going to have to try and find if some OTHER keyboard that might work for this.

Otherwise, it's an excellent suggestion! Thanks! I will keep you posted if I find the shortcuts for my Canadian CSA keyboard.

Yep, if I switch to that keyboard I see the same thing. Grrrr!

Not in the UI, but after some random noodling around this looks promising:

tell application "Numbers"
	tell table 1 of active sheet of front document
		if formatted value of first cell of the selection range is missing value then
			display dialog "Text not properly active"
		else
			display dialog "Yes! Use your shortcuts normally"
		end if
	end tell
end tell

Perhaps you could start the previous macro with an action containing this AppleScript, then branch on the result. If "Yes!" then pass the ⌥-style keystrokes because you know they'll work "properly", but if "not properly active" pass no keystroke and bleep to let you know...

The Canadian CSA problem is indeed infuriating, because there really doesn't seem to be any other shortcut that works.

Out of curiosity, I've installed Karabiner-Elements and created a profile with the rule provided here, which turns the numpad into cursor keys. And those modified numpad keys work regardless of the state that Numbers is indeed (method A or method B of entering cell). But of course, I don't really want to use this, because I need the numpad to enter numbers!

Then I tried a couple of rules that change fn-I/J/K/L into cursor keys, but this is low level, which means that, when the rule is active, it is impossible to use KM to trigger fn-J or fn-L. (It triggers the actual cursor keys instead.) So that doesn't help. Maybe there is a way to combine Karabiner rules with Keyboard Maestro, but I haven't figured it out.

Which brings us to your AppleScript script, which indeed appears to be working! I am going to try and see if I can at least block the hijacking when Numbers is in the "wrong" state, if I cannot actually work around it. (I am not aware of a scriptable way to turn Numbers from the wrong state to the right state. I usually have to exit the cell and then re-enter it the right way. But of course that loses the current cursor position, so it's not helpful in this situation.)

Thanks a lot. I'll keep working on this and see if I can come up with something.

Sorry, I'm not quite sure if I understood everything correctly. But when it comes to navigation in a text (or similar), I use a KM palette. If the palette is visible, each shortcut or single letter should do what you want. When you close the palette everything is back to normal.

In my case: Palette is visible. j = left arrow. k = right arrow. h = beginning line. f = line up. d = line down, and so on.

It doesn't matter if you send Numbers an actual ⌥→ or a simulated one via KM's "Keystroke" action -- if the Numbers cell is in the "not properly open" state then a new column is inserted before the active cell's column rather than the insertion point moving one word to the left.

You can make key-mapping application specific, so it would be "impossible to use KM to trigger fn-J or fn-L when in Numbers". Have you got macros that have those triggers, need to be active in Numbers, and definitely can't be reassigned to other hotkeys? If not, a specifically-targetted Karabiner rule may work for you.

I was referring to rules in Karabiner (like this one). My idea was to turn fn-I/J/K/L into cursor keys, since I never use these shortcuts for anything else, and then see if they would work for text selection and navigation in Numbers, which they do. With that rule active in Karabiner, fn-option-L and fn-option-J work for jumping right and left by whole words, and fn-option-shift-L and fn-option-shift-J work for extending the selection to the right and to the left by whole words.

Unfortunately, if I then try to trigger fn-I/J/K/L with Keyboard Maestro's Type Keystroke actions, it instead records actual cursor key presses, because Karabiner obvious takes precedence and already "translates" these key presses before KM has had a chance to record them in the Type Keystroke action I am trying to create.

So, back to square one with this approach.

If I want to keep using my Canadian CSA keyboard (which of course I do), I have no choice but to try to use the AppleScript script provided above to detect Numbers's current state (i.e. whether the cell was entered in with method A [double-click] or method B [typing over]) and let option-shift-Right and option-shift-Left work normally in the former case and block them altogether in the latter case. It's not ideal, because I'd like option-shift-Right and option-shift-Left to work properly in all situations, but at least I won't accidentally insert columns all the time when I don't mean to.

Fortunately, as indicated, ctrl-option-shift-F/B do work properly even with my Canadian CSA keyboard, so at least I can get keyboard selection extensions working properly at all times, which is half the battle won.

I will continue to explore alternatives.

Sorry, Nige_S, this is getting a bit too complicated for me. I barely know anything about Karabiner, so I might need more detailed instructions :slight_smile:

To clarify: I don't currently use fn-J or fn-L for anything.

Ok, at the risk of suggesting nonsense. :hot_face:

Could this work with BTT? fn is a "normal" modifier there and as far as I know KM and BTT work at the same level.

I know even less and have never even installed it! But a quick look at the complex modifications shows an Application Specific section, and a look at the JSON for one of those shows you can use a conditions block and test for a particular frontmost_application for which (and only which) your remapping would be active:

 "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.apple\\.iWorks\\.Numbers"
              ]
            }
          ]

So you'd include that in your Fn-I/J/K/L rule. I know there are Karabiner users here who might be able to help, or you might be able to use a rules generator.

OK, Nige_S, I have finally got around to exploring this further.

I am afraid the JSON stuff is way above my pay grade. You might not be familiar with Karabiner-Elements, but you are clearly familiar with JSON, and I know absolutely nothing about it. So for now I have to give up on a Karabiner-based solution, I am afraid. (I might try to find the time to study JSON in the future.)

The alternate keyboard shortcuts work great for extending selection word by word, so that's great. Sadly the alternate shortcuts for moving the cursor don't work on my Canadian CSA keyboard layout.

The AppleScript approach you suggested seems to be working overall, but:

  1. AppleScript execution is not that fast and there is a noticeable lag while KM executes the script to determine Numbers's state.
  2. The script doesn't seem to work all the time. Sometime "missing value" is true even though it shouldn't be.

#2 is obviously a significant problem, because, when it produces a false positive, a macro to block column insertion based on the script blocks the normal working of the shortcut.

I might try to figure out why the script doesn't work reliably 100% of the time but it is a bit of a black box for me, since I don't know much about AppleScript either and I am not sure I understand what the link between "formatted value" and the way the cell was entered is in the first place.

If you have any further suggestions, TIA.