Skip to content

Commit

Permalink
added scrolling to search matches (albeit awkward^^)
Browse files Browse the repository at this point in the history
  • Loading branch information
karottenreibe committed Sep 2, 2011
1 parent 1578e26 commit 74d7cde
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/search.lua
Expand Up @@ -189,7 +189,7 @@ for k, m in pairs({
s.cur = c
end
if not m then return false end
doc:highlight_match(m.match)
doc:highlight_match(m)
return true
end,

Expand Down
4 changes: 4 additions & 0 deletions widgets/document.c
Expand Up @@ -83,6 +83,10 @@ luaH_document_push_indexed_table(lua_State *L, lua_CFunction index, lua_CFunctio
{
/* create table */
lua_newtable(L);
/* store light userdata */
lua_pushliteral(L, "__data");
lua_pushvalue(L, idx); /* copy userdata */
lua_rawset(L, -3);
/* setup metatable */
lua_createtable(L, 0, 2);
/* push __index metafunction */
Expand Down
29 changes: 27 additions & 2 deletions widgets/document/search.c
Expand Up @@ -35,10 +35,35 @@ static gint
luaH_document_highlight_match(lua_State *L)
{
document_data_t *d = luaH_checkdocument_data(L, 1);
GList *match = lua_touserdata(L, 2);
if (!match)
luaH_checktable(L, 2);

// TODO: handle this with out __data and remove __data again
lua_pushstring(L, "page");
lua_gettable(L, -2);
lua_pushstring(L, "__data");
lua_rawget(L, -2);
page_info_t *p = lua_touserdata(L, -1);
lua_pop(L, 2);

lua_pushstring(L, "match");
lua_gettable(L, -2);
GList *match = lua_touserdata(L, -1);
lua_pop(L, 1);

if (!match || !p)
luaL_typerror(L, 2, "search match");

d->current_match = match;

/* scroll to match */
// TODO let lua handle that
PopplerRectangle *r = (PopplerRectangle*) match->data;
cairo_rectangle_int_t *pc = page_coordinates_from_pdf_coordinates(r, p);
cairo_rectangle_int_t *dc = document_coordinates_from_page_coordinates(pc, p);
d->hadjust->value = dc->x;
d->vadjust->value = dc->y;
g_free(dc);
g_free(pc);
document_render(d);
return 0;
}
Expand Down

0 comments on commit 74d7cde

Please sign in to comment.