Example #1
0
        //indexの位置の表示を反転した新しいGLineを返す
        //inverseがfalseだと、GWordの分割はするがDecorationの反転はしない。ヒクヒク問題の対処として実装。
        internal GLine InverseCaret(int index, bool inverse, bool underline)
        {
            ExpandBuffer(index + 1);
            if (_text[index] == WIDECHAR_PAD)
            {
                index--;
            }
            GLine ret = new GLine(_text, null);

            ret.ID      = _id;
            ret.EOLType = _eolType;

            GWord w          = _firstWord;
            int   nextoffset = 0;

            while (w != null)
            {
                nextoffset = WordNextOffset(w);
                if (w.Offset <= index && index < nextoffset)
                {
                    //!!tailから順に連結した方が効率はよい
                    if (w.Offset < index)
                    {
                        GWord head = new GWord(w.Decoration, w.Offset, w.CharGroup);
                        ret.Append(head);
                    }

                    TextDecoration dec = (TextDecoration)w.Decoration.Clone();
                    if (inverse)
                    {
                        //色つきキャレットのサポート
                        dec.ToCaretStyle();
                    }
                    if (underline)
                    {
                        dec.Underline = true;
                    }
                    GWord mid = new GWord(dec, index, w.CharGroup);
                    ret.Append(mid);

                    if (index + CalcDisplayLength(_text[index]) < nextoffset)
                    {
                        GWord tail = new GWord(w.Decoration, index + CalcDisplayLength(_text[index]), w.CharGroup);
                        ret.Append(tail);
                    }
                }
                else
                {
                    ret.Append(w.StandAloneClone());
                }

                w = w.Next;
            }

            //!!この、キャレット位置にスペースを入れるのはInverseとは違う処理であるから分離すること
            if (nextoffset <= index)
            {
                while (nextoffset <= index)
                {
                    Debug.Assert(nextoffset < ret.Text.Length);
                    ret.Text[nextoffset++] = ' ';
                }
                TextDecoration dec = TextDecoration.ClonedDefault();
                if (inverse)
                {
                    dec.ToCaretStyle();
                }
                if (underline)
                {
                    dec.Underline = true;
                }
                ret.Append(new GWord(dec, index, CharGroup.SingleByte));
            }

            return(ret);
        }