From 7d10a636e732474477fffa0a8a6968734916fec6 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 28 Aug 2012 21:56:46 +0200 Subject: [PATCH] correctly return first search position and refresh screen --- cre.cpp | 11 +++++------ crereader.lua | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cre.cpp b/cre.cpp index 16dda017d..dbba4d75b 100644 --- a/cre.cpp +++ b/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 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; diff --git a/crereader.lua b/crereader.lua index 3b2cbd4c9..1d8141755 100644 --- a/crereader.lua +++ b/crereader.lua @@ -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