Exemple #1
0
        /*
         *  かな漢字変換の途中で表示するテキストの書式を指定してきた。
         */
        private void EditContext_FormatUpdating(CoreTextEditContext sender, CoreTextFormatUpdatingEventArgs ev)
        {
            Debug.WriteLine("<<--- FormatUpdating: BG:{0} cancel:{1} range:({2},{3}) reason:{4} result:{5} color:{6} under-line:({7},{8})",
                            (ev.BackgroundColor == null ? "null" : ev.BackgroundColor.Value.ToString()),
                            ev.IsCanceled,
                            ev.Range.StartCaretPosition, ev.Range.EndCaretPosition,
                            ev.Reason,
                            ev.Result,
                            (ev.TextColor == null ? "null" : ev.TextColor.Value.ToString()),
                            (ev.UnderlineColor == null ? "null" : ev.UnderlineColor.Value.ToString()),
                            (ev.UnderlineType == null ? "null" : ev.UnderlineType.Value.ToString())
                            );

            if (ev.UnderlineType != null)
            {
                // 下線がnullでない場合

                // 選択範囲の文字の下線を指定します。
                for (int i = ev.Range.StartCaretPosition; i < ev.Range.EndCaretPosition; i++)
                {
                    // TCharはstructなので Chars[i]=ev.UnderlineType.Value; と書くとエラーになります。
                    TChar ch = Chars[i];
                    ch.Underline = ev.UnderlineType.Value;
                    Chars[i]     = ch;
                }
            }

            // 再描画します。
            Win2DCanvas.Invalidate();
        }
Exemple #2
0
        /*
         *  字句型を更新します。
         */
        void UpdateTokenType(int sel_start, int sel_end)
        {
            // 行の先頭位置
            int line_top = GetLineTop(sel_start);

            // 直前の字句型
            ETokenType last_token_type = (line_top == 0 ? ETokenType.Undefined : Chars[line_top - 1].CharType);

            for (;;)
            {
                // 次の行の先頭位置または文書の終わり
                int next_line_top = GetNextLineTopOrEOT(line_top);

                // 行の先頭位置から次の行の先頭位置または文書の終わりまでの文字列
                string lex_string = StringFromRange(line_top, next_line_top);

                // 変更前の最後の字句型
                ETokenType last_token_type_before = (next_line_top == 0 ? ETokenType.Undefined : Chars[next_line_top - 1].CharType);

                // 現在行の字句解析をして字句タイプのリストを得ます。
                ETokenType[] token_type_list = LexicalAnalysis(lex_string, last_token_type);

                // 字句型をテキストにセットします。
                for (int i = 0; i < token_type_list.Length; i++)
                {
                    TChar ch = Chars[line_top + i];
                    ch.CharType         = token_type_list[i];
                    Chars[line_top + i] = ch;
                }

                // 変更後の最後の字句型
                last_token_type = (token_type_list.Length == 0 ? ETokenType.Undefined : token_type_list[token_type_list.Length - 1]);

                if (sel_end <= next_line_top)
                {
                    // 変更した文字列の字句解析が終わった場合

                    if (last_token_type == last_token_type_before)
                    {
                        // 最後の字句型が同じ場合

                        break;
                    }
                    else
                    {
                        // 最後の字句型が違う場合

                        if (last_token_type_before != ETokenType.BlockComment && last_token_type_before != ETokenType.VerbatimString &&
                            last_token_type != ETokenType.BlockComment && last_token_type != ETokenType.VerbatimString)
                        {
                            // 変更前も変更後の最後の字句が複数行にまたがらない場合

                            break;
                        }
                    }
                }

                // 次の行の字句解析をします。
                line_top = next_line_top;
            }
        }
 public TDiff(int pos, int removed_cound, int inserted_count)
 {
     DiffPos       = pos;
     RemovedChars  = new TChar[removed_cound];
     InsertedCount = inserted_count;
 }