Skip to content
Browse files

add getPosFromXPointer in cre.cpp

  • Loading branch information...
1 parent 763e222 commit d04370464b92316a0c0a32008f77c2b93be9ea31 @houqp houqp committed
Showing with 16 additions and 14 deletions.
  1. +16 −14 cre.cpp
View
30 cre.cpp
@@ -117,28 +117,29 @@ static int getPageFromXPointer(lua_State *L) {
return 1;
}
-static int getCurrentPos(lua_State *L) {
+static int getPosFromXPointer(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
+ const char *xpointer_str = luaL_checkstring(L, 2);
- lua_pushinteger(L, doc->text_view->GetPos());
+ int pos = 0;
+ ldomXPointer xp = doc->dom_doc->createXPointer(lString16(xpointer_str));
+
+ lvPoint pt = xp.toPoint();
+ if (pt.y > 0) {
+ pos = pt.y;
+ }
+ lua_pushinteger(L, pos);
return 1;
}
-//static int getPosFromXPointer(lua_State *L) {
- //CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
- //const char *xpointer_str = luaL_checkstring(L, 2);
-
- //lvRect rc;
- //int pos;
+static int getCurrentPos(lua_State *L) {
+ CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
- //ldomXPointer *xp = NULL;
- //xp = doc->dom_doc->createXPointer(lString16(xpointer_str));
- //getCursorDocRect(*xp, rc);
- //pos =
+ lua_pushinteger(L, doc->text_view->GetPos());
- //return 1;
-//}
+ return 1;
+}
static int getCurrentPercent(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
@@ -437,6 +438,7 @@ static const struct luaL_Reg credocument_meth[] = {
{"getPages", getNumberOfPages},
{"getCurrentPage", getCurrentPage},
{"getPageFromXPointer", getPageFromXPointer},
+ {"getPosFromXPointer", getPosFromXPointer},
{"getCurrentPos", getCurrentPos},
{"getCurrentPercent", getCurrentPercent},
{"getXPointer", getXPointer},

0 comments on commit d043704

Please sign in to comment.
Something went wrong with that request. Please try again.