From 132d0553ae2b8fa155f0d43c948c70852b2db03c Mon Sep 17 00:00:00 2001
From: Eugene Pankov <e@ajenti.org>
Date: Wed, 24 Jan 2018 16:40:30 +0100
Subject: [PATCH] fixed alt-arrow keys on Mac as well as Home and End
 combinations (fixes #255)

---
 terminus-core/src/services/hotkeys.util.ts    |  2 +-
 .../src/components/terminalTab.component.ts   | 48 +++++++++++++------
 terminus-terminal/src/config.ts               | 24 ++++++++--
 terminus-terminal/src/hotkeys.ts              | 24 ++++++++++
 4 files changed, 80 insertions(+), 18 deletions(-)

diff --git a/terminus-core/src/services/hotkeys.util.ts b/terminus-core/src/services/hotkeys.util.ts
index e613ad86..01759c3f 100644
--- a/terminus-core/src/services/hotkeys.util.ts
+++ b/terminus-core/src/services/hotkeys.util.ts
@@ -5,7 +5,7 @@ export const metaKeyName = {
 }[process.platform]
 
 export const altKeyName = {
-    darwin: 'Option',
+    darwin: '⌥',
     win32: 'Alt',
     linux: 'Alt',
 }[process.platform]
diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts
index 67c42f64..9af893c6 100644
--- a/terminus-terminal/src/components/terminalTab.component.ts
+++ b/terminus-terminal/src/components/terminalTab.component.ts
@@ -88,20 +88,40 @@ export class TerminalTabComponent extends BaseTabComponent {
             if (!this.hasFocus) {
                 return
             }
-            if (hotkey === 'copy') {
-                this.hterm.copySelectionToClipboard()
-            }
-            if (hotkey === 'clear') {
-                this.clear()
-            }
-            if (hotkey === 'zoom-in') {
-                this.zoomIn()
-            }
-            if (hotkey === 'zoom-out') {
-                this.zoomOut()
-            }
-            if (hotkey === 'reset-zoom') {
-                this.resetZoom()
+            switch (hotkey) {
+                case 'copy':
+                    this.hterm.copySelectionToClipboard()
+                    break
+                case 'clear':
+                    this.clear()
+                    break
+                case 'zoom-in':
+                    this.zoomIn()
+                    break
+                case 'zoom-out':
+                    this.zoomOut()
+                    break
+                case 'reset-zoom':
+                    this.resetZoom()
+                    break
+                case 'home':
+                    this.sendInput('\x1bOH')
+                    break
+                case 'end':
+                    this.sendInput('\x1bOF')
+                    break
+                case 'previous-word':
+                    this.sendInput('\x1bb')
+                    break
+                case 'next-word':
+                    this.sendInput('\x1bf')
+                    break
+                case 'delete-previous-word':
+                    this.sendInput('\x1b\x7f')
+                    break
+                case 'delete-next-word':
+                    this.sendInput('\x1bd')
+                    break
             }
         })
         this.bellPlayer = document.createElement('audio')
diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts
index 73cf9706..5afe183b 100644
--- a/terminus-terminal/src/config.ts
+++ b/terminus-terminal/src/config.ts
@@ -75,7 +75,13 @@ export class TerminalConfigProvider extends ConfigProvider {
                     ['Ctrl-A', 'Ctrl-C'],
                     '⌘-T',
                     '⌘-N',
-                ]
+                ],
+                'home': ['⌘-ArrowLeft', 'Home'],
+                'end': ['⌘-ArrowRight', 'End'],
+                'previous-word': ['⌥-ArrowLeft'],
+                'next-word': ['⌥-ArrowRight'],
+                'delete-previous-word': ['⌥-Backspace'],
+                'delete-next-word': ['⌥-Delete'],
             },
         },
         [Platform.Windows]: {
@@ -108,7 +114,13 @@ export class TerminalConfigProvider extends ConfigProvider {
                     ['Ctrl-A', 'C'],
                     ['Ctrl-A', 'Ctrl-C'],
                     'Ctrl-Shift-T',
-                ]
+                ],
+                'home': ['Home'],
+                'end': ['End'],
+                'previous-word': ['Ctrl-ArrowLeft'],
+                'next-word': ['Ctrl-ArrowRight'],
+                'delete-previous-word': ['Ctrl-Backspace'],
+                'delete-next-word': ['Ctrl-Delete'],
             },
         },
         [Platform.Linux]: {
@@ -139,7 +151,13 @@ export class TerminalConfigProvider extends ConfigProvider {
                     ['Ctrl-A', 'C'],
                     ['Ctrl-A', 'Ctrl-C'],
                     'Ctrl-Shift-T',
-                ]
+                ],
+                'home': ['Home'],
+                'end': ['End'],
+                'previous-word': ['Ctrl-ArrowLeft'],
+                'next-word': ['Ctrl-ArrowRight'],
+                'delete-previous-word': ['Ctrl-Backspace'],
+                'delete-next-word': ['Ctrl-Delete'],
             },
         },
     }
diff --git a/terminus-terminal/src/hotkeys.ts b/terminus-terminal/src/hotkeys.ts
index dc19d04c..53e01ead 100644
--- a/terminus-terminal/src/hotkeys.ts
+++ b/terminus-terminal/src/hotkeys.ts
@@ -8,6 +8,30 @@ export class TerminalHotkeyProvider extends HotkeyProvider {
             id: 'copy',
             name: 'Copy to clipboard',
         },
+        {
+            id: 'home',
+            name: 'Beginning of the line',
+        },
+        {
+            id: 'end',
+            name: 'End of the line',
+        },
+        {
+            id: 'previous-word',
+            name: 'Jump to previous word',
+        },
+        {
+            id: 'next-word',
+            name: 'Jump to next word',
+        },
+        {
+            id: 'delete-previous-word',
+            name: 'Delete previous word',
+        },
+        {
+            id: 'delete-next-word',
+            name: 'Delete next word',
+        },
         {
             id: 'clear',
             name: 'Clear terminal',