Ejemplo n.º 1
0
        /*
         *  テキストの選択位置の変更をIMEに伝えます。
         */
        void MyNotifySelectionChanged()
        {
            CoreTextRange new_range;

            new_range.StartCaretPosition = SelStart;
            new_range.EndCaretPosition   = SelEnd;

            Debug.WriteLine("--->> NotifySelectionChanged");
            editContext.NotifySelectionChanged(new_range);
        }
Ejemplo n.º 2
0
 // Change the selection and notify CoreTextEditContext of the new selection.
 void SetSelectionAndNotify(CoreTextRange selection)
 {
     SetSelection(selection);
     _editContext.NotifySelectionChanged(_selection);
 }
Ejemplo n.º 3
0
        /*
         *  キーが押された。
         */
        private void CoreWindow_KeyDown(CoreWindow sender, KeyEventArgs args)
        {
            Debug.WriteLine("<<--- Key Down {0}", args.VirtualKey);

            switch (args.VirtualKey)
            {
            case Windows.System.VirtualKey.Left: // 左矢印(←)キー

                // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
                RemoveCursor();

                if (0 < Selection.EndCaretPosition)
                {
                    // テキストの選択位置が左端でない場合

                    // テキストの選択位置を1つ左に移動します。
                    Selection.EndCaretPosition--;
                    Selection.StartCaretPosition = Selection.EndCaretPosition;

                    // IMEに選択位置の変更を知らせます。
                    Debug.WriteLine("--->> NotifySelectionChanged");
                    editContext.NotifySelectionChanged(Selection);
                }

                // カーソルを挿入します。
                InsertCursor();
                break;

            case Windows.System.VirtualKey.Right: // 右矢印(→)キー

                // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
                RemoveCursor();

                if (Selection.EndCaretPosition < EditText.Inlines.Count)
                {
                    // テキストの選択位置が右端でない場合

                    // テキストの選択位置を1つ右に移動します。
                    Selection.EndCaretPosition++;
                    Selection.StartCaretPosition = Selection.EndCaretPosition;

                    // IMEに選択位置の変更を知らせます。
                    Debug.WriteLine("--->> NotifySelectionChanged");
                    editContext.NotifySelectionChanged(Selection);
                }

                // カーソルを挿入します。
                InsertCursor();
                break;


            case Windows.System.VirtualKey.Delete: // Deleteキー

                // カーソルがあると文字の操作に邪魔なので、いったん取り除きます。
                RemoveCursor();

                if (Selection.EndCaretPosition < EditText.Inlines.Count)
                {
                    // テキストの選択位置が右端でない場合

                    // テキストの選択位置の文字を1つ削除します。
                    EditText.Inlines.RemoveAt(Selection.EndCaretPosition);

                    // 削除前のテキストの選択位置をセットします。
                    CoreTextRange modified_range;
                    modified_range.StartCaretPosition = Selection.EndCaretPosition;
                    modified_range.EndCaretPosition   = Selection.EndCaretPosition + 1;

                    // 削除後のテキストの選択位置をセットします。
                    Selection.StartCaretPosition = Selection.EndCaretPosition;

                    // IMEにテキストの変更を知らせます。
                    Debug.WriteLine("--->> NotifyTextChanged");
                    editContext.NotifyTextChanged(modified_range, 0, Selection);
                }

                // カーソルを挿入します。
                InsertCursor();
                break;
            }
        }