netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/ecrire.git/commit/?id=4c157c4982f1338d56294a4afcedd9ad29e6cfb1

commit 4c157c4982f1338d56294a4afcedd9ad29e6cfb1
Author: Alastair Poole <nets...@gmail.com>
Date:   Thu Apr 8 11:00:29 2021 +0100

    search: remove the dialog.
    
    WIP.
---
 src/bin/Ecrire.h           |  1 +
 src/bin/main.c             | 38 +++++++++++++-------------------------
 src/bin/ui/search_dialog.c | 40 ++++++++++++++++++++++++----------------
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/src/bin/Ecrire.h b/src/bin/Ecrire.h
index 8bacd45..b9f1a4a 100644
--- a/src/bin/Ecrire.h
+++ b/src/bin/Ecrire.h
@@ -18,6 +18,7 @@ typedef struct _Ecrire_Editor
      Evas_Object *frame;
      Evas_Object *entry;
 
+     Evas_Object *search_win;
      Evas_Object *settings_popup;
 
      struct
diff --git a/src/bin/main.c b/src/bin/main.c
index bf85dee..b4562fc 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -31,19 +31,14 @@ _editor_del(void *data)
    Elm_Entry_Change_Info *inf;
    EINA_LIST_FREE(inst->undo_stack, inf)
      {
-        if (inf)
-          {
-             if (inf->insert)
-               {
-                  eina_stringshare_del(inf->change.insert.content);
-               }
-             else
-               {
-                  eina_stringshare_del(inf->change.del.content);
-               }
-             free(inf);
-          }
+        if (!inf) continue;
+        if (inf->insert)
+          eina_stringshare_del(inf->change.insert.content);
+        else
+          eina_stringshare_del(inf->change.del.content);
+        free(inf);
      }
+   if (inst->search_win) evas_object_del(inst->search_win);
    evas_object_del(inst->win);
    eina_stringshare_del(inst->filename);
    free(inst);
@@ -57,21 +52,14 @@ _editor_reset(Ecrire_Editor *inst)
    elm_object_text_set(inst->entry, "");
    ecrire_editor_font_set(inst, inst->font.name, inst->font.size);
 
-   /* Init the undo stack */
    EINA_LIST_FREE(inst->undo_stack, inf)
      {
-        if (inf)
-          {
-             if (inf->insert)
-               {
-                  eina_stringshare_del(inf->change.insert.content);
-               }
-             else
-               {
-                  eina_stringshare_del(inf->change.del.content);
-               }
-             free(inf);
-          }
+        if (!inf) continue;
+        if (inf->insert)
+          eina_stringshare_del(inf->change.insert.content);
+        else
+          eina_stringshare_del(inf->change.del.content);
+        free(inf);
      }
    inst->undo_stack = inst->undo_stack_ptr =
       eina_list_append(inst->undo_stack, NULL);
diff --git a/src/bin/ui/search_dialog.c b/src/bin/ui/search_dialog.c
index 9328d30..9af445a 100644
--- a/src/bin/ui/search_dialog.c
+++ b/src/bin/ui/search_dialog.c
@@ -10,6 +10,7 @@ typedef struct
   Ecrire_Editor          *inst;
 
   int                    initial_pos;
+  int                    prev_find_pos;
   Eina_Bool              forwards;
   Eina_Bool              wrap;
   Evas_Textblock_Cursor *cur_find;
@@ -71,11 +72,6 @@ _search_replace(Entry_Search *search, const char *text, 
Eina_Bool jump_next)
         if (!found)
           {
              found = utf8;
-             if (search->wrap)
-               {
-                  elm_entry_cursor_pos_set(entry, 0);
-                  return 0;
-               }
           }
      }
    else
@@ -97,12 +93,20 @@ _search_replace(Entry_Search *search, const char *text, 
Eina_Bool jump_next)
 #endif
           }
 
-        elm_entry_select_none(entry);
-        evas_textblock_cursor_pos_set(mcur, pos + initial_pos + strlen(text));
-        elm_entry_cursor_selection_begin(entry);
-        elm_entry_cursor_pos_set(entry, pos + initial_pos);
-        elm_entry_cursor_selection_end(entry);
-        evas_textblock_cursor_copy(mcur, search->cur_find);
+       if ((search->wrap) && (search->prev_find_pos == (pos + initial_pos)))
+          {
+             elm_entry_cursor_pos_set(entry, 0);
+          }
+        else
+          {
+             elm_entry_select_none(entry);
+             evas_textblock_cursor_pos_set(mcur, pos + initial_pos + 
strlen(text));
+             elm_entry_cursor_selection_begin(entry);
+             elm_entry_cursor_pos_set(entry, pos + initial_pos);
+             elm_entry_cursor_selection_end(entry);
+             evas_textblock_cursor_copy(mcur, search->cur_find);
+             search->prev_find_pos = pos + initial_pos;
+          }
      }
 
    free(utf8);
@@ -160,6 +164,7 @@ _cb_win_del(void *data EINA_UNUSED, Evas *e, Evas_Object 
*obj, void *event_info)
    if (search->cur_find)
      evas_textblock_cursor_free(search->cur_find);
 
+   search->inst->search_win = NULL;
    free(search);
 }
 
@@ -171,17 +176,16 @@ ui_find_dialog_open(Evas_Object *parent, Ecrire_Editor 
*inst)
    const Evas_Object *tb;
    Evas_Textblock_Cursor *cursor;
 
+   if (inst->search_win) return NULL;
+
    Entry_Search *search = calloc(1, sizeof(Entry_Search));
    EINA_SAFETY_ON_NULL_RETURN_VAL(search, NULL);
 
    search->inst = inst;
+   search->wrap = 1;
    search->forwards = 1;
 
-   tb = elm_entry_textblock_get(inst->entry);
-   cursor = (Evas_Textblock_Cursor *) evas_object_textblock_cursor_get(tb);
-   search->initial_pos = evas_textblock_cursor_pos_get(cursor);
-
-   win = elm_win_add(parent, "search", ELM_WIN_TOOLBAR);
+   search->inst->search_win = win = elm_win_add(parent, "search", 
ELM_WIN_TOOLBAR);
    elm_win_autodel_set(win, EINA_TRUE);
    elm_win_title_set(win, _("Search"));
    evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cb_win_del, search);
@@ -270,6 +274,10 @@ ui_find_dialog_open(Evas_Object *parent, Ecrire_Editor 
*inst)
    evas_object_show(chk);
    evas_object_smart_callback_add(chk, "changed", _cb_wrap_changed, search);
 
+   tb = elm_entry_textblock_get(inst->entry);
+   cursor = (Evas_Textblock_Cursor *) evas_object_textblock_cursor_get(tb);
+   search->initial_pos = evas_textblock_cursor_pos_get(cursor);
+
    /* Forcing it to be the min height. */
    evas_object_resize(win, 250, 1);
    evas_object_show(win);

-- 


Reply via email to