]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed some abstraction leaks in view
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 17:23:57 +0000 (13:23 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Apr 2018 17:23:57 +0000 (13:23 -0400)
inc/edit.h
lib/view.c
lib/x11.c
tide.c

index b98a1c8c892fc1ed701e7e765a8e86131ace8eab..231c6fa9d6fe6cf3e2782c03cedd2f08a183db79 100644 (file)
@@ -128,6 +128,7 @@ void view_redo(View* view);
 void view_putstr(View* view, char* str);
 char* view_getstr(View* view, Sel* sel);
 char* view_getcmd(View* view);
+char* view_getword(View* view);
 char* view_getctx(View* view);
 void view_selctx(View* view);
 void view_scroll(View* view, int move);
@@ -142,6 +143,8 @@ 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);
+void view_selectall(View* view);
+void view_selectobj(View* view, bool (*istype)(Rune));
 
 /* Command Executions
  *****************************************************************************/
index 6c50d6836111672029b083376fdaa67f2c775da2..6f62db7ce2e4b048618f2fc5671d093544cab1a9 100644 (file)
@@ -282,6 +282,16 @@ void view_scrollto(View* view, size_t csr) {
     }
 }
 
+void view_selectall(View* view) {
+    view->selection = (Sel){ .beg = 0, .end = buf_end(&(view->buffer)) };
+    view->sync_needed = true;
+}
+
+void view_selectobj(View* view, bool (*istype)(Rune)) {
+    buf_getword(&(view->buffer), istype, &(view->selection));
+    view->sync_needed = true;
+}
+
 static void move_selection(View* view, bool extsel, Sel* sel, int move, movefn_t bything) {
     view->sync_needed = true;
     if (num_selected(*sel) && !extsel) {
index fd7aa20fda6a6da89010143e444b372c32d25d17..716d5e13d5bb43ccbf3454f192115174b3d48da4 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -137,9 +137,6 @@ void win_init(KeyBinding* bindings) {
     Keys = bindings;
     CurrFont = x11_font_load(FontString);
     View* view = win_view(TAGS);
-    view->buffer.gapstart = view->buffer.bufstart;
-    view->buffer.gapend   = view->buffer.bufend;
-    view->selection = (Sel){0,0,0};
     view_putstr(view, TagString);
     view_selprev(view); // clear the selection
     buf_logclear(&(view->buffer));
@@ -191,8 +188,6 @@ 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.");
     before = now;
 }
 
diff --git a/tide.c b/tide.c
index f732aa386f11a28c1c6eb4de02ea7215bb1d3168..6e3f638d3a1744f1786a012c8e65d274d53c29b1 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -40,9 +40,7 @@ static void select_line(char* arg) {
 }
 
 static void select_all(char* arg) {
-    View* view = win_view(FOCUSED);
-    view_jumpto(view, false, buf_end(&(view->buffer)));
-    view->selection.beg = 0;
+    view_selectall(win_view(FOCUSED));
 }
 
 static void join_lines(char* arg) {
@@ -73,11 +71,7 @@ void cut(char* arg) {
     /* now perform the cut */
     char* str = view_getstr(view, NULL);
     x11_sel_set(CLIPBOARD, str);
-    if (str && *str) {
-        delete(arg);
-        if (view->selection.end == buf_end(&(view->buffer)))
-            view_delete(view, LEFT, false);
-    }
+    if (str && *str) delete(arg);
 }
 
 void paste(char* arg) {
@@ -241,7 +235,7 @@ static void cmd_exec(char* cmd) {
 
     /* get the selection that the command will operate on */
     if (op && op != '<' && op != '!' && 0 == view_selsize(win_view(EDIT)))
-        win_view(EDIT)->selection = (Sel){ .beg = 0, .end = buf_end(win_buf(EDIT)) };
+        view_selectall(win_view(EDIT));
     char* input = view_getstr(win_view(EDIT), NULL);
     size_t len  = (input ? strlen(input) : 0);
     View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED);
@@ -345,8 +339,8 @@ static void pick_ctag(char* arg) {
 
 static void complete(char* arg) {
     View* view = win_view(FOCUSED);
-    buf_getword(&(view->buffer), risword, &(view->selection));
-    view->selection.end = buf_byrune(&(view->buffer), view->selection.end, RIGHT);
+    view_selectobj(view, risword);
+    view_byrune(view, RIGHT, true);
     cmd_execwitharg(CMD_COMPLETE, view_getstr(view, NULL));
 }
 
@@ -390,11 +384,6 @@ static void newline(char* arg) {
     if (x11_keymodsset(ModShift)) {
         view_byline(view, UP, false);
         view_bol(view, false);
-        if (view->selection.end == 0) {
-            view_insert(view, true, '\n');
-            view->selection = (Sel){0,0,0};
-            return;
-        }
     }
     view_eol(view, false);
     view_insert(view, true, '\n');