Commit 71918258 authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed bug #34313 Reworked a passing through the search results.

parent 6e3c1a57
...@@ -226,7 +226,14 @@ CDocumentSearch.prototype.GetFootnotes = function() ...@@ -226,7 +226,14 @@ CDocumentSearch.prototype.GetFootnotes = function()
{ {
return this.Footnotes; return this.Footnotes;
}; };
CDocumentSearch.prototype.GetDirection = function()
{
return this.Direction;
};
CDocumentSearch.prototype.SetDirection = function(bDirection)
{
this.Direction = bDirection;
};
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// CDocument // CDocument
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
...@@ -269,7 +276,6 @@ CDocument.prototype.Search = function(Str, Props, bDraw) ...@@ -269,7 +276,6 @@ CDocument.prototype.Search = function(Str, Props, bDraw)
return this.SearchEngine; return this.SearchEngine;
}; };
CDocument.prototype.Search_Select = function(Id) CDocument.prototype.Search_Select = function(Id)
{ {
this.Selection_Remove(); this.Selection_Remove();
...@@ -280,7 +286,6 @@ CDocument.prototype.Search_Select = function(Id) ...@@ -280,7 +286,6 @@ CDocument.prototype.Search_Select = function(Id)
this.Document_UpdateSelectionState(); this.Document_UpdateSelectionState();
this.Document_UpdateRulersState(); this.Document_UpdateRulersState();
}; };
CDocument.prototype.Search_Replace = function(NewStr, bAll, Id) CDocument.prototype.Search_Replace = function(NewStr, bAll, Id)
{ {
var bResult = false; var bResult = false;
...@@ -350,114 +355,151 @@ CDocument.prototype.Search_Replace = function(NewStr, bAll, Id) ...@@ -350,114 +355,151 @@ CDocument.prototype.Search_Replace = function(NewStr, bAll, Id)
return bResult; return bResult;
}; };
CDocument.prototype.Search_GetId = function(bNext) CDocument.prototype.Search_GetId = function(bNext)
{ {
this.SearchEngine.Set_Direction( bNext ); var Id = null;
// Получим Id найденного элемента
if ( docpostype_DrawingObjects === this.CurPos.Type )
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
var Id = ParaDrawing.Search_GetId( bNext, true ); this.SearchEngine.SetDirection(bNext);
if ( null != Id )
return Id;
this.DrawingObjects.resetSelection(); if (docpostype_DrawingObjects === this.CurPos.Type)
ParaDrawing.GoTo_Text( true === bNext ? false : true, false ); {
} var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
if ( docpostype_Content === this.CurPos.Type )
{
var Id = null;
var Pos = this.CurPos.ContentPos; Id = ParaDrawing.Search_GetId(bNext, true);
if ( true === this.Selection.Use && selectionflag_Common === this.Selection.Flag ) if (null != Id)
Pos = ( true === bNext ? Math.max(this.Selection.StartPos, this.Selection.EndPos) : Math.min(this.Selection.StartPos, this.Selection.EndPos) ); return Id;
var StartPos = Pos; this.DrawingObjects.resetSelection();
ParaDrawing.GoTo_Text(true === bNext ? false : true, false);
}
if ( true === bNext ) if (docpostype_Content === this.CurPos.Type)
{ {
Id = this.Content[Pos].Search_GetId(true, true); Id = this.private_GetSearchIdInMainDocument(true);
if ( null != Id ) if (null === Id)
return Id; Id = this.private_GetSearchIdInFootnotes(false);
Pos++; if (null === Id)
Id = this.private_GetSearchIdInHdrFtr(false);
var Count = this.Content.length; if (null === Id)
while ( Pos < Count ) Id = this.private_GetSearchIdInMainDocument(false);
{ }
Id = this.Content[Pos].Search_GetId(true, false); else if (docpostype_HdrFtr === this.CurPos.Type)
{
Id = this.private_GetSearchIdInHdrFtr(true);
if ( null != Id ) if (null === Id)
return Id; Id = this.private_GetSearchIdInMainDocument(false);
Pos++; if (null === Id)
} Id = this.private_GetSearchIdInFootnotes(false);
Pos = 0; if (null === Id)
while ( Pos <= StartPos ) Id = this.private_GetSearchIdInHdrFtr(false);
{ }
Id = this.Content[Pos].Search_GetId(true, false); else if (docpostype_Footnotes === this.CurPos.Type)
{
Id = this.private_GetSearchIdInFootnotes(true);
if ( null != Id ) if (null === Id)
return Id; Id = this.private_GetSearchIdInHdrFtr(false);
Pos++; if (null === Id)
} Id = this.private_GetSearchIdInMainDocument(false);
return null; if (null === Id)
} Id = this.private_GetSearchIdInFootnotes(false);
else }
{
Id = this.Content[Pos].Search_GetId(false, true);
if ( null != Id ) return Id;
return Id; };
CDocument.prototype.Search_Set_Selection = function(bSelection)
{
var OldValue = this.SearchEngine.Selection;
if ( OldValue === bSelection )
return;
Pos--; this.SearchEngine.Selection = bSelection;
this.DrawingDocument.ClearCachePages();
this.DrawingDocument.FirePaint();
};
CDocument.prototype.Search_Get_Selection = function()
{
return this.SearchEngine.Selection;
};
CDocument.prototype.private_GetSearchIdInMainDocument = function(isCurrent)
{
var Id = null;
var bNext = this.SearchEngine.GetDirection();
var Pos = this.CurPos.ContentPos;
if (true === this.Selection.Use && selectionflag_Common === this.Selection.Flag)
Pos = bNext ? Math.max(this.Selection.StartPos, this.Selection.EndPos) : Math.min(this.Selection.StartPos, this.Selection.EndPos);
while ( Pos >= 0 ) if (true !== isCurrent)
{ Pos = bNext ? 0 : this.Content.length - 1;
Id = this.Content[Pos].Search_GetId(false, false);
if ( null != Id ) if (true === bNext)
return Id; {
Id = this.Content[Pos].Search_GetId(true, isCurrent);
Pos--; if (null != Id)
} return Id;
Pos = this.Content.length - 1; Pos++;
while ( Pos >= StartPos )
{
Id = this.Content[Pos].Search_GetId(false, false);
if ( null != Id ) var Count = this.Content.length;
return Id; while (Pos < Count)
{
Id = this.Content[Pos].Search_GetId(true, false);
Pos--; if (null != Id)
} return Id;
return null; Pos++;
} }
} }
else if ( docpostype_HdrFtr === this.CurPos.Type ) else
{
return this.SectionsInfo.Search_GetId( bNext, this.HdrFtr.CurHdrFtr );
}
else if (docpostype_Footnotes === this.CurPos.Type)
{ {
var oCurFootnote = this.Footnotes.CurFootnote; Id = this.Content[Pos].Search_GetId(false, isCurrent);
var Id = oCurFootnote.Search_GetId(bNext, true);
if (null !== Id) if (null != Id)
return Id; return Id;
var arrFootnotes = this.SearchEngine.GetFootnotes(); Pos--;
var nCurPos = -1;
var nCount = arrFootnotes.length; while (Pos >= 0)
{
Id = this.Content[Pos].Search_GetId(false, false);
if (null != Id)
return Id;
Pos--;
}
}
return Id;
};
CDocument.prototype.private_GetSearchIdInHdrFtr = function(isCurrent)
{
return this.SectionsInfo.Search_GetId(this.SearchEngine.GetDirection(), isCurrent ? this.HdrFtr.CurHdrFtr : null);
};
CDocument.prototype.private_GetSearchIdInFootnotes = function(isCurrent)
{
var bNext = this.SearchEngine.GetDirection();
var oCurFootnote = this.Footnotes.CurFootnote;
var arrFootnotes = this.SearchEngine.GetFootnotes();
var nCurPos = -1;
var nCount = arrFootnotes.length;
if (nCount <= 0)
return null;
if (isCurrent)
{
for (var nIndex = 0; nIndex < nCount; ++nIndex) for (var nIndex = 0; nIndex < nCount; ++nIndex)
{ {
if (arrFootnotes[nIndex] === oCurFootnote) if (arrFootnotes[nIndex] === oCurFootnote)
...@@ -466,49 +508,40 @@ CDocument.prototype.Search_GetId = function(bNext) ...@@ -466,49 +508,40 @@ CDocument.prototype.Search_GetId = function(bNext)
break; break;
} }
} }
}
if (-1 == nCurPos)
{
nCurPos = bNext ? 0 : nCount - 1;
oCurFootnote = arrFootnotes[nCurPos];
isCurrent = false;
}
if (-1 === nCurPos) var Id = oCurFootnote.Search_GetId(bNext, isCurrent);
return null; if (null !== Id)
return Id;
if (true === bNext) if (true === bNext)
{
for (var nIndex = nCurPos + 1; nIndex < nCount; ++nIndex)
{ {
for (var nIndex = nCurPos + 1; nIndex < nCount; ++nIndex) Id = arrFootnotes[nIndex].Search_GetId(bNext, false);
{ if (null != Id)
Id = arrFootnotes[nIndex].Search_GetId(bNext, false); return Id;
if (null != Id)
return Id;
}
} }
else }
else
{
for (var nIndex = nCurPos - 1; nIndex >= 0; --nIndex)
{ {
for (var nIndex = nCurPos - 1; nIndex >= 0; --nIndex) Id = arrFootnotes[nIndex].Search_GetId(bNext, false);
{ if (null != Id)
Id = arrFootnotes[nIndex].Search_GetId(bNext, false); return Id;
if (null != Id)
return Id;
}
} }
} }
return null; return null;
};
CDocument.prototype.Search_Set_Selection = function(bSelection)
{
var OldValue = this.SearchEngine.Selection;
if ( OldValue === bSelection )
return;
this.SearchEngine.Selection = bSelection;
this.DrawingDocument.ClearCachePages();
this.DrawingDocument.FirePaint();
}; };
CDocument.prototype.Search_Get_Selection = function()
{
return this.SearchEngine.Selection;
};
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// CDocumentContent // CDocumentContent
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
...@@ -660,97 +693,106 @@ CDocumentSectionsInfo.prototype.Search = function(Str, Props, SearchEngine) ...@@ -660,97 +693,106 @@ CDocumentSectionsInfo.prototype.Search = function(Str, Props, SearchEngine)
}; };
CDocumentSectionsInfo.prototype.Search_GetId = function(bNext, CurHdrFtr) CDocumentSectionsInfo.prototype.Search_GetId = function(bNext, CurHdrFtr)
{ {
var HdrFtrs = []; var HdrFtrs = [];
var CurPos = -1; var CurPos = -1;
var bEvenOdd = EvenAndOddHeaders; var bEvenOdd = EvenAndOddHeaders;
var Count = this.Elements.length; var Count = this.Elements.length;
for ( var Index = 0; Index < Count; Index++ ) for (var Index = 0; Index < Count; Index++)
{ {
var SectPr = this.Elements[Index].SectPr; var SectPr = this.Elements[Index].SectPr;
var bFirst = SectPr.Get_TitlePage(); var bFirst = SectPr.Get_TitlePage();
if ( null != SectPr.HeaderFirst && true === bFirst ) if (null != SectPr.HeaderFirst && true === bFirst)
{ {
HdrFtrs.push( SectPr.HeaderFirst ); HdrFtrs.push(SectPr.HeaderFirst);
if ( CurHdrFtr === SectPr.HeaderFirst ) if (CurHdrFtr === SectPr.HeaderFirst)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
if ( null != SectPr.HeaderEven && true === bEvenOdd ) if (null != SectPr.HeaderEven && true === bEvenOdd)
{ {
HdrFtrs.push( SectPr.HeaderEven ); HdrFtrs.push(SectPr.HeaderEven);
if ( CurHdrFtr === SectPr.HeaderEven ) if (CurHdrFtr === SectPr.HeaderEven)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
if ( null != SectPr.HeaderDefault ) if (null != SectPr.HeaderDefault)
{ {
HdrFtrs.push( SectPr.HeaderDefault ); HdrFtrs.push(SectPr.HeaderDefault);
if ( CurHdrFtr === SectPr.HeaderDefault ) if (CurHdrFtr === SectPr.HeaderDefault)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
if ( null != SectPr.FooterFirst && true === bFirst ) if (null != SectPr.FooterFirst && true === bFirst)
{ {
HdrFtrs.push( SectPr.FooterFirst ); HdrFtrs.push(SectPr.FooterFirst);
if ( CurHdrFtr === SectPr.FooterFirst ) if (CurHdrFtr === SectPr.FooterFirst)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
if ( null != SectPr.FooterEven && true === bEvenOdd ) if (null != SectPr.FooterEven && true === bEvenOdd)
{ {
HdrFtrs.push( SectPr.FooterEven ); HdrFtrs.push(SectPr.FooterEven);
if ( CurHdrFtr === SectPr.FooterEven ) if (CurHdrFtr === SectPr.FooterEven)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
if ( null != SectPr.FooterDefault ) if (null != SectPr.FooterDefault)
{ {
HdrFtrs.push( SectPr.FooterDefault ); HdrFtrs.push(SectPr.FooterDefault);
if ( CurHdrFtr === SectPr.FooterDefault ) if (CurHdrFtr === SectPr.FooterDefault)
CurPos = HdrFtrs.length - 1; CurPos = HdrFtrs.length - 1;
} }
} }
var Count = HdrFtrs.length;
if ( -1 != CurPos ) var Count = HdrFtrs.length;
{
var Id = CurHdrFtr.Search_GetId( bNext, true );
if ( null != Id )
return Id;
if ( true === bNext ) var isCurrent = true;
{ if (-1 === CurPos)
for ( var Index = CurPos + 1; Index < Count; Index++ ) {
{ isCurrent = false;
Id = HdrFtrs[Index].Search_GetId( bNext, false ); CurPos = bNext ? 0 : HdrFtrs.length - 1;
if (HdrFtrs[CurPos])
CurHdrFtr = HdrFtrs[CurPos];
}
if ( null != Id ) if (CurPos >= 0 && CurPos <= HdrFtrs.length - 1)
return Id; {
} var Id = CurHdrFtr.Search_GetId(bNext, isCurrent);
} if (null != Id)
else return Id;
{
for ( var Index = CurPos - 1; Index >= 0; Index-- )
{
Id = HdrFtrs[Index].Search_GetId( bNext, false );
if ( null != Id ) if (true === bNext)
return Id; {
} for (var Index = CurPos + 1; Index < Count; Index++)
} {
} Id = HdrFtrs[Index].Search_GetId(bNext, false);
return null; if (null != Id)
return Id;
}
}
else
{
for (var Index = CurPos - 1; Index >= 0; Index--)
{
Id = HdrFtrs[Index].Search_GetId(bNext, false);
if (null != Id)
return Id;
}
}
}
return null;
}; };
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// CTable // CTable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment