示例#1
0
        public void PasteLastLine()
        {
            _nextInputInline = null;

            if (!Clipboard.ContainsText())
            {
                return;
            }

            var data = Clipboard.GetText();

            if (data != null)
            {
                var strs = StyledTextUtil.SplitWithBlockBreak(data);
                if (strs.Any())
                {
                    var last = strs.Last();
                    if (!string.IsNullOrEmpty(last))
                    {
                        Insert(last);
                    }
                }
            }
        }
示例#2
0
 // ------------------------------
 // protected
 // ------------------------------
 /// <summary>
 /// 改行はスペースに変換.
 /// '\n'はBlockBreak,'\r'はLineBreakであらわすため.
 /// </summary>
 protected string Sanitize(string s)
 {
     return(StyledTextUtil.NormalizeLineBreak(s, " "));
 }
示例#3
0
        public void InsertText(string text, bool inBlock)
        {
            _nextInputInline = null;

            if (StringUtil.IsNullOrWhitespace(text))
            {
                return;
            }

            var cmds             = new CompositeCommand();
            var hasLastLineBreak = text[text.Length - 1] == '\n' || text[text.Length - 1] == '\r';
            var lines            = StyledTextUtil.SplitWithBlockBreak(text);

            if (lines.Any())
            {
                if (!_selection.IsEmpty)
                {
                    /// 範囲選択されているならその範囲を削除
                    var index = _selection.Offset;
                    cmds.Children.Add(new RemoveCommand(_target, _selection.Offset, _selection.Length));
                    CaretIndex = index;
                    ClearSelection();
                }

                var firstLine  = lines[0];
                var lastLine   = lines[lines.Length - 1];
                var caretIndex = _caretIndex;
                var urlRanges  = new List <Tuple <Range, string> >(); /// for link
                foreach (var line in lines)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        _nextInputInline = null;
                        var sanitized = line.Replace("\t", "    ");

                        /// link取得
                        var ranges = StringUtil.GetUrlRanges(sanitized);
                        if (ranges.Any())
                        {
                            foreach (var r in ranges)
                            {
                                var tuple = Tuple.Create(
                                    new Range(r.Offset + caretIndex, r.Length),
                                    sanitized.Substring(r.Offset, r.Length)
                                    );
                                urlRanges.Add(tuple);
                            }
                        }

                        if (line == firstLine)
                        {
                            cmds.Children.Add(new InsertStringCommand(_target, caretIndex, sanitized));
                        }
                        else
                        {
                            cmds.Children.Add(
                                new InsertInlineCommand(_target, caretIndex, new Run(sanitized))
                                );
                        }
                        caretIndex += sanitized.Length;
                    }
                    if (line != lastLine || hasLastLineBreak)
                    {
                        if (inBlock)
                        {
                            cmds.Children.Add(new InsertLineBreakCommand(_target, caretIndex));
                        }
                        else
                        {
                            cmds.Children.Add(new InsertBlockBreakCommand(_target, caretIndex));
                        }
                        ++caretIndex;
                    }
                }

                /// link設定
                foreach (var urlRange in urlRanges)
                {
                    var link = new SetLinkCommand(_target, urlRange.Item1, new Link(urlRange.Item2));
                    cmds.Children.Add(link);
                }

                _executor.Execute(cmds);
                CaretIndex = caretIndex;
            }
        }