コード例 #1
0
        private void CheckCharQueue(ref char[] text, ref int caret)
        {
            CharQueue cq = _context.CharQueue;

            lock (cq) {
                if (cq.IsEmpty)
                {
                    return;
                }

                //適用の必要あるときはテキストはローカルコピーで作業
                text = (char[])text.Clone();

                while (!cq.IsEmpty)
                {
                    char ch = cq.PopChar();
                    if (ch == (char)0x08)
                    {
                        if (caret > 0)
                        {
                            text[--caret] = ' ';
                        }
                    }
                    else if ((char)0x21 <= ch && ch <= (char)0x7E) //TODO 別関数。IsPrintableとか
                    {
                        if (caret < text.Length - 1)
                        {
                            text[caret++] = ch;
                        }
                    }
                    Debug.WriteLineIf(DebugOpt.IntelliSense, "Queue Worked");
                }
            }
        }
コード例 #2
0
        private void CheckCharQueue(ref string text, ref int caret)
        {
            CharQueue cq = _context.CharQueue;

            lock (cq) {
                if (cq.IsEmpty)
                {
                    return;
                }

                StringBuilder edit = new StringBuilder(text);

                while (!cq.IsEmpty)
                {
                    char ch = cq.PopChar();
                    if (ch == (char)0x08)
                    {
                        if (caret > 0)
                        {
                            caret--;
                            if (caret < edit.Length)
                            {
                                edit.Remove(caret, 1);
                            }
                        }
                    }
                    else if ((char)0x21 <= ch && ch <= (char)0x7E)   //TODO 別関数。IsPrintableとか
                    {
                        if (caret <= edit.Length)
                        {
                            edit.Insert(caret, ch);
                            caret++;
                        }
                    }
                    Debug.WriteLineIf(DebugOpt.IntelliSense, "Queue Worked");
                }

                text = edit.ToString();
            }
        }