Commit 411dd481 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Реализовано передвижение курсора по клавишам up/down/home/end в новом варианте параграфа.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53657 954022d7-b5bf-4e40-9824-e11837661b57
parent 177c7edf
......@@ -12363,673 +12363,4 @@ CDocument.prototype =
editor.sync_UpdateCommentPosition( Comment.Get_Id(), Coords.X, Coords.Y );
}
}
};
Paragraph.prototype.Test_Recalculate_Lines = function(PRSW)
{
var CurLine = 0;
PRSW.Line = 0;
PRSW.Reset_Ranges();
var RecalcResult = recalcresult_NextElement;
while ( true )
{
PRSW.Line = CurLine;
PRSW.RecalcResult = recalcresult_NextLine;
this.Test_Recalculate_Line(PRSW);
RecalcResult = PRSW.RecalcResult;
if ( recalcresult_NextLine === RecalcResult )
{
CurLine++;
PRSW.Reset_Ranges();
continue;
}
else if ( recalcresult_CurLine === RecalcResult )
{
continue;
}
else if ( recalcresult_NextElement === RecalcResult || recalcresult_NextPage === RecalcResult )
{
break;
}
else //if ( recalcresult_CurPage === RecalcResult || recalcresult_PrevPage === RecalcResult )
{
// В эту ветку мы попадаем, если в нашем параграфе встретилось, что-то из-за чего надо пересчитывать
// эту страницу или предыдущую страницу. Поэтому далее можно ничего не делать, а сообщать верхнему
// классу об этом.
return RecalcResult;
}
}
}
Paragraph.prototype.Test_Recalculate_Line = function(PRSW)
{
var CurLine = PRSW.Line;
var CurPage = PRSW.Page;
var CurRange = 0;
this.Lines.length = CurLine + 1;
this.Lines[CurLine] = new CParaLine();
// Параметры Ranges и RangesCount не обнуляются здесь, они задаются выше
var Ranges = PRSW.Ranges;
var RangesCount = PRSW.RangesCount;
// Обнуляем параметры PRS для строки
PRSW.Reset_Line();
// Заполняем строку отрезками обтекания. Выставляем начальные сдвиги для отрезков. Начало промежутка = конец вырезаемого промежутка
this.Lines[CurLine].Reset();
this.Lines[CurLine].Add_Range( 0, 100 );
for ( var Index = 1; Index < Ranges.length + 1; Index++ )
{
this.Lines[CurLine].Add_Range( 0, 100 );
}
while ( CurRange <= RangesCount )
{
PRSW.Range = CurRange;
this.Test_Recalculate_Range( PRSW );
CurRange++;
}
if ( PRSW.RecalcResult !== recalcresult_NextElement )
PRSW.RecalcResult = recalcresult_NextLine;
if ( true === PRSW.End )
PRSW.RecalcResult = recalcresult_NextElement;
}
Paragraph.prototype.Test_Recalculate_Range = function(PRSW)
{
var PRS = g_oPRSW;
var CurLine = PRS.Line;
var CurRange = PRS.Range;
var CurPage = PRS.Page;
var RangesCount = PRS.RangesCount;
// Найдем начальную позицию данного отрезка
var StartPos = 0;
if ( 0 === CurLine && 0 === CurRange )
StartPos = 0;
else if ( CurRange > 0 )
StartPos = this.Lines[CurLine].Ranges[CurRanges - 1].EndPos;
else
StartPos = this.Lines[CurLine - 1].Ranges[ this.Lines[CurLine - 1].Ranges.length - 1 ].EndPos;
var Line = this.Lines[CurLine];
var Range = Line.Ranges[CurRange];
this.Lines[CurLine].Set_RangeStartPos( CurRange, StartPos );
var X = 0;
var XEnd = 300;
// Обновляем состояние пересчета
PRS.Reset_Range(X, XEnd);
var ContentLen = this.Content.length;
var Pos = StartPos;
for ( ;Pos < ContentLen; Pos++ )
{
var Item = this.Content[Pos];
// if ( ( 0 === Pos && 0 === CurLine ) || Pos !== StartPos )
// {
// Item.StartLine = CurLine;
// Item.NeedAddNumbering = false;
// }
//PRSW.Update_CurPos( Pos, 0 );
Item.StartLine = CurLine;
Item.Test_Recalculate_Range( PRSW );
if ( true === PRS.NewRange )
break;
}
this.Lines[CurLine].Set_RangeEndPos( CurRange, Pos );
}
ParaRun.prototype.Test_Recalculate_Range = function(PRSW)
{
var CurLine = PRSW.Line - this.StartLine;
var Lines = this.Lines;
if ( 0 !== CurLine )
{
this.Lines[CurLine] = new CParaRunLine();
this.LinesLength = CurLine + 1;
}
else
{
this.LinesLength = 1;
}
var Para = PRSW.Paragraph;
var RangeStartPos = 0;
var RangeEndPos = -1;
// Вычислим RangeStartPos
var CurRange = PRSW.Range;
if ( 0 === CurLine )
{
if ( 0 !== CurRange )
{
RangeStartPos = this.Lines[0].Ranges[CurRange - 1].EndPos;
}
else
{
RangeStartPos = 0;
}
}
else if ( 0 === CurRange )
{
var _Line = this.Lines[CurLine - 1];
RangeStartPos = _Line.Ranges[_Line.Ranges.length - 1].EndPos;
}
else
{
var _Line = this.Lines[CurLine];
RangeStartPos = Line.Ranges[CurRange - 1].EndPos;
}
var X = PRSW.X;
var Y = PRSW.Y;
var XEnd = PRSW.XEnd;
var MoveToLBP = PRSW.MoveToLBP;
var NewRange = PRSW.NewRange;
var ForceNewPage = PRSW.ForceNewPage;
var NewPage = PRSW.NewPage;
var BreakPageLine = PRSW.BreakPageLine;
var End = PRSW.End;
var Word = PRSW.Word;
var StartWord = PRSW.StartWord;
var FirstItemOnLine = PRSW.FirstItemOnLine;
var EmptyLine = PRSW.EmptyLine;
var RangesCount = PRSW.RangesCount;
var SpaceLen = PRSW.SpaceLen;
var WordLen = PRSW.WordLen;
var SpacesCount = PRSW.SpacesCount;
var X = PRSW.X;
var XEnd = PRSW.XEnd;
var ParaLine = PRSW.Line;
var ParaRange = PRSW.Range;
var Pos = RangeStartPos;
var UpdateLineMetricsText = false;
var Content = this.Content;
var RunLen = Content.length;
var Pos = RangeStartPos;
for ( ; Pos < RunLen; Pos++ )
{
if ( false === StartWord && true === FirstItemOnLine && Math.abs( XEnd - X ) < 0.001 && RangesCount > 0 )
{
NewRange = true;
RangeEndPos = Pos;
break;
}
var Item = Content[Pos];
var ItemType = Item.Type;
if ( true === this.Internal_Recalculate_Numbering( Item, PRSW, null ) )
PRSW.Set_NumberingPos( Pos, Item );
switch (ItemType)
{
case para_Text:
{
// Отмечаем, что началось слово
StartWord = true;
UpdateLineMetricsText = true;
// При проверке, убирается ли слово, мы должны учитывать ширину предшествующих пробелов.
var LetterLen = Item.Width;
if ( true !== Word )
{
// Слово только началось. Делаем следующее:
// 1) Если до него на строке ничего не было и данная строка не
// имеет разрывов, тогда не надо проверять убирается ли слово в строке.
// 2) В противном случае, проверяем убирается ли слово в промежутке.
// Если слово только началось, и до него на строке ничего не было, и в строке нет разрывов, тогда не надо проверять убирается ли оно на строке.
if ( true !== FirstItemOnLine )//|| false === Para.Internal_Check_Ranges(ParaLine, ParaRange) )
{
if ( X + SpaceLen + LetterLen > XEnd )
{
NewRange = true;
RangeEndPos = Pos;
}
}
if ( true !== NewRange )
{
// Отмечаем начало нового слова
PRSW.Set_LineBreakPos( Pos );
WordLen = Item.Width;
Word = true;
}
}
else
{
if ( X + SpaceLen + WordLen + LetterLen > XEnd )
{
if ( true === FirstItemOnLine )
{
// Слово оказалось единственным элементом в промежутке, и, все равно,
// не умещается целиком. Делаем следующее:
//
// 1) Если у нас строка без вырезов, тогда ставим перенос строки на
// текущей позиции.
// 2) Если у нас строка с вырезом, и данный вырез не последний, тогда
// ставим перенос внутри строки в начале слова.
// 3) Если у нас строка с вырезом и вырез последний, тогда ставим перенос
// строки в начале слова.
if ( false )//false === Para.Internal_Check_Ranges(ParaLine, ParaRange) )
{
// Слово не убирается в отрезке. Переносим слово в следующий отрезок
MoveToLBP = true;
NewRange = true;
}
else
{
EmptyLine = false;
X += WordLen;
// Слово не убирается в отрезке, но, поскольку, слово 1 на строке и отрезок тоже 1,
// делим слово в данном месте
NewRange = true;
RangeEndPos = Pos;
}
}
else
{
// Слово не убирается в отрезке. Переносим слово в следующий отрезок
MoveToLBP = true;
NewRange = true;
}
}
if ( true !== NewRange )
{
// Мы убираемся в пределах данной строки. Прибавляем ширину буквы к ширине слова
WordLen += LetterLen;
// Если текущий символ с переносом, например, дефис, тогда на нем заканчивается слово
if ( true === Item.SpaceAfter )
{
// Добавляем длину пробелов до слова и ширину самого слова.
X += SpaceLen + WordLen;
Word = false;
FirstItemOnLine = false;
EmptyLine = false;
SpaceLen = 0;
WordLen = 0;
SpacesCount = 0;
}
}
}
break;
}
case para_End:
{
PRSW.End = true;
PRSW.NewRange = true;
break;
}
}
if ( true === PRSW.NewRange )
break;
}
//if ( true === UpdateLineMetricsText )
// this.Internal_Recalculate_LineMetrics( PRSW, linerule_Auto );
if ( Pos >= RunLen )
{
RangeEndPos = Pos;
if ( Lines.length > this.LinesLength )
Lines.length = this.LinesLength;
}
PRSW.MoveToLBP = MoveToLBP;
PRSW.ForceNewPage = ForceNewPage;
PRSW.NewPage = NewPage;
PRSW.BreakPageLine = BreakPageLine;
PRSW.Word = Word;
PRSW.StartWord = StartWord;
PRSW.FirstItemOnLine = FirstItemOnLine;
PRSW.EmptyLine = EmptyLine;
PRSW.SpaceLen = SpaceLen;
PRSW.WordLen = WordLen;
PRSW.SpacesCount = SpacesCount;
PRSW.X = X;
PRSW.XEnd = XEnd;
this.Range.StartPos = RangeStartPos;
this.Range.EndPos = RangeEndPos;
// var Range = this.Lines[CurLine].Ranges[PRSW.Range];
// Range.StartPos = RangeStartPos;
// Range.EndPos = RangeEndPos;
//this.Lines[CurLine].Add_Range( PRSW.Range, RangeStartPos, RangeEndPos );
}
CDocument.prototype.Test_Recalculate_Paragraph = function()
{
var Count = Paras.length;
for ( var Pos = 0; Pos < Count; Pos++ )
{
var Para = Paras[Pos];
var PRSW = g_oPRSW;
Para.Test_Recalculate_Lines( PRSW );
}
}
var Items = null;
var Paras = null;
CDocument.prototype.LoadTestDocument3 = function()
{
var Count = 232000;
History.TurnOff();
g_oTableId.m_bTurnOff = true;
if ( null === Items )
{
Items = new Array();
for ( var Pos = 0; Pos < Count; Pos++ )
{
Items[Pos] = new ParaText();
Items[Pos].Width = 3.4;
Items[Pos].Height = 1.1;
}
var Period = 1;
var Runs = new Array();
var CurRun = new ParaRun(null, null);
for ( var Pos = 0; Pos < Count; Pos++ )
{
if ( 0 === Pos % Period )
{
if ( 0 != CurRun.Content.length )
Runs.push( CurRun );
var CurRun = new ParaRun(null, null);
}
CurRun.Content.push( Items[Pos] );
}
if ( 0 != CurRun.Content.length )
Runs.push( CurRun );
var Count2 = Runs.length;
var Period2 = 1000;
Paras = [];
var CurPara = new Paragraph();
CurPara.Content = [];
for ( var Pos = 0; Pos < Count2; Pos++ )
{
if ( 0 === Pos % Period2 )
{
if ( 0 != CurPara.Content.length )
{
CurPara.Content[CurPara.Content.length - 1].Content.push( new ParaEnd() );
Paras.push( CurPara );
}
var CurPara = new Paragraph();
CurPara.Content = [];
}
CurPara.Content.push( Runs[Pos] );
}
if ( 0 != CurPara.Content.length )
{
CurPara.Content[CurPara.Content.length - 1].Content.push( new ParaEnd() );
Paras.push( CurPara );
}
}
Debug_ParaRunMode = true;
var __starttime = new Date().getTime();
var PRSW = g_oPRSW;
var ContentLen = this.Content
this.Test_Recalculate_Paragraph();
console.log("Test: " + ((new Date().getTime() - __starttime) / 1000) );
console.log("X: " + PRSW.X + " Y: " + PRSW.Y );
g_oTableId.m_bTurnOff = false;
History.TurnOn();
return;
}
CDocument.prototype.LoadTestDocument6 = function()
{
g_oIdCounter.Set_Load(true);
editor.ShowParaMarks = true;
Debug_ParaRunMode = false;
// Добавляем тестовый текст к документу
this.DrawingDocument.m_bIsNoSendChangeDocument = false;
this.DrawingDocument.m_bIsOpeningDocument = true;
this.DrawingDocument.TargetStart();
var Strings = ["History", "A box of punched cards with several program decks.", "Before text editors existed, computer text was punched into punched cards with keypunch machines. The text was carried as a physical box of these thin cardboard cards, and read into a card-reader. Magnetic tape or disk \"card-image\" files created from such card decks often had no line-separation characters at all, commonly assuming fixed-length 80-character records. An alternative to cards was punched paper tape, generated by teletype (TTY) machines; these did need special characters to indicate ends of records.", "The first text editors were line editors oriented to teletype- or typewriter- style terminals, which did not provide a window or screen-oriented display. They usually had very short commands (to minimize typing) that reproduced the current line. Among them were a command to print a selected section(s) of the file on the typewriter (or printer) in case of necessity. An \"edit cursor\", an imaginary insertion point, could be moved by special commands that operated with line numbers of specific text strings (context). Later, the context strings were extended to regular expressions. To see the changes, the file needed to be printed on the printer. These \"line-based text editors\" were considered revolutionary improvements over keypunch machines. In case typewriter-based terminals were not available, they were adapted to keypunch equipment. In this case the user needed to punch the commands into the separate deck of cards and feed them into the computer in order to edit the file.", "When computer terminals with video screens became available, screen-based text editors (sometimes termed just \"screen editors\") became common. One of the earliest \"full screen\" editors was O26 - which was written for the operator console of the CDC 6000 series machines in 1967. Another early full screen editor is vi. Written in the 1970s, vi is still a standard editor[1] for Unix and Linux operating systems. Vi and Emacs are popular editors on these systems. The productivity of editing using full-screen editors (compared to the line-based editors) motivated many of the early purchases of video terminals."];
var oldPara = this.Content[this.Content.length - 1];
var Para = new Paragraph( this.DrawingDocument, this, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
Para.Content = [];
oldPara.Set_DocumentNext(Para);
Para.Set_DocumentPrev(oldPara);
var bWord = false;
var Run = undefined;
this.Content = [];
this.Content.push( Para );
for ( var j = 0; j < 100; j++ )
{
var Pos = 0;
for ( var i = 0; i < Strings.length; i++ )
{
switch ( i )
{
case 0 :
{
Para.Style_Add( this.Styles.Get_Default_Heading(0) );
break;
}
default:
{
Para.Pr.Jc = align_Justify;
break;
}
}
for ( var Index = 0; Index < Strings[i].length; Index++ )
{
if ( " " != Strings[i].charAt( Index ) )
{
Para.Content.push( new ParaTextPr( ) );
Para.Content.push( new ParaText( Strings[i].charAt( Index ) ) );
}
else
{
Para.Content.push( new ParaTextPr( ) );
Para.Content.push( new ParaSpace() );
}
}
Para.Content.push( new ParaTextPr( ) );
Para.Content.push( new ParaEnd() );
Para.Content.push( new ParaEmpty() );
bWord = false;
oldPara = Para;
Para = new Paragraph( this.DrawingDocument, this, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
Para.Content = [];
oldPara.Set_DocumentNext(Para);
Para.Set_DocumentPrev(oldPara);
this.Content.push( Para );
Pos = 0;
}
}
Para.Content.push( new ParaEnd() );
Para.Content.push( new ParaEmpty() );
this.HdrFtr.Content[0].Header.First = null;
this.HdrFtr.Content[0].Header.Even = null;
this.HdrFtr.Content[0].Header.Odd = null;
this.HdrFtr.Content[0].Footer.First = null;
this.HdrFtr.Content[0].Footer.Even = null;
this.HdrFtr.Content[0].Footer.Odd = null;
this.Recalculate(false, false, { Inline : { Pos : 0, PageNum : 0 }, Flow : [], HdrFtr : [] } );
var Rand = Math.floor( Math.random() * 100 );
g_oIdCounter.Set_UserId("" + Rand);
g_oIdCounter.Set_Load(false);
}
CDocument.prototype.LoadTestDocument7 = function()
{
g_oIdCounter.Set_Load(true);
editor.ShowParaMarks = true;
Debug_ParaRunMode = false;
// Добавляем тестовый текст к документу
this.DrawingDocument.m_bIsNoSendChangeDocument = false;
this.DrawingDocument.m_bIsOpeningDocument = true;
this.DrawingDocument.TargetStart();
var Strings = ["History", "A box of punched cards with several program decks.", "Before text editors existed, computer text was punched into punched cards with keypunch machines. The text was carried as a physical box of these thin cardboard cards, and read into a card-reader. Magnetic tape or disk \"card-image\" files created from such card decks often had no line-separation characters at all, commonly assuming fixed-length 80-character records. An alternative to cards was punched paper tape, generated by teletype (TTY) machines; these did need special characters to indicate ends of records.", "The first text editors were line editors oriented to teletype- or typewriter- style terminals, which did not provide a window or screen-oriented display. They usually had very short commands (to minimize typing) that reproduced the current line. Among them were a command to print a selected section(s) of the file on the typewriter (or printer) in case of necessity. An \"edit cursor\", an imaginary insertion point, could be moved by special commands that operated with line numbers of specific text strings (context). Later, the context strings were extended to regular expressions. To see the changes, the file needed to be printed on the printer. These \"line-based text editors\" were considered revolutionary improvements over keypunch machines. In case typewriter-based terminals were not available, they were adapted to keypunch equipment. In this case the user needed to punch the commands into the separate deck of cards and feed them into the computer in order to edit the file.", "When computer terminals with video screens became available, screen-based text editors (sometimes termed just \"screen editors\") became common. One of the earliest \"full screen\" editors was O26 - which was written for the operator console of the CDC 6000 series machines in 1967. Another early full screen editor is vi. Written in the 1970s, vi is still a standard editor[1] for Unix and Linux operating systems. Vi and Emacs are popular editors on these systems. The productivity of editing using full-screen editors (compared to the line-based editors) motivated many of the early purchases of video terminals."];
var oldPara = this.Content[this.Content.length - 1];
var Para = new Paragraph( this.DrawingDocument, this, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
Para.Content = [];
oldPara.Set_DocumentNext(Para);
Para.Set_DocumentPrev(oldPara);
var bWord = false;
var Run = undefined;
this.Content = [];
this.Content.push( Para );
for ( var j = 0; j < 100; j++ )
{
var Pos = 0;
for ( var i = 0; i < Strings.length; i++ )
{
switch ( i )
{
case 0 :
{
Para.Style_Add( this.Styles.Get_Default_Heading(0) );
break;
}
default:
{
Para.Pr.Jc = align_Justify;
break;
}
}
for ( var Index = 0; Index < Strings[i].length; Index++ )
{
if ( " " != Strings[i].charAt( Index ) )
{
if ( false === bWord )
{
Para.Content.push( new ParaTextPr( ) );
bWord = true;
}
Para.Content.push( new ParaText( Strings[i].charAt( Index ) ) );
}
else
{
bWord = false;
Para.Content.push( new ParaTextPr( ) );
Para.Content.push( new ParaSpace() );
}
}
Para.Content.push( new ParaTextPr( ) );
Para.Content.push( new ParaEnd() );
Para.Content.push( new ParaEmpty() );
bWord = false;
oldPara = Para;
Para = new Paragraph( this.DrawingDocument, this, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
Para.Content = [];
oldPara.Set_DocumentNext(Para);
Para.Set_DocumentPrev(oldPara);
this.Content.push( Para );
Pos = 0;
}
}
Para.Content.push( new ParaEnd() );
Para.Content.push( new ParaEmpty() );
this.HdrFtr.Content[0].Header.First = null;
this.HdrFtr.Content[0].Header.Even = null;
this.HdrFtr.Content[0].Header.Odd = null;
this.HdrFtr.Content[0].Footer.First = null;
this.HdrFtr.Content[0].Footer.Even = null;
this.HdrFtr.Content[0].Footer.Odd = null;
this.Recalculate(false, false, { Inline : { Pos : 0, PageNum : 0 }, Flow : [], HdrFtr : [] } );
var Rand = Math.floor( Math.random() * 100 );
g_oIdCounter.Set_UserId("" + Rand);
g_oIdCounter.Set_Load(false);
}
\ No newline at end of file
};
\ No newline at end of file
......@@ -75,6 +75,7 @@ function Paragraph(DrawingDocument, Parent, PageNum, X, Y, XLimit, YLimit)
ContentPos : 0, // Ближайшая позиция в контенте (между элементами)
ContentPos2 : -1, // Реальный элемент
Line : -1,
Range : -1,
RealX : 0, // позиция курсора, без учета расположения букв
RealY : 0, // это актуально для клавиш вверх и вниз
PagesPos : 0 // позиция в массиве this.Pages
......@@ -725,6 +726,13 @@ Paragraph.prototype =
{
// Сначала определим строку и отрезок
var ParaPos = this.Content[this.CurPos.ContentPos].Get_CurrentParaPos();
if ( -1 !== this.CurPos.Line )
{
ParaPos.Line = this.CurPos.Line;
ParaPos.Range = this.CurPos.Range;
}
var CurLine = ParaPos.Line;
// Определим страницу
......@@ -739,10 +747,25 @@ Paragraph.prototype =
}
}
if ( -1 !== this.CurPos.Line )
return ParaPos;
},
Get_ParaPosByContentPos : function(ContentPos)
{
// Сначала определим строку и отрезок
var ParaPos = this.Content[ContentPos.Get(0)].Get_ParaPosByContentPos(ContentPos, 1);
var CurLine = ParaPos.Line;
// Определим страницу
var PagesCount = this.Pages.length;
for ( var CurPage = PagesCount - 1; CurPage >= 0; CurPage-- )
{
// TODO: разобраться с Range
ParaPos.Line = this.CurPos.Line;
var Page = this.Pages[CurPage];
if ( CurLine >= Page.StartLine && CurLine <= Page.EndLine )
{
ParaPos.Page = CurPage;
return ParaPos;
}
}
return ParaPos;
......@@ -4555,6 +4578,13 @@ Paragraph.prototype =
var CurRange = LinePos.Range;
var CurPage = LinePos.Page;
// Если в текущей позиции явно указана строка
if ( -1 != this.CurPos.Line )
{
CurLine = this.CurPos.Line;
CurRange = this.CurPos.Range;
}
var X = this.Lines[CurLine].Ranges[CurRange].XVisible;
var Y = this.Pages[CurPage].Y + this.Lines[CurLine].Y;
......@@ -5022,6 +5052,9 @@ Paragraph.prototype =
if ( recalcresult_NextElement !== RecalcResultAlign )
return false;
// Во время пересчета сбрасываем привязку курсора к строке.
this.CurPos.Line = -1;
return true;
},
......@@ -5135,6 +5168,9 @@ Paragraph.prototype =
}
else
{
// Во время пересчета сбрасываем привязку курсора к строке.
this.CurPos.Line = -1;
var CurPage = _PageIndex - this.PageNum;
var RecalcResult = this.Recalculate_Page__( CurPage );
......@@ -8200,10 +8236,28 @@ Paragraph.prototype =
// Корректируем позицию курсора:
// Если курсор находится в начале какого-либо рана, тогда мы его двигаем в конец предыдущего рана
Correct_ContentPos : function()
Correct_ContentPos : function(CorrectEndLinePos)
{
var Count = this.Content.length;
var CurPos = this.CurPos.ContentPos;
while ( CurPos > 0 && true === this.Content[CurPos].Cursor_Is_Start() )
// Если курсор попадает на конец строки, тогда мы его переносим в начало следующей
if ( true === CorrectEndLinePos && true === this.Content[CurPos].Cursor_Is_End() )
{
var _CurPos = CurPos + 1;
// Пропускаем пустые раны
while ( true === this.Content[_CurPos].Is_Empty(true) && _CurPos < Count )
_CurPos++;
if ( _CurPos < Count && true === this.Content[_CurPos].Is_StartFromNewLine() )
{
CurPos = _CurPos;
this.Content[CurPos].Cursor_MoveToStartPos();
}
}
while ( CurPos > 0 && true === this.Content[CurPos].Cursor_Is_NeededCorrectPos() )
{
CurPos--;
this.Content[CurPos].Cursor_MoveToEndPos();
......@@ -8225,7 +8279,7 @@ Paragraph.prototype =
return ContentPos;
},
Set_ParaContentPos : function(ContentPos, bSelection, bStart)
Set_ParaContentPos : function(ContentPos, bSelection, bStart, Line, CorrectEndLinePos)
{
var Pos = ContentPos.Get(0);
if ( true === bSelection )
......@@ -8245,10 +8299,105 @@ Paragraph.prototype =
{
this.CurPos.ContentPos = Pos;
this.Content[Pos].Set_ParaContentPos( ContentPos, 1, bSelection, bStart );
this.Correct_ContentPos();
this.Correct_ContentPos(CorrectEndLinePos);
this.CurPos.Line = Line;
this.CurPos.Range = 0;
}
},
Get_ParaContentPosByXY : function(X, Y, PageNum, bYLine)
{
var SearchPos = new CParagraphSearchPosXY();
if ( this.Lines.length <= 0 )
return SearchPos;
// Определим страницу
var PNum = ( PageNum === -1 || undefined === PageNum ? 0 : PageNum - this.PageNum );
// Сначала определим на какую строку мы попали
if ( PNum >= this.Pages.length )
{
PNum = this.Pages.length - 1;
bYLine = true;
Y = this.Lines.length - 1;
}
else if ( PNum < 0 )
{
PNum = 0;
bYLine = true;
Y = 0;
}
var CurLine = 0;
if ( true === bYLine )
CurLine = Y;
else
{
CurLine = this.Pages[PNum].FirstLine;
var bFindY = false;
var CurLineY = this.Pages[PNum].Y + this.Lines[CurLine].Y + this.Lines[CurLine].Metrics.Descent + this.Lines[CurLine].Metrics.LineGap;
var LastLine = ( PNum >= this.Pages.length - 1 ? this.Lines.length - 1 : this.Pages[PNum + 1].FirstLine - 1 );
while ( !bFindY )
{
if ( Y < CurLineY )
break;
if ( CurLine >= LastLine )
break;
CurLine++;
CurLineY = this.Lines[CurLine].Y + this.Pages[PNum].Y + this.Lines[CurLine].Metrics.Descent + this.Lines[CurLine].Metrics.LineGap;
}
}
// Определим отрезок, в который мы попадаем
var CurRange = 0;
var RangesCount = this.Lines[CurLine].Ranges.length;
for ( ; CurRange < RangesCount; CurRange++ )
{
var _Range = this.Lines[CurLine].Ranges[CurRange];
if ( X < _Range.XEnd )
break;
}
if ( CurRange >= RangesCount )
CurRange = Math.max(RangesCount - 1, 0);
// Определим уже непосредственно позицию, куда мы попадаем
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
SearchPos.CurX = Range.XVisible;
SearchPos.X = X;
for ( var CurPos = StartPos; CurPos <= EndPos; CurPos++ )
{
var Item = this.Content[CurPos];
if ( true === Item.Get_ParaContentPosByXY( SearchPos, 1, CurLine, CurRange ) )
SearchPos.Pos.Update( CurPos, 0 );
}
// По Х попали в какой-то элемент, проверяем по Y
if ( true === SearchPos.InText && Y >= this.Pages[PNum].Y + this.Lines[CurLine].Y - this.Lines[CurLine].Metrics.Ascent - 0.01 && Y <= this.Pages[PNum].Y + this.Lines[CurLine].Y + this.Lines[CurLine].Metrics.Descent + this.Lines[CurLine].Metrics.LineGap + 0.01 )
SearchPos.InText = true;
else
SearchPos.InText = false;
if ( SearchPos.NumberingDiffX <= SearchPos.DiffX )
SearchPos.Numbering = true;
else
SearchPos.Numbering = false;
SearchPos.Line = CurLine;
return SearchPos;
},
Cursor_GetPos : function()
{
return { X : this.CurPos.RealX, Y : this.CurPos.RealY };
......@@ -8281,6 +8430,7 @@ Paragraph.prototype =
}
else
{
var Result = true;
if ( true === this.Selection.Use )
{
......@@ -8303,15 +8453,22 @@ Paragraph.prototype =
if ( true === SearchPos.Found )
{
this.Set_ParaContentPos( SearchPos.Pos, false, false );
return true;
this.Set_ParaContentPos( SearchPos.Pos, false, false, -1, true );
Result = true;
}
else
{
return false;
Result = false;
}
}
}
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
return Result;
}
},
......@@ -8342,6 +8499,8 @@ Paragraph.prototype =
}
else
{
var Result = true;
if ( true === this.Selection.Use )
{
......@@ -8364,15 +8523,78 @@ Paragraph.prototype =
if ( true === SearchPos.Found )
{
this.Set_ParaContentPos( SearchPos.Pos, false, false );
return true;
this.Set_ParaContentPos( SearchPos.Pos, false, false, -1, true );
Result = true;
}
else
{
return false;
Result = false;
}
}
}
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
return Result;
}
},
Cursor_MoveAt : function(X,Y, bLine, bDontChangeRealPos, PageNum)
{
if ( true !== Debug_ParaRunMode )
{
var TempPos = this.Internal_GetContentPosByXY( X, Y, bLine, PageNum );
var Pos = TempPos.Pos;
var Line = TempPos.Line;
if ( undefined !== this.Content[TempPos.Pos2] && para_Math === this.Content[TempPos.Pos2].Type )
{
this.Content[TempPos.Pos2].Cursor_MoveAt( X, Y );
this.CurPos.ContentPos2 = TempPos.Pos2;
}
else
this.CurPos.ContentPos2 = -1;
if ( -1 != Pos )
{
this.Set_ContentPos( Pos, true, Line );
}
this.Internal_Recalculate_CurPos(Pos, false, false, false );
if ( bDontChangeRealPos != true )
{
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
if ( true != bLine )
{
this.CurPos.RealX = X;
this.CurPos.RealY = Y;
}
}
else
{
var SearchPosXY = this.Get_ParaContentPosByXY( X, Y, PageNum, bLine );
this.Set_ParaContentPos( SearchPosXY.Pos, false, false, SearchPosXY.Line, false );
this.Internal_Recalculate_CurPos(-1, false, false, false );
if ( bDontChangeRealPos != true )
{
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
if ( true != bLine )
{
this.CurPos.RealX = X;
this.CurPos.RealY = Y;
}
}
},
......@@ -8503,28 +8725,149 @@ Paragraph.prototype =
}
},
Cursor_MoveUp : function(Count, AddToSelect)
Get_EndRangePos : function(SearchPos, ContentPos)
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
var LinePos = this.Get_ParaPosByContentPos(ContentPos);
if ( this.CurPos.ContentPos < 0 )
return false;
var CurLine = LinePos.Line;
var CurRange = LinePos.Range;
if ( !Count || 0 == Count )
return;
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
var absCount = ( Count < 0 ? -Count : Count );
SearchPos.Line = CurLine;
// Пока сделаем для Count = 1
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
// Ищем в данном отрезке
for ( var CurPos = StartPos; CurPos <= EndPos; CurPos++ )
{
var Item = this.Content[CurPos];
var Result = true;
if ( true === this.Selection.Use )
if ( true === Item.Get_EndRangePos( CurLine, CurRange, SearchPos, 1 ) )
SearchPos.Pos.Update( CurPos, 0 );
}
},
Get_StartRangePos : function(SearchPos, ContentPos)
{
var LinePos = this.Get_ParaPosByContentPos(ContentPos);
var CurLine = LinePos.Line;
var CurRange = LinePos.Range;
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
SearchPos.Line = CurLine;
// Ищем в данном отрезке
for ( var CurPos = EndPos; CurPos >= StartPos; CurPos-- )
{
if ( true === AddToSelect )
var Item = this.Content[CurPos];
if ( true === Item.Get_StartRangePos( CurLine, CurRange, SearchPos, 1 ) )
SearchPos.Pos.Update( CurPos, 0 );
}
},
Cursor_MoveUp : function(Count, AddToSelect)
{
if ( true !== Debug_ParaRunMode )
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( this.CurPos.ContentPos < 0 )
return false;
if ( !Count || 0 == Count )
return;
var absCount = ( Count < 0 ? -Count : Count );
// Пока сделаем для Count = 1
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var Result = true;
if ( true === this.Selection.Use )
{
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
if ( true === AddToSelect )
{
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.RecalculateCurPos();
this.CurPos.RealY = this.CurPos.Y;
if ( 0 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
this.Selection.EndPos = this.Internal_GetStartPos();
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
this.Selection.EndPos = this.CurPos.ContentPos;
}
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return Result;
}
}
else
{
var StartPos = this.Selection.StartPos;
var EndPos = this.Selection.EndPos;
if ( StartPos > EndPos )
{
var Temp = EndPos;
EndPos = StartPos;
StartPos = Temp;
}
this.Set_ContentPos( StartPos, true, -1 );
this.CurPos.ContentPos2 = -1;
this.Selection_Remove();
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
if ( 0 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
}
else if ( true === AddToSelect )
{
this.Selection.Use = true;
this.Selection.StartPos = this.CurPos.ContentPos;
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
......@@ -8558,134 +8901,168 @@ Paragraph.prototype =
}
else
{
var StartPos = this.Selection.StartPos;
var EndPos = this.Selection.EndPos;
if ( StartPos > EndPos )
var CurPos2 = this.CurPos.ContentPos2;
var MathElement = this.Content[CurPos2];
if ( undefined !== MathElement && para_Math === MathElement.Type )
{
var Temp = EndPos;
EndPos = StartPos;
StartPos = Temp;
}
this.Set_ContentPos( StartPos, true, -1 );
this.CurPos.ContentPos2 = -1;
this.Selection_Remove();
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
if ( true === MathElement.Cursor_MoveUp(false) )
{
if ( true === MathElement.Selection_IsUse() && false === MathElement.Selection_IsEmpty() )
this.Internal_SelectMath( CurPos2 );
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
return true;
}
else
{
this.CurPos.ContentPos2 = -1;
}
}
if ( 0 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
return Result;
}
else if ( true === AddToSelect )
else
{
this.Selection.Use = true;
this.Selection.StartPos = this.CurPos.ContentPos;
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.RecalculateCurPos();
this.CurPos.RealY = this.CurPos.Y;
if ( 0 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
this.Selection.EndPos = this.Internal_GetStartPos();
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
this.Selection.EndPos = this.CurPos.ContentPos;
}
var LinePos = this.Get_CurrentParaPos();
var CurLine = LinePos.Line;
if ( this.Selection.StartPos == this.Selection.EndPos )
var Result = true;
if ( true === this.Selection.Use )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return Result;
}
}
else
{
var CurPos2 = this.CurPos.ContentPos2;
var MathElement = this.Content[CurPos2];
if ( undefined !== MathElement && para_Math === MathElement.Type )
else
{
if ( true === MathElement.Cursor_MoveUp(false) )
if ( true === AddToSelect )
{
if ( true === MathElement.Selection_IsUse() && false === MathElement.Selection_IsEmpty() )
this.Internal_SelectMath( CurPos2 );
return true;
}
else
{
this.CurPos.ContentPos2 = -1;
if ( 0 == CurLine )
{
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
}
}
}
if ( 0 == CurLine )
{
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine - 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
}
return Result;
}
return Result;
},
Cursor_MoveDown : function(Count, AddToSelect)
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( true !== Debug_ParaRunMode )
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( this.CurPos.ContentPos < 0 )
return false;
if ( this.CurPos.ContentPos < 0 )
return false;
if ( !Count || 0 == Count )
return;
if ( !Count || 0 == Count )
return;
var absCount = ( Count < 0 ? -Count : Count );
var absCount = ( Count < 0 ? -Count : Count );
// Пока сделаем для Count = 1
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
// Пока сделаем для Count = 1
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var Result = true;
if ( true === this.Selection.Use )
{
if ( true === AddToSelect )
var Result = true;
if ( true === this.Selection.Use )
{
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
if ( true === AddToSelect )
{
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.RecalculateCurPos();
this.CurPos.RealY = this.CurPos.Y;
if ( this.Lines.length - 1 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
this.Selection.EndPos = this.Content.length - 1;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
this.Selection.EndPos = this.CurPos.ContentPos;
}
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return Result;
}
}
else
{
var StartPos = this.Selection.StartPos;
var EndPos = this.Selection.EndPos;
if ( StartPos > EndPos )
{
var Temp = EndPos;
EndPos = StartPos;
StartPos = Temp;
}
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( EndPos, CursorPos_max ) ), true, -1 );
this.Selection_Remove();
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
if ( this.Lines.length - 1 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
}
else if ( AddToSelect )
{
this.Selection.Use = true;
this.Selection.StartPos = this.CurPos.ContentPos;
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
......@@ -8712,245 +9089,267 @@ Paragraph.prototype =
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return Result;
}
}
else
{
var StartPos = this.Selection.StartPos;
var EndPos = this.Selection.EndPos;
if ( StartPos > EndPos )
{
var Temp = EndPos;
EndPos = StartPos;
StartPos = Temp;
}
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( EndPos, CursorPos_max ) ), true, -1 );
this.Selection_Remove();
this.RecalculateCurPos();
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
return Result;
}
}
else
{
var CurPos2 = this.CurPos.ContentPos2;
var MathElement = this.Content[CurPos2];
if ( undefined !== MathElement && para_Math === MathElement.Type )
{
if ( true === MathElement.Cursor_MoveDown(false) )
{
if ( true === MathElement.Selection_IsUse() && false === MathElement.Selection_IsEmpty() )
this.Internal_SelectMath( CurPos2 );
this.Internal_Recalculate_CurPos( this.CurPos.ContentPos, true, false, false );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
return true;
}
else
{
this.CurPos.ContentPos2 = -1;
}
}
if ( this.Lines.length - 1 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
return Result;
}
else if ( AddToSelect )
else
{
this.Selection.Use = true;
this.Selection.StartPos = this.CurPos.ContentPos;
// Пока сделаем для Count = 1
CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
this.RecalculateCurPos();
this.CurPos.RealY = this.CurPos.Y;
if ( this.Lines.length - 1 == CurLine )
{
// Переходим в предыдущий элеменет документа
Result = false;
this.Selection.EndPos = this.Content.length - 1;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
this.Selection.EndPos = this.CurPos.ContentPos;
}
var LinePos = this.Get_CurrentParaPos();
var CurLine = LinePos.Line;
if ( this.Selection.StartPos == this.Selection.EndPos )
var Result = true;
if ( true === this.Selection.Use )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return Result;
}
}
else
{
var CurPos2 = this.CurPos.ContentPos2;
var MathElement = this.Content[CurPos2];
if ( undefined !== MathElement && para_Math === MathElement.Type )
else
{
if ( true === MathElement.Cursor_MoveDown(false) )
if ( true === AddToSelect )
{
if ( true === MathElement.Selection_IsUse() && false === MathElement.Selection_IsEmpty() )
this.Internal_SelectMath( CurPos2 );
return true;
}
else
{
this.CurPos.ContentPos2 = -1;
if ( this.Lines.length - 1 == CurLine )
{
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
}
}
}
if ( this.Lines.length - 1 == CurLine )
{
// Возвращяем значение false, это означает, что надо перейти в
// предыдущий элемент контента документа.
return false;
}
else
{
this.Cursor_MoveAt( this.CurPos.RealX, CurLine + 1, true, true );
this.CurPos.RealY = this.CurPos.Y;
}
return Result;
}
return Result;
},
Cursor_MoveEndOfLine : function(AddToSelect)
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( true !== Debug_ParaRunMode )
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( this.CurPos.ContentPos < 0 )
return false;
if ( this.CurPos.ContentPos < 0 )
return false;
if ( true === this.Selection.Use )
{
if ( true === AddToSelect )
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
else
if ( true === this.Selection.Use )
{
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( CursorPos_max, ( this.Selection.EndPos >= this.Selection.StartPos ? this.Selection.EndPos : this.Selection.StartPos ) ) ), true, -1 );
this.Selection_Remove();
if ( true === AddToSelect )
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
else
{
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( CursorPos_max, ( this.Selection.EndPos >= this.Selection.StartPos ? this.Selection.EndPos : this.Selection.StartPos ) ) ), true, -1 );
this.Selection_Remove();
}
}
}
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var LineEndPos = ( CurLine >= this.Lines.length - 1 ? this.Internal_GetEndPos() : this.Lines[CurLine + 1].StartPos - 1 );
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var LineEndPos = ( CurLine >= this.Lines.length - 1 ? this.Internal_GetEndPos() : this.Lines[CurLine + 1].StartPos - 1 );
if ( true === this.Selection.Use && true === AddToSelect )
{
this.Selection.EndPos = LineEndPos;
if ( this.Selection.StartPos == this.Selection.EndPos )
if ( true === this.Selection.Use && true === AddToSelect )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Selection.EndPos = LineEndPos;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
return;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return;
}
}
}
else if ( AddToSelect )
{
this.Selection.StartPos = this.CurPos.ContentPos;
this.Selection.Use = true;
else if ( AddToSelect )
{
this.Selection.StartPos = this.CurPos.ContentPos;
this.Selection.Use = true;
this.Selection.EndPos = LineEndPos;
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Selection.EndPos = LineEndPos;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
if ( this.Selection.StartPos == this.Selection.EndPos )
return;
}
}
else
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( LineEndPos, true, -1 );
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return;
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
else
{
this.Set_ContentPos( LineEndPos, true, -1 );
if ( true === this.Selection.Use )
{
}
else
{
if ( true === AddToSelect )
{
}
else
{
var SearchPos = new CParagraphSearchPos();
var ContentPos = this.Get_ParaContentPos( false, false );
this.Get_EndRangePos( SearchPos, ContentPos );
this.Set_ParaContentPos( SearchPos.Pos, false, false, SearchPos.Line, false );
this.RecalculateCurPos();
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
this.RecalculateCurPos();
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
},
Cursor_MoveStartOfLine : function(AddToSelect)
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( true !== Debug_ParaRunMode )
{
var CursorPos_max = this.Internal_GetEndPos();
var CursorPos_min = this.Internal_GetStartPos();
if ( this.CurPos.ContentPos < 0 )
return false;
if ( this.CurPos.ContentPos < 0 )
return false;
if ( true === this.Selection.Use )
{
if ( true === AddToSelect )
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
else
if ( true === this.Selection.Use )
{
this.Set_ContentPos( ( this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos ), true, -1 );
this.Selection_Remove();
if ( true === AddToSelect )
this.Set_ContentPos( this.Selection.EndPos, true, -1 );
else
{
this.Set_ContentPos( ( this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos ), true, -1 );
this.Selection_Remove();
}
}
}
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var LineStartPos = this.Lines[CurLine].StartPos;
if ( true === this.Selection.Use && true === AddToSelect )
{
this.Selection.EndPos = LineStartPos;
var CurLine = this.Internal_Get_ParaPos_By_Pos( this.CurPos.ContentPos).Line;
var LineStartPos = this.Lines[CurLine].StartPos;
if ( this.Selection.StartPos == this.Selection.EndPos )
if ( true === this.Selection.Use && true === AddToSelect )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Selection.EndPos = LineStartPos;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
return;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return;
}
}
}
else if ( AddToSelect )
{
this.Selection.EndPos = LineStartPos;
else if ( AddToSelect )
{
this.Selection.EndPos = LineStartPos;
this.Selection.StartPos = this.CurPos.ContentPos;
this.Selection.Use = true;
this.Selection.StartPos = this.CurPos.ContentPos;
this.Selection.Use = true;
if ( this.Selection.StartPos == this.Selection.EndPos )
if ( this.Selection.StartPos == this.Selection.EndPos )
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
return;
}
}
else
{
this.Selection_Remove();
this.Selection.Use = false;
this.Set_ContentPos( LineStartPos, true, -1 );
this.Set_ContentPos( Math.max( CursorPos_min, Math.min( this.Selection.EndPos, CursorPos_max ) ), true, -1 );
this.RecalculateCurPos();
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
return;
}
}
else
{
this.Set_ContentPos( LineStartPos, true, -1 );
if ( true === this.Selection.Use )
{
this.RecalculateCurPos();
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
else
{
if ( true === AddToSelect )
{
}
else
{
var SearchPos = new CParagraphSearchPos();
var ContentPos = this.Get_ParaContentPos( false, false );
this.Get_StartRangePos( SearchPos, ContentPos );
this.Set_ParaContentPos( SearchPos.Pos, false, false, SearchPos.Line, false );
this.RecalculateCurPos();
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
}
}
},
......@@ -9012,7 +9411,7 @@ Paragraph.prototype =
this.CurPos.ContentPos = 0;
this.Content[0].Cursor_MoveToStartPos();
this.Correct_ContentPos();
this.Correct_ContentPos(false);
}
}
},
......@@ -9075,7 +9474,7 @@ Paragraph.prototype =
this.CurPos.ContentPos = this.Content.length - 1;
this.Content[this.CurPos.ContentPos].Cursor_MoveToEndPos();
this.Correct_ContentPos();
this.Correct_ContentPos(false);
}
}
},
......@@ -10702,40 +11101,6 @@ Paragraph.prototype =
return null;
},
Cursor_MoveAt : function(X,Y, bLine, bDontChangeRealPos, PageNum)
{
var TempPos = this.Internal_GetContentPosByXY( X, Y, bLine, PageNum );
var Pos = TempPos.Pos;
var Line = TempPos.Line;
if ( undefined !== this.Content[TempPos.Pos2] && para_Math === this.Content[TempPos.Pos2].Type )
{
this.Content[TempPos.Pos2].Cursor_MoveAt( X, Y );
this.CurPos.ContentPos2 = TempPos.Pos2;
}
else
this.CurPos.ContentPos2 = -1;
if ( -1 != Pos )
{
this.Set_ContentPos( Pos, true, Line );
}
this.Internal_Recalculate_CurPos(Pos, false, false, false );
if ( bDontChangeRealPos != true )
{
this.CurPos.RealX = this.CurPos.X;
this.CurPos.RealY = this.CurPos.Y;
}
if ( true != bLine )
{
this.CurPos.RealX = X;
this.CurPos.RealY = Y;
}
},
Selection_SetStart : function(X,Y,PageNum, bTableBorder)
{
var Pos = this.Internal_GetContentPosByXY( X, Y, false, PageNum );
......@@ -17888,6 +18253,7 @@ function CParagraphSearchPos()
this.Pos = new CParagraphContentPos(); // Искомая позиция
this.Found = false; // Нашли или нет
this.Line = -1;
this.Stage = 0; // Номера этапов для поиска начала и конца слова
this.Shift = false;
......@@ -17896,3 +18262,17 @@ function CParagraphSearchPos()
this.UpdatePos = false;
}
function CParagraphSearchPosXY()
{
this.Pos = new CParagraphContentPos();
this.CurX = 0;
this.X = 0;
this.DiffX = 1000000; // километра для ограничения должно хватить
this.NumberingDiffX = 1000000; // километра для ограничения должно хватить
this.Line = 0;
this.InText = false;
this.Numbering = false;
this.End = false;
}
......@@ -78,6 +78,41 @@ ParaRun.prototype =
// Функции для работы с содержимым данного рана
//-----------------------------------------------------------------------------------
// Проверяем пустой ли ран
Is_Empty : function(SkipAnchor)
{
var Count = this.Content.length;
if ( true !== SkipAnchor )
{
if ( Count > 0 )
return false;
else
return true;
}
else
{
for ( var CurPos = 0; CurPos < this.Content.length; CurPos++ )
{
var Item = this.Content[CurPos];
if ( para_Drawing !== Item.Type || false !== Item.Is_Inline() )
return false;
}
return true;
}
},
// Начинается ли данный ран с новой строки
Is_StartFromNewLine : function()
{
if ( this.LinesLength < 2 || 0 != this.Lines[1].Ranges[0].StartPos )
return false;
return true;
},
// Добавляем элемент в текущую позицию
Add : function(Item)
{
......@@ -259,8 +294,32 @@ ParaRun.prototype =
return new CParaPos( ( LinesCount === 1 ? this.Lines[0].RangesLength - 1 + this.StartRange : this.Lines[0].RangesLength - 1 ), LinesCount - 1 + this.StartLine, 0, 0 );
},
Get_ParaPosByContentPos : function(ContentPos, Depth)
{
var Pos = ContentPos.Get(Depth);
var CurLine = 0;
var CurRange = 0;
var LinesCount = this.LinesLength;
for ( ; CurLine < LinesCount; CurLine++ )
{
var RangesCount = this.Lines[CurLine].RangesLength;
for ( CurRange = 0; CurRange < RangesCount; CurRange++ )
{
var Range = this.Lines[CurLine].Ranges[CurRange];
if ( Pos < Range.EndPos && Pos >= Range.StartPos )
return new CParaPos( ( CurLine === 0 ? CurRange + this.StartRange : CurRange ), CurLine + this.StartLine, 0, 0 );
}
}
return new CParaPos( ( LinesCount === 1 ? this.Lines[0].RangesLength - 1 + this.StartRange : this.Lines[0].RangesLength - 1 ), LinesCount - 1 + this.StartLine, 0, 0 );
},
Recalculate_CurPos : function(X, Y, CurrentRun, _CurRange, _CurLine, CurPage, UpdateCurPos, UpdateTarget, ReturnTarget)
{
var Para = this.Paragraph;
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
......@@ -315,8 +374,6 @@ ParaRun.prototype =
{
// Обновляем позицию курсора в параграфе
var Para = this.Paragraph;
Para.CurPos.X = _X;
Para.CurPos.Y = Y;
Para.CurPos.PagesPos = CurPage;
......@@ -2337,6 +2394,46 @@ ParaRun.prototype =
return false;
},
// Проверяем нужно ли поправить позицию курсора
Cursor_Is_NeededCorrectPos : function()
{
var NewRangeStart = false;
var RangeEnd = false;
var Pos = this.State.ContentPos;
var LinesLen = this.LinesLength;
for ( var CurLine = 0; CurLine < LinesLen; CurLine++ )
{
var Line = this.Lines[CurLine];
var RangesLen = Line.RangesLength;
for ( var CurRange = 0; CurRange < RangesLen; CurRange++ )
{
var Range = Line.Ranges[CurRange];
if ( 0 !== CurLine || 0 !== CurRange )
{
if ( Pos === Range.StartPos )
{
NewRangeStart = true;
}
}
if ( Pos === Range.EndPos )
{
RangeEnd = true;
}
}
if ( true === NewRangeStart )
break;
}
if ( true !== NewRangeStart && true !== RangeEnd && true === this.Cursor_Is_Start() )
return true;
return false;
},
Cursor_Is_End : function()
{
if ( this.State.ContentPos >= this.Content.length )
......@@ -2365,6 +2462,109 @@ ParaRun.prototype =
this.State.ContentPos = CurPos;
},
Get_ParaContentPosByXY : function(SearchPos, Depth, _CurLine, _CurRange)
{
var Result = false;
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
for ( var CurPos = StartPos; CurPos < EndPos; CurPos++ )
{
var Item = this.Content[CurPos];
var TempDx = 0;
var bCheck = false;
// TODO: Сделать поддержку нумерации
// if ( ItemNum === this.Numbering.Pos )
// {
// if ( para_Numbering === this.Numbering.Type )
// {
// var NumberingItem = this.Numbering;
// var NumPr = this.Numbering_Get();
// var NumJc = this.Parent.Get_Numbering().Get_AbstractNum( NumPr.NumId ).Lvl[NumPr.Lvl].Jc;
//
// var NumX0 = CurX;
// var NumX1 = CurX;
//
// switch( NumJc )
// {
// case align_Right:
// {
// NumX0 -= NumberingItem.WidthNum;
// break;
// }
// case align_Center:
// {
// NumX0 -= NumberingItem.WidthNum / 2;
// NumX1 += NumberingItem.WidthNum / 2;
// break;
// }
// case align_Left:
// default:
// {
// NumX1 += NumberingItem.WidthNum;
// break;
// }
// }
//
// if ( X >= NumX0 && X <= NumX1 )
// NumberingDiffX = 0;
// }
//
// CurX += this.Numbering.WidthVisible;
//
// if ( -1 != DiffPos )
// {
// DiffX = Math.abs( X - CurX );
// DiffPos = ItemNum;
// }
// }
if ( para_Drawing != Item.Type || true === Item.Is_Inline() )
{
TempDx = Item.WidthVisible;
}
// Проверяем, попали ли мы в данный элемент
var Diff = SearchPos.X - SearchPos.CurX;
if ( Math.abs( Diff ) < SearchPos.DiffX + 0.001 )
{
SearchPos.DiffX = Math.abs( Diff );
SearchPos.Pos.Update( CurPos, Depth );
Result = true;
if ( Diff >= - 0.001 && Diff <= TempDx + 0.001 )
{
SearchPos.InText = true;
}
}
// TODO: Сделать разруливование со строками
// if ( true != bEnd && ItemNum === this.Lines[CurLine].EndPos && X > CurX + TempDx && para_NewLine != Item.Type )
// {
// ResultLine = CurLine;
// DiffPos = ItemNum + 1;
// }
SearchPos.CurX += TempDx;
// Заглушка для знака параграфа
if ( para_End === Item.Type && Math.abs( SearchPos.X - SearchPos.CurX ) < SearchPos.DiffX )
{
SearchPos.End = true;
}
}
return Result;
},
Get_ParaContentPos : function(bSelection, bStart, ContentPos)
{
var Pos = ( true !== bSelection ? this.State.ContentPos : ( false !== bStart ? this.State.Selection.StartPos : this.State.Selection.EndPos ) );
......@@ -2623,6 +2823,62 @@ ParaRun.prototype =
SearchPos.UpdatePos = true;
}
},
Get_EndRangePos : function(_CurLine, _CurRange, SearchPos, Depth)
{
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
var LastPos = -1;
for ( var CurPos = StartPos; CurPos < EndPos; CurPos++ )
{
var Item = this.Content[CurPos];
if ( !((para_Drawing === Item.Type && true !== Item.Is_Inline) || para_End === Item.Type) )
LastPos = CurPos + 1;
}
// Проверяем, попал ли хоть один элемент в данный отрезок, если нет, тогда не регистрируем такой ран
if ( -1 !== LastPos )
{
SearchPos.Pos.Update( EndPos, Depth );
return true;
}
else
return false;
},
Get_StartRangePos : function(_CurLine, _CurRange, SearchPos, Depth)
{
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
var Range = this.Lines[CurLine].Ranges[CurRange];
var StartPos = Range.StartPos;
var EndPos = Range.EndPos;
var FirstPos = -1;
for ( var CurPos = EndPos - 1; CurPos >= StartPos; CurPos-- )
{
var Item = this.Content[CurPos];
if ( !(para_Drawing === Item.Type && true !== Item.Is_Inline) )
FirstPos = CurPos;
}
// Проверяем, попал ли хоть один элемент в данный отрезок, если нет, тогда не регистрируем такой ран
if ( -1 !== FirstPos )
{
SearchPos.Pos.Update( FirstPos, Depth );
return true;
}
else
return false;
},
//-----------------------------------------------------------------------------------
// Функции для работы с настройками текста свойств
//-----------------------------------------------------------------------------------
......
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