Skip to content

Commit

Permalink
Update bookmark list also on any line changes in the document
Browse files Browse the repository at this point in the history
In addition to updating the bookmark list on document notebook tab change
and adding/removing line markers, also rebuild the bookmark list
when the text in the document changes with lines added or deleted.

Should fix SF bugs geany#129 and geany#39.
  • Loading branch information
eht16 committed Sep 20, 2015
1 parent 88a5cfa commit 3d3df5c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions addons/src/ao_bookmarklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct _AoBookmarkListPrivate
typedef struct
{
AoBookmarkList *bm;
GeanyDocument *document;
guint document_id;
} AoBookmarkListRefreshContainer;

enum
Expand Down Expand Up @@ -416,11 +416,12 @@ static gboolean update_bookmark_list_delayed(gpointer data)
AoBookmarkListRefreshContainer *container = data;
AoBookmarkList *bm = container->bm;
AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);
GeanyDocument *doc = container->document;
ScintillaObject *sci = doc->editor->sci;
GeanyDocument *doc = document_find_by_id(container->document_id);

if (priv->enable_bookmarklist && DOC_VALID(doc))
if (priv->enable_bookmarklist && doc != NULL)
{
ScintillaObject *sci = doc->editor->sci;

gtk_list_store_clear(priv->store);
while ((line_nr = scintilla_send_message(sci, SCI_MARKERNEXT, line_nr, mask)) != -1)
{
Expand All @@ -438,11 +439,13 @@ static gboolean update_bookmark_list_delayed(gpointer data)
void ao_bookmark_list_update(AoBookmarkList *bm, GeanyDocument *doc)
{
AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);

if (priv->refresh_idle_source_id == 0)
{
AoBookmarkListRefreshContainer *container = g_new0(AoBookmarkListRefreshContainer, 1);

container->bm = bm;
container->document = doc;
container->document_id = doc->id;
priv->refresh_idle_source_id = plugin_idle_add(
geany_plugin,
update_bookmark_list_delayed,
Expand All @@ -455,16 +458,23 @@ void ao_bookmark_list_update_marker(AoBookmarkList *bm, GeanyEditor *editor, SCN
{
AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);

if (priv->enable_bookmarklist &&
nt->nmhdr.code == SCN_MODIFIED && nt->modificationType == SC_MOD_CHANGEMARKER)
if (priv->enable_bookmarklist && nt->nmhdr.code == SCN_MODIFIED)
{
if (sci_is_marker_set_at_line(editor->sci, nt->line, 1))
if (nt->modificationType == SC_MOD_CHANGEMARKER)
{
add_line(bm, editor->sci, nt->line);
if (sci_is_marker_set_at_line(editor->sci, nt->line, 1))
{
add_line(bm, editor->sci, nt->line);
}
else
{
delete_line(bm, nt->line);
}
}
else
else if (nt->linesAdded != 0)
{
delete_line(bm, nt->line);
/* if any lines changed, refresh the whole list as we refer line numbers */
ao_bookmark_list_update(bm, editor->document);
}
}
}
Expand Down

0 comments on commit 3d3df5c

Please sign in to comment.