示例#1
0
        private string GetTextFromLineSelectArea(SelectCollection Selections)
        {
            Selection sel = Util.NormalizeIMaker <Selection>(Selections.First());

            string str = this.Document.ToString(sel.start, sel.length);

            return(str);
        }
示例#2
0
        string GetTextFromRectangleSelectArea(SelectCollection Selections)
        {
            StringBuilder temp = new StringBuilder();

            if (Selections.First().start < Selections.Last().start)
            {
                for (int i = 0; i < this.View.Selections.Count; i++)
                {
                    Selection sel = Util.NormalizeIMaker <Selection>(Selections[i]);

                    string str = this.Document.ToString(sel.start, sel.length);
                    if (str.IndexOf(Environment.NewLine) == -1)
                    {
                        temp.AppendLine(str);
                    }
                    else
                    {
                        temp.Append(str);
                    }
                }
            }
            else
            {
                for (int i = this.View.Selections.Count - 1; i >= 0; i--)
                {
                    Selection sel = Util.NormalizeIMaker <Selection>(Selections[i]);

                    string str = this.Document.ToString(sel.start, sel.length).Replace(Document.NewLine.ToString(), Environment.NewLine);
                    if (str.IndexOf(Environment.NewLine) == -1)
                    {
                        temp.AppendLine(str);
                    }
                    else
                    {
                        temp.Append(str);
                    }
                }
            }
            return(temp.ToString());
        }
示例#3
0
        private void RepleaceSelectionArea(SelectCollection Selections, string value, bool updateInsertPoint = false)
        {
            if (value == null)
            {
                return;
            }

            if (this.RectSelection == false)
            {
                Selection sel = Selection.Create(this.Document.AnchorIndex, 0);
                if (Selections.Count > 0)
                {
                    sel = Util.NormalizeIMaker <Selection>(this.View.Selections.First());
                }

                this.Document.Replace(sel.start, sel.length, value);
                return;
            }

            if (this.Document.FireUpdateEvent == false)
            {
                throw new InvalidOperationException("");
            }

            int StartIndex = this.SelectionStart;

            SelectCollection newInsertPoint = new SelectCollection();

            if (this.SelectionLength == 0)
            {
                int i;

                this.Document.UndoManager.BeginUndoGroup();

                this.Document.FireUpdateEvent = false;

                string[] line = value.Split(new string[] { Document.NewLine.ToString() }, StringSplitOptions.RemoveEmptyEntries);

                TextPoint Current = this.View.GetLayoutLineFromIndex(this.SelectionStart);

                for (i = 0; i < line.Length && Current.row < this.View.LayoutLines.Count; i++, Current.row++)
                {
                    if (Current.col > this.View.LayoutLines[Current.row].Length)
                    {
                        Current.col = this.View.LayoutLines[Current.row].Length;
                    }
                    StartIndex = this.View.GetIndexFromLayoutLine(Current);
                    this.Document.Replace(StartIndex, 0, line[i]);
                    StartIndex += line[i].Length;
                }

                for (; i < line.Length; i++)
                {
                    StartIndex = this.Document.Length;
                    string str = Document.NewLine + line[i];
                    this.Document.Replace(StartIndex, 0, str);
                    StartIndex += str.Length;
                }

                this.Document.FireUpdateEvent = true;

                this.Document.UndoManager.EndUndoGroup();
            }
            else
            {
                SelectCollection temp = new SelectCollection(this.View.Selections); //コピーしないとReplaceCommandを呼び出した段階で書き換えられてしまう

                this.Document.UndoManager.BeginUndoGroup();

                this.Document.FireUpdateEvent = false;

                if (temp.First().start < temp.Last().start)
                {
                    for (int i = temp.Count - 1; i >= 0; i--)
                    {
                        Selection sel = Util.NormalizeIMaker <Selection>(temp[i]);

                        StartIndex = sel.start;

                        this.Document.Replace(sel.start, sel.length, value);

                        newInsertPoint.Add(Selection.Create(sel.start + (value.Length - sel.length) * i, 0));
                    }
                }
                else
                {
                    for (int i = 0; i < temp.Count; i++)
                    {
                        Selection sel = Util.NormalizeIMaker <Selection>(temp[i]);

                        StartIndex = sel.start;

                        this.Document.Replace(sel.start, sel.length, value);

                        newInsertPoint.Add(Selection.Create(sel.start + (value.Length - sel.length) * i, 0));
                    }
                }

                this.Document.FireUpdateEvent = true;

                this.Document.UndoManager.EndUndoGroup();
            }
            this.JumpCaret(StartIndex);
            if (updateInsertPoint && newInsertPoint.Count > 0)
            {
                this.View.Selections = newInsertPoint;
            }
        }
示例#4
0
        private void ReplaceBeforeSelectionArea(SelectCollection Selections, int removeLength, string insertStr)
        {
            if (removeLength == 0 && insertStr.Length == 0)
            {
                return;
            }

            if (this.RectSelection == false || this.Document.FireUpdateEvent == false)
            {
                throw new InvalidOperationException();
            }

            SelectCollection temp = this.View.Selections;
            int selectStart       = temp.First().start;
            int selectEnd         = temp.Last().start + temp.Last().length;

            //ドキュメント操作後に行うとうまくいかないので、あらかじめ取得しておく
            TextPoint start = this.View.LayoutLines.GetTextPointFromIndex(selectStart);
            TextPoint end   = this.View.LayoutLines.GetTextPointFromIndex(selectEnd);

            bool reverse = temp.First().start > temp.Last().start;

            int lineHeadIndex = this.View.LayoutLines.GetIndexFromLineNumber(this.View.LayoutLines.GetLineNumberFromIndex(selectStart));

            if (selectStart - removeLength < lineHeadIndex)
            {
                return;
            }

            this.Document.UndoManager.BeginUndoGroup();
            this.Document.FireUpdateEvent = false;

            if (reverse)
            {
                for (int i = 0; i < temp.Count; i++)
                {
                    this.ReplaceBeforeSelection(temp[i], removeLength, insertStr);
                }
            }
            else
            {
                for (int i = temp.Count - 1; i >= 0; i--)
                {
                    this.ReplaceBeforeSelection(temp[i], removeLength, insertStr);
                }
            }

            this.Document.FireUpdateEvent = true;
            this.Document.UndoManager.EndUndoGroup();

            int delta = insertStr.Length - removeLength;

            start.col += delta;
            end.col   += delta;

            if (reverse)
            {
                this.JumpCaret(start.row, start.col);
            }
            else
            {
                this.JumpCaret(end.row, end.col);
            }

            this.Document.Select(start, 0, end.row - start.row);
        }