]> git.mdlowis.com Git - projs/tide.git/commitdiff
cleaned up some selection handling code
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 16:22:26 +0000 (12:22 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 16:22:26 +0000 (12:22 -0400)
inc/edit.h
lib/buf.c
lib/view.c
lib/x11.c

index 2c67658162d066b789da8fc985e7b726b6ade4c8..b98a1c8c892fc1ed701e7e765a8e86131ace8eab 100644 (file)
@@ -126,7 +126,6 @@ void view_eof(View* view, bool extsel);
 void view_undo(View* view);
 void view_redo(View* view);
 void view_putstr(View* view, char* str);
-void view_append(View* view, char* str);
 char* view_getstr(View* view, Sel* sel);
 char* view_getcmd(View* view);
 char* view_getctx(View* view);
index 585ce838b0efb6f35e6a09cd941ad4668e81dc9e..db1f5b451743c478f8636eaaa21c0a00dd580fc8 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -28,7 +28,7 @@ void buf_init(Buf* buf) {
     /* reset the state to defaults */
     buf->modified  = false;
     buf->bufsize   = 8192;
-    buf->bufstart  = (char*)malloc(buf->bufsize);
+    buf->bufstart  = malloc(buf->bufsize);
     buf->bufend    = buf->bufstart + buf->bufsize;
     buf->gapstart  = buf->bufstart;
     buf->gapend    = buf->bufend;
index 92e0373837473454a412c4050f542d87fb2c6d2f..6c50d6836111672029b083376fdaa67f2c775da2 100644 (file)
@@ -133,9 +133,7 @@ void view_selprev(View* view) {
 
 void view_select(View* view, size_t row, size_t col) {
     view_setcursor(view, row, col, false);
-    Sel sel = view->selection;
-    select_context(view, risword, &sel);
-    view->selection = sel;
+    select_context(view, risword, &(view->selection));
 }
 
 size_t view_selsize(View* view) {
@@ -174,12 +172,10 @@ void view_insert(View* view, bool indent, Rune rune) {
 }
 
 void view_delete(View* view, int dir, bool byword) {
-    Sel* sel = &(view->selection);
-    if (sel->beg == sel->end)
+    if (view->selection.beg == view->selection.end)
         (byword ? view_byword : view_byrune)(view, dir, true);
-    selswap(sel);
-    buf_del(&(view->buffer), sel);
-    move_to(view, false, sel->beg);
+    buf_del(&(view->buffer), &(view->selection));
+    move_to(view, false, view->selection.end);
 }
 
 void view_jumpto(View* view, bool extsel, size_t off) {
@@ -228,39 +224,17 @@ void view_redo(View* view) {
 }
 
 void view_putstr(View* view, char* str) {
-    selswap(&(view->selection));
-    unsigned beg = view->selection.beg;
-    while (*str) {
-        Rune rune = 0;
-        size_t length = 0;
-        while (!utf8decode(&rune, &length, *str++));
-        view_insert(view, false, rune);
-    }
-    view->selection.beg = beg;
-}
-
-void view_append(View* view, char* str) {
-    size_t end = buf_end(&(view->buffer));
-    if (view->selection.end != end)
-        view->selection = (Sel){ .beg = end, .end = end };
-    if (!num_selected(view->selection) && !buf_iseol(&(view->buffer), view->selection.end-1)) {
-        buf_putc(&(view->buffer), '\n', &(view->selection));
-        view->selection.beg++;
-    }
-    unsigned beg = view->selection.beg;
-    view_putstr(view, str);
-    view->selection.beg = beg;
+    buf_puts(&(view->buffer), str, &(view->selection));
 }
 
 char* view_getstr(View* view, Sel* range) {
-    return buf_gets(&(view->buffer), &(view->selection));
+    return buf_gets(&(view->buffer), (range ? range : &(view->selection)));
 }
 
 char* view_getcmd(View* view) {
-    Sel sel = view->selection;
-    if (!num_selected(sel))
-        select_context(view, riscmd, &sel);
-    return view_getstr(view, &sel);
+    if (!num_selected(view->selection))
+        select_context(view, riscmd, &(view->selection));
+    return view_getstr(view, NULL);
 }
 
 void view_selctx(View* view) {
index cc60f9fe1d3f1f8659f8a067057d4d44724b6066..fd7aa20fda6a6da89010143e444b372c32d25d17 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -191,8 +191,8 @@ void win_quit(void) {
     uint64_t now = getmillis();
     if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime)
         exit(0);
-    else
-        view_append(win_view(TAGS), "File is modified.");
+//    else
+//        view_append(win_view(TAGS), "File is modified.");
     before = now;
 }
 
@@ -495,8 +495,8 @@ static void xfocus(XEvent* e) {
     if (X.xic)
         (e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic);
     Buf* buf = win_buf(EDIT);
-    if (buf->path && buf->modtime != modtime(buf->path))
-        view_append(win_view(TAGS), "File modified externally: Get {Put }");
+//    if (buf->path && buf->modtime != modtime(buf->path))
+//        view_append(win_view(TAGS), "File modified externally: Get {Put }");
 }
 
 static void xkeypress(XEvent* e) {