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()
{
return this.Footnotes;
};
CDocumentSearch.prototype.GetDirection = function()
{
return this.Direction;
};
CDocumentSearch.prototype.SetDirection = function(bDirection)
{
this.Direction = bDirection;
};
//----------------------------------------------------------------------------------------------------------------------
// CDocument
//----------------------------------------------------------------------------------------------------------------------
......@@ -269,7 +276,6 @@ CDocument.prototype.Search = function(Str, Props, bDraw)
return this.SearchEngine;
};
CDocument.prototype.Search_Select = function(Id)
{
this.Selection_Remove();
......@@ -280,7 +286,6 @@ CDocument.prototype.Search_Select = function(Id)
this.Document_UpdateSelectionState();
this.Document_UpdateRulersState();
};
CDocument.prototype.Search_Replace = function(NewStr, bAll, Id)
{
var bResult = false;
......@@ -350,114 +355,151 @@ CDocument.prototype.Search_Replace = function(NewStr, bAll, Id)
return bResult;
};
CDocument.prototype.Search_GetId = function(bNext)
{
this.SearchEngine.Set_Direction( bNext );
// Получим Id найденного элемента
if ( docpostype_DrawingObjects === this.CurPos.Type )
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
var Id = null;
var Id = ParaDrawing.Search_GetId( bNext, true );
if ( null != Id )
return Id;
this.SearchEngine.SetDirection(bNext);
this.DrawingObjects.resetSelection();
ParaDrawing.GoTo_Text( true === bNext ? false : true, false );
}
if ( docpostype_Content === this.CurPos.Type )
{
var Id = null;
if (docpostype_DrawingObjects === this.CurPos.Type)
{
var ParaDrawing = this.DrawingObjects.getMajorParaDrawing();
var Pos = this.CurPos.ContentPos;
if ( true === this.Selection.Use && selectionflag_Common === this.Selection.Flag )
Pos = ( true === bNext ? Math.max(this.Selection.StartPos, this.Selection.EndPos) : Math.min(this.Selection.StartPos, this.Selection.EndPos) );
Id = ParaDrawing.Search_GetId(bNext, true);
if (null != Id)
return Id;
var StartPos = Pos;
this.DrawingObjects.resetSelection();
ParaDrawing.GoTo_Text(true === bNext ? false : true, false);
}
if ( true === bNext )
{
Id = this.Content[Pos].Search_GetId(true, true);
if (docpostype_Content === this.CurPos.Type)
{
Id = this.private_GetSearchIdInMainDocument(true);
if ( null != Id )
return Id;
if (null === Id)
Id = this.private_GetSearchIdInFootnotes(false);
Pos++;
if (null === Id)
Id = this.private_GetSearchIdInHdrFtr(false);
var Count = this.Content.length;
while ( Pos < Count )
{
Id = this.Content[Pos].Search_GetId(true, false);
if (null === Id)
Id = this.private_GetSearchIdInMainDocument(false);
}
else if (docpostype_HdrFtr === this.CurPos.Type)
{
Id = this.private_GetSearchIdInHdrFtr(true);
if ( null != Id )
return Id;
if (null === Id)
Id = this.private_GetSearchIdInMainDocument(false);
Pos++;
}
if (null === Id)
Id = this.private_GetSearchIdInFootnotes(false);
Pos = 0;
while ( Pos <= StartPos )
{
Id = this.Content[Pos].Search_GetId(true, false);
if (null === Id)
Id = this.private_GetSearchIdInHdrFtr(false);
}
else if (docpostype_Footnotes === this.CurPos.Type)
{
Id = this.private_GetSearchIdInFootnotes(true);
if ( null != Id )
return Id;
if (null === Id)
Id = this.private_GetSearchIdInHdrFtr(false);
Pos++;
}
if (null === Id)
Id = this.private_GetSearchIdInMainDocument(false);
return null;
}
else
{
Id = this.Content[Pos].Search_GetId(false, true);
if (null === Id)
Id = this.private_GetSearchIdInFootnotes(false);
}
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 )
{
Id = this.Content[Pos].Search_GetId(false, false);
if (true !== isCurrent)
Pos = bNext ? 0 : this.Content.length - 1;
if ( null != Id )
return Id;
if (true === bNext)
{
Id = this.Content[Pos].Search_GetId(true, isCurrent);
Pos--;
}
if (null != Id)
return Id;
Pos = this.Content.length - 1;
while ( Pos >= StartPos )
{
Id = this.Content[Pos].Search_GetId(false, false);
Pos++;
if ( null != Id )
return Id;
var Count = this.Content.length;
while (Pos < Count)
{
Id = this.Content[Pos].Search_GetId(true, false);
Pos--;
}
if (null != Id)
return Id;
return null;
}
}
else if ( docpostype_HdrFtr === this.CurPos.Type )
{
return this.SectionsInfo.Search_GetId( bNext, this.HdrFtr.CurHdrFtr );
}
else if (docpostype_Footnotes === this.CurPos.Type)
Pos++;
}
}
else
{
var oCurFootnote = this.Footnotes.CurFootnote;
var Id = oCurFootnote.Search_GetId(bNext, true);
if (null !== Id)
Id = this.Content[Pos].Search_GetId(false, isCurrent);
if (null != Id)
return Id;
var arrFootnotes = this.SearchEngine.GetFootnotes();
var nCurPos = -1;
var nCount = arrFootnotes.length;
Pos--;
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)
{
if (arrFootnotes[nIndex] === oCurFootnote)
......@@ -466,49 +508,40 @@ CDocument.prototype.Search_GetId = function(bNext)
break;
}
}
}
if (-1 == nCurPos)
{
nCurPos = bNext ? 0 : nCount - 1;
oCurFootnote = arrFootnotes[nCurPos];
isCurrent = false;
}
if (-1 === nCurPos)
return null;
var Id = oCurFootnote.Search_GetId(bNext, isCurrent);
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)
return Id;
}
Id = arrFootnotes[nIndex].Search_GetId(bNext, false);
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)
return Id;
}
Id = arrFootnotes[nIndex].Search_GetId(bNext, false);
if (null != Id)
return Id;
}
}
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();
return null;
};
CDocument.prototype.Search_Get_Selection = function()
{
return this.SearchEngine.Selection;
};
//----------------------------------------------------------------------------------------------------------------------
// CDocumentContent
//----------------------------------------------------------------------------------------------------------------------
......@@ -660,97 +693,106 @@ CDocumentSectionsInfo.prototype.Search = function(Str, Props, SearchEngine)
};
CDocumentSectionsInfo.prototype.Search_GetId = function(bNext, CurHdrFtr)
{
var HdrFtrs = [];
var CurPos = -1;
{
var HdrFtrs = [];
var CurPos = -1;
var bEvenOdd = EvenAndOddHeaders;
var Count = this.Elements.length;
for ( var Index = 0; Index < Count; Index++ )
{
var SectPr = this.Elements[Index].SectPr;
var bFirst = SectPr.Get_TitlePage();
var bEvenOdd = EvenAndOddHeaders;
var Count = this.Elements.length;
for (var Index = 0; Index < Count; Index++)
{
var SectPr = this.Elements[Index].SectPr;
var bFirst = SectPr.Get_TitlePage();
if ( null != SectPr.HeaderFirst && true === bFirst )
{
HdrFtrs.push( SectPr.HeaderFirst );
if (null != SectPr.HeaderFirst && true === bFirst)
{
HdrFtrs.push(SectPr.HeaderFirst);
if ( CurHdrFtr === SectPr.HeaderFirst )
CurPos = HdrFtrs.length - 1;
}
if (CurHdrFtr === SectPr.HeaderFirst)
CurPos = HdrFtrs.length - 1;
}
if ( null != SectPr.HeaderEven && true === bEvenOdd )
{
HdrFtrs.push( SectPr.HeaderEven );
if (null != SectPr.HeaderEven && true === bEvenOdd)
{
HdrFtrs.push(SectPr.HeaderEven);
if ( CurHdrFtr === SectPr.HeaderEven )
CurPos = HdrFtrs.length - 1;
}
if (CurHdrFtr === SectPr.HeaderEven)
CurPos = HdrFtrs.length - 1;
}
if ( null != SectPr.HeaderDefault )
{
HdrFtrs.push( SectPr.HeaderDefault );
if (null != SectPr.HeaderDefault)
{
HdrFtrs.push(SectPr.HeaderDefault);
if ( CurHdrFtr === SectPr.HeaderDefault )
CurPos = HdrFtrs.length - 1;
}
if (CurHdrFtr === SectPr.HeaderDefault)
CurPos = HdrFtrs.length - 1;
}
if ( null != SectPr.FooterFirst && true === bFirst )
{
HdrFtrs.push( SectPr.FooterFirst );
if (null != SectPr.FooterFirst && true === bFirst)
{
HdrFtrs.push(SectPr.FooterFirst);
if ( CurHdrFtr === SectPr.FooterFirst )
CurPos = HdrFtrs.length - 1;
}
if (CurHdrFtr === SectPr.FooterFirst)
CurPos = HdrFtrs.length - 1;
}
if ( null != SectPr.FooterEven && true === bEvenOdd )
{
HdrFtrs.push( SectPr.FooterEven );
if (null != SectPr.FooterEven && true === bEvenOdd)
{
HdrFtrs.push(SectPr.FooterEven);
if ( CurHdrFtr === SectPr.FooterEven )
CurPos = HdrFtrs.length - 1;
}
if (CurHdrFtr === SectPr.FooterEven)
CurPos = HdrFtrs.length - 1;
}
if ( null != SectPr.FooterDefault )
{
HdrFtrs.push( SectPr.FooterDefault );
if (null != SectPr.FooterDefault)
{
HdrFtrs.push(SectPr.FooterDefault);
if ( CurHdrFtr === SectPr.FooterDefault )
CurPos = HdrFtrs.length - 1;
}
}
var Count = HdrFtrs.length;
if (CurHdrFtr === SectPr.FooterDefault)
CurPos = HdrFtrs.length - 1;
}
}
if ( -1 != CurPos )
{
var Id = CurHdrFtr.Search_GetId( bNext, true );
if ( null != Id )
return Id;
var Count = HdrFtrs.length;
if ( true === bNext )
{
for ( var Index = CurPos + 1; Index < Count; Index++ )
{
Id = HdrFtrs[Index].Search_GetId( bNext, false );
var isCurrent = true;
if (-1 === CurPos)
{
isCurrent = false;
CurPos = bNext ? 0 : HdrFtrs.length - 1;
if (HdrFtrs[CurPos])
CurHdrFtr = HdrFtrs[CurPos];
}
if ( null != Id )
return Id;
}
}
else
{
for ( var Index = CurPos - 1; Index >= 0; Index-- )
{
Id = HdrFtrs[Index].Search_GetId( bNext, false );
if (CurPos >= 0 && CurPos <= HdrFtrs.length - 1)
{
var Id = CurHdrFtr.Search_GetId(bNext, isCurrent);
if (null != Id)
return Id;
if ( null != Id )
return Id;
}
}
}
if (true === bNext)
{
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
......
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