"Join lines" universal text action (delete newline and all leading whitespace)

Description of what you are sharing

This has been bothering me for years. Especially when coding, you often find cases where you have a second line with many leading tabs or spaces, but then you need to bring the second line back up, perhaps because you decided to modify the line you were currently on:

admin_users = db.table('users').where('status', 'active') \
                               .where('role', 'admin')
# but you decide to strip out the middle bit and want:
admin_users = db.table('users').where('role', 'admin')
# or you realize you just want it on one line after all:
admin_users = db.table('users').where('status', 'active').where('role', 'admin')

Normally, you need to do one of two things: take your fingers off the keyboard and carefully try and select precisely the extra whitespace across two lines and delete it, or mash forward-delete a bunch of times, which can get annoying.

Okay, I know this is a minor complaint, but it’s just one of those pain points. Some editors have a built-in feature, often called ‘join lines’ or similar with a comparable effect that you can activate with a shortcut, but not all do! Anyways, I was long told this was basically impossible to implement yourself. Not so! Here’s what I decided to do: use some built in shortcuts to jump to end of line, hop to the next line, select the entire line, cut, backspace back to current line, and then use a bit of JavaScript to trim the leading whitespace, spaces and tabs alike, which can then be re-pasted in. And voilá! It works. Maybe there was a slightly more efficient way of doing this, but it works across apps and web pretty well.

Here’s the pastable BTT trigger:

[
  {
    "BTTLastUpdatedAt" : 1775370054.1118932,
    "BTTTriggerType" : 0,
    "BTTTriggerClass" : "BTTTriggerTypeKeyboardShortcut",
    "BTTUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
    "BTTAdditionalConfiguration" : "1572944",
    "BTTShortcutScope" : 0,
    "BTTShortcutKeyboardType" : 2302,
    "BTTTriggerOnDown" : 1,
    "BTTLayoutIndependentChar" : "DELETE",
    "BTTShortcutKeyCode" : 51,
    "BTTShortcutAdvancedModifierKeys" : "1572944",
    "BTTShortcutModifierKeys" : 1572864,
    "BTTOrder" : 2,
    "BTTAutoAdaptToKeyboardLayout" : 0,
    "BTTActionsToExecute" : [
      {
        "BTTLastUpdatedAt" : 1775370035.7689519,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "E404D302-CC7D-42F3-BE89-8B08BC265A44",
        "BTTLayoutIndependentActionChar" : "RIGHT",
        "BTTShortcutToSend" : "55,124",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 0
      },
      {
        "BTTLastUpdatedAt" : 1775369919.137316,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "B1792891-F492-40EE-A179-546AF3BACC4D",
        "BTTLayoutIndependentActionChar" : "RIGHT",
        "BTTShortcutToSend" : "124",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 3
      },
      {
        "BTTLastUpdatedAt" : 1775369919.1374331,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "08007920-72C8-47D3-A900-7C0E435C08C9",
        "BTTLayoutIndependentActionChar" : "RIGHT",
        "BTTShortcutToSend" : "56,55,124",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 4
      },
      {
        "BTTLastUpdatedAt" : 1775369919.1373429,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "88949F3D-D686-464D-A75E-99596CECE909",
        "BTTLayoutIndependentActionChar" : "x",
        "BTTShortcutToSend" : "55,7",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 5
      },
      {
        "BTTLastUpdatedAt" : 1775370035.7686861,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "6DFADD48-B712-4638-942E-D2ED357C3903",
        "BTTPredefinedActionType" : 129,
        "BTTPredefinedActionName" : "Pause Execution  or  Delay Next Action (blocking)",
        "BTTDelayNextActionBy" : "0.1",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 6
      },
      {
        "BTTLastUpdatedAt" : 1775369919.1374202,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "F7CEF4DC-E6AC-4B79-86E0-1812451E4067",
        "BTTLayoutIndependentActionChar" : "DELETE",
        "BTTShortcutToSend" : "51",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 7
      },
      {
        "BTTLastUpdatedAt" : 1775369919.137445,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "1FF0E49B-A11A-47B2-BA5D-88B467BC1D7D",
        "BTTLayoutIndependentActionChar" : "SPACE",
        "BTTShortcutToSend" : "49",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 8
      },
      {
        "BTTLastUpdatedAt" : 1775370035.7687039,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "79457B4B-5AB2-4C0B-9ADB-0ACE880172B9",
        "BTTPredefinedActionType" : 448,
        "BTTPredefinedActionName" : "Transform Clipboard Contents with Java Script",
        "BTTAdditionalActionData" : {
          "BTTClipboardTransformerExampleInput" : "    \t  start of stuff",
          "BTTActionPasteInputFormat" : "public.utf8-plain-text",
          "BTTClipboardTransformerJS" : "async (clipboardContentString) => {\n    return clipboardContentString.trimStart();\n}"
        },
        "BTTGenericActionConfig" : "RemoveLeadStuff",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 9
      },
      {
        "BTTLastUpdatedAt" : 1775370035.768779,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "A12E7373-9C23-4424-8AF6-41A4A1B48E2B",
        "BTTPredefinedActionType" : 129,
        "BTTPredefinedActionName" : "Pause Execution  or  Delay Next Action (blocking)",
        "BTTDelayNextActionBy" : "0.1",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 10
      },
      {
        "BTTLastUpdatedAt" : 1775369919.1374578,
        "BTTTriggerParentUUID" : "5EB25F98-F1ED-403C-B58F-3EBB63281037",
        "BTTIsPureAction" : true,
        "BTTUUID" : "181F485A-3885-4F00-8A19-94351777ADA3",
        "BTTLayoutIndependentActionChar" : "v",
        "BTTShortcutToSend" : "55,9",
        "BTTTriggerOnDown" : 1,
        "BTTOrder" : 11
      }
    ],
    "BTTTriggerConfig" : {
      "BTTLeftRightModifierDifferentiation" : 1,
      "BTTTriggerRestrictions" : "0"
    }
  }
]