The Arcade Expression Editor Can Do More Than You Think!

1042
2
06-07-2022 03:05 PM
jcarlson
MVP Esteemed Contributor
9 2 1,042

Did you know that the Arcade Expression Editor in ArcGIS Online and Portal can do some fancy stuff?

Most of the guides are focused on the functions, but what about just using the editor itself? As of writing this, the embedded editor you see in AGOL is built using Ace. Why is that important? Because Ace has keyboard shortcuts. (For a handy reference, you can check out this article.)

I like "show" rather than just "tell", though, so I've put together some GIFs to demonstrate these shortcuts. Here are a few things that maybe you didn't know about, and which you should definitely try.

Multiple Cursors

This was the biggest one for me. Just hold the Alt key, then click and drag. For a keyboard-only method, hold Ctrl + Alt and press Up or Down to add a cursor above or below the "primary" line (the one highlighted in yellow). Note that if you already have an active cursor in that direction, this will just change which line is "primary".

Click and drag with the mouseClick and drag with the mouse

Adding cursors and moving the "primary" line with keyboard commands.Adding cursors and moving the "primary" line with keyboard commands.

And if you need to select lines that aren't adjacent, just Ctrl + Alt and click.

brave_E2PiqHcN0F.gif

Adding Multiple Cursors to Specific Text

You know how if you highlight text in your editor, you can see other instances of the text faintly highlighted? Have you ever wanted to certain occurrences of, say, a variable name?

Ctrl + Alt + Right or Left will add a cursor to the next / previous occurrence of the selected text.

brave_ul4GJuz3oq.gif

Find / Replace

What if you want to edit all occurrences of a variable name? Or something more complicated? If you've never done it, the usual Ctrl + F (find) and Ctrl + H (find and replace) work here in the Expression Editor, and come complete with regex support.

I almost feel silly mentioning this shortcut, but it's easy to forget about. When your cursor isn't focused in the expression window, Ctrl + F just opens your browser's find tool.

brave_hiDfqfEhqH.gif

Move the Current Line(s)

Hold the Alt key and press the Up or Down Arrow to move the line(s) of the cursor accordingly.

brave_KKSamxonIM.gif

Increment or Decrement a Number

Ctrl + Shift and the Up or Down Arrow will increment your integers. Correctly interprets negative numbers, too!

Note that this will "target" the number to the left of the cursor, so you can adjust specific decimal places or the tens, hundreds, etc.

brave_xUD4lonNss.gif

Duplicating Text

Duplicate Selection

Ctrl + Shift + D will duplicate your current selection.

brave_yaNxswySyx.gif

Duplicate Current Line

Alt + Shift + Up or Down will duplicate the current line. This one has always felt a bit counter-intuitive to me, but I think of it as the arrow key is what direction you want to move the cursor, leaving behind a copy. So Up will move the cursor up, and leaves behind the copy below. To my eyes, it just looks like I'm pressing Up to create a copy Down, but oh well.

brave_A4QMENPqbP.gif

Go To Position

Line / Character Combo

Ctrl + L will open a text box where you can specify a given line, and optionally the character position. Handy for debugging long expressions.

brave_KPktj8wASq.gif

Matching Bracket

Assuming you actually matched all your brackets, just select one of them and use Ctrl + P.

brave_YZDw9MuqwA.gif

Adjusting Text

Comment / Uncomment

Ctrl + / will toggle the selected lines as being comments or not.

brave_ry0dM7kAEh.gif

Switch Case

Ctrl + U makes any selected text UPPER-CASE. Ctrl + Shift + U for lower-case.

brave_48LWtLqzhG.gif

In Closing: Change Your Settings!

There are more shortcuts than these, and I encourage you to play around and see what else you can incorporate into your work to make things more efficient.

The last thing I want to mention is my favorite. Ctrl + , will open the settings menu. You might not have known that this even existed, but it does!

jcarlson_0-1654613757419.png

There's a lot in here worthy of its own post, but you can probably just look at the Ace docs for that. Odds are, though, there's a setting or two in here that you might like to change, especially the theme. Prefer Solarized Dark or Monokai? You can have it!

jcarlson_1-1654613894056.png

 

2 Comments
JohannesLindner
MVP Frequent Contributor

Good find, excellent write-up!

From the shortcuts you listed, I'm most excited for the regex search and replace, that's going to be helpful (even though I'll probably spend longer trying to figure out the regex syntax than just doing it manually...)

The article you linked made me aware of the fold marks next to the line numbers, with these you can hide multi-line code blocks (eg function bodies, if and for blocks, list and dictionary declarations). Pretty basic IDE stuff, but I didn't notice it in the editor before.

With shortcuts, you can even fold arbitrary lines, though that is probably not going to help with readability...

 

Sadly, the theme setting only applies to the editor window. That makes the editor look kinda out of place next to the unchanged Globals/Functions/Constants view:

JohannesLindner_0-1654691770949.png

 

jcarlson
MVP Esteemed Contributor

@JohannesLindner  true, a Dracula editor on Esri's otherwise bright and shiny Playground looks a bit funny. But then, there's always the Stylus browser extension, if you really just want dark mode everywhere.

About the Author
I'm a GIS Analyst for Kendall County, IL. When I'm not on the clock, you can usually find me contributing to OpenStreetMap, knitting, or nattering on to my family about any and all of the above.