Why does modifyNumberUp toggle add/remove and next/previous

Viewed 126

Note: I actually stumbled across this behavior in RStudio on MacOS yet I assume it is rather about Java/JS.

When you place your cursor right after a number you can increment/decrement it via OPTION + SHIFT + ARROW UP/DOWN (or CNTRL + SHIFT + ARROW UP/DOWN for windows. This shortcut probably invokes the keybinding modifyNumberUp / modifyNumberDown. However, it also toggles the word pairs add/remove and next/previous.

  1. What is going on here? Is it actually JS or something else?
  2. Why does this happen? What is the purpose?
  3. Is there a list of words that are defined that way?

Just paste the following in a code editor like https://ace.c9.io/, set the cursor, and use the shortcut.

1
add
next
2 Answers

Eventually, I found the source of this behaviour. RStudio - and many other editors - refer to the Ace editor (which is written in JS).

RStudio consumes several JavaScript libraries, including Ace (text editor) and xterm.js (terminal emulator)

RStudio Documentation

Within this editor, there is a function modifyNumber defined. In case the input is not a number, the function toggleWord is triggered. This Function uses a list of toggleWordPairs to switch between multiple pairs. These are:

toggleWordPairs = [
  ["first", "last"],
  ["true", "false"],
  ["yes", "no"],
  ["width", "height"],
  ["top", "bottom"],
  ["right", "left"],
  ["on", "off"],
  ["x", "y"],
  ["get", "set"],
  ["max", "min"],
  ["horizontal", "vertical"],
  ["show", "hide"],
  ["add", "remove"],
  ["up", "down"],
  ["before", "after"],
  ["even", "odd"],
  ["in", "out"],
  ["inside", "outside"],
  ["next", "previous"],
  ["increase", "decrease"],
  ["attach", "detach"],
  ["&&", "||"],
  ["==", "!="]
];

There is a similar editor right here and it does not behave the way you have mentioned. RStudio & ace.c9.io might have put this feature separately, and it has nothing to do with JS itself, although they could have coded it in JS. THe reason would be convenience for users who have certain combinations used repeatedly. A better place to look for a list of words would be the docs, or if they have, their forums etc.

Related