mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
correctly return first search position and refresh screen
This commit is contained in:
11
cre.cpp
11
cre.cpp
@@ -434,14 +434,10 @@ static int findText(lua_State *L) {
|
||||
int origin = luaL_checkint(L, 3);
|
||||
bool reverse = luaL_checkint(L, 4);
|
||||
bool caseInsensitive = luaL_checkint(L, 5);
|
||||
const char *l_lastPatt = luaL_checkstring(L, 6);
|
||||
lString16 _lastPattern = lString16(l_lastPatt);
|
||||
|
||||
if ( pattern.empty() )
|
||||
return 0;
|
||||
if ( pattern!=_lastPattern && origin==1 )
|
||||
origin = 0;
|
||||
_lastPattern = pattern;
|
||||
|
||||
LVArray<ldomWord> words;
|
||||
lvRect rc;
|
||||
doc->text_view->GetPos( rc );
|
||||
@@ -483,7 +479,10 @@ static int findText(lua_State *L) {
|
||||
if ( ranges ) {
|
||||
if ( ranges->length()>0 ) {
|
||||
int pos = ranges->get(0)->start.y;
|
||||
doc->text_view->SetPos(pos);
|
||||
//doc->text_view->SetPos(pos); // commented out not to mask lua code which does the same
|
||||
CRLog::debug("# SetPos = %d", pos);
|
||||
lua_pushinteger(L, pos);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -600,21 +600,29 @@ end
|
||||
function CREReader:searchHighLight(search)
|
||||
Debug("FIXME CreReader::searchHighLight", search)
|
||||
|
||||
if self.last_search ~= nil then
|
||||
if self.last_search == nil or self.last_search.search == nil then
|
||||
self.last_search = {
|
||||
search = "",
|
||||
}
|
||||
end
|
||||
|
||||
self.doc:findText(
|
||||
local origin = 0 -- 0=current 1=next-last -1=first-current
|
||||
if self.last_search.search == search then
|
||||
origin = 1
|
||||
end
|
||||
|
||||
local pos = self.doc:findText(
|
||||
search,
|
||||
0, -- origin: 0=current 1=prev-first -1=backwards
|
||||
origin,
|
||||
0, -- reverse: boolean
|
||||
1, -- caseInsensitive: boolean
|
||||
self.last_search.search
|
||||
1 -- caseInsensitive: boolean
|
||||
)
|
||||
|
||||
self:redrawCurrentPage()
|
||||
if pos then
|
||||
self.pos = pos -- first metch position
|
||||
self:redrawCurrentPage()
|
||||
end
|
||||
|
||||
self.last_search.search = search
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user