]> git.mdlowis.com Git - projs/tide.git/commitdiff
Addeded shortcut for joining lines
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 19 May 2017 01:22:07 +0000 (21:22 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 19 May 2017 01:22:07 +0000 (21:22 -0400)
docs/xedit.1
docs/xedit.1.md
inc/edit.h
inc/shortcuts.h
lib/view.c
xedit.c

index 9fc7b8722244bb6c6cf090686b90ef56da4645ba..d70d41624e151d0e5c61599291cf51c7ee800f42 100644 (file)
@@ -181,6 +181,10 @@ Copy the selected text to the X11 CLIPBOARD selection\. If no text is selected t
 Paste the contents of the X11 CLIPBOARD selection to the active region\.
 .
 .TP
+\fBCtrl+j\fR
+Join the current line and the next line\.
+.
+.TP
 \fBDelete\fR
 Delete the character to the right\.
 .
index 55dd87c1ac1c1ca4377999b86c53b20451ffcaa4..7472123e6bd841258f2037744a14621cd4af3e1f 100644 (file)
@@ -218,6 +218,9 @@ position.
 * `Ctrl+v`:
     Paste the contents of the X11 CLIPBOARD selection to the active region.
 
+* `Ctrl+j`:
+    Join the current line and the next line.
+
 * `Delete`:
     Delete the character to the right.
 
index e4a2b1f869974b186e954afba477093ef7faa490..55a4196b482c2503c25bfe22f8cbc7adc73357e4 100644 (file)
@@ -171,6 +171,7 @@ void view_selword(View* view, size_t row, size_t col);
 void view_select(View* view, size_t row, size_t col);
 void view_jumpto(View* view, bool extsel, size_t off);
 void view_scrollto(View* view, size_t csr);
+Rune view_getrune(View* view);
 
 /* Command Executions
  *****************************************************************************/
index 9ada8c10469b1ebc0861c23035a73cb41afea587..f18471f1a242ce2c0cae41fa99da94bec899553c 100644 (file)
@@ -4,6 +4,17 @@ static void select_line(void) {
     view_selctx(view);
 }
 
+static void join_lines(void) {
+    View* view = win_view(FOCUSED);
+    view_eol(view, false);
+    view_delete(view, RIGHT, false);
+    Rune r = view_getrune(view);
+    for (; r == '\t' || r == ' '; r = view_getrune(view))
+        view_delete(view, RIGHT, false);
+    if (r != '\n' && r != RUNE_CRLF)
+        view_insert(view, false, ' ');
+}
+
 static void delete(void) {
     bool byword = x11_keymodsset(ModCtrl);
     view_delete(win_view(FOCUSED), RIGHT, byword);
index 9567baeab6adb06cfc00c3eb6f3b8617e15420b5..996c965f0dec369c3159bf93c4fb1c369870bdf1 100644 (file)
@@ -578,3 +578,7 @@ void view_indent(View* view, int dir) {
 
    } while (off && off >= view->selection.beg);
 }
+
+Rune view_getrune(View* view) {
+    return buf_get(&(view->buffer), view->selection.end);
+}
diff --git a/xedit.c b/xedit.c
index 234488ddf4126a01f3163928bbb7a12b3ad91688..0809f49e7712ec8cd7be27e8dcb602d82a959449 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -365,12 +365,13 @@ static KeyBinding Bindings[] = {
     { ModCtrl, 'e', cursor_eol  },
 
     /* Standard Text Editing Shortcuts */
-    { ModCtrl, 's', save  },
-    { ModCtrl, 'z', undo  },
-    { ModCtrl, 'y', redo  },
-    { ModCtrl, 'x', cut   },
-    { ModCtrl, 'c', copy  },
-    { ModCtrl, 'v', paste },
+    { ModCtrl, 's', save       },
+    { ModCtrl, 'z', undo       },
+    { ModCtrl, 'y', redo       },
+    { ModCtrl, 'x', cut        },
+    { ModCtrl, 'c', copy       },
+    { ModCtrl, 'v', paste      },
+    { ModCtrl, 'j', join_lines },
 
     /* Block Indent */
     { ModCtrl, '[', del_indent },