Ejemplo n.º 1
0
        private IEnumerator <object> HandleInputTask()
        {
            bool wasFocused = false;

            var rightClickGesture  = new ClickGesture(1);
            var clickGesture       = new ClickGesture();
            var doubleClickGesture = new DoubleClickGesture();
            var dragGesture        = new DragGesture(0, DragDirection.Any, dragThreshold: EditorParams.MouseSelectionThreshold);

            ClickableWidget.Gestures.Add(rightClickGesture);
            ClickableWidget.Gestures.Add(clickGesture);
            ClickableWidget.Gestures.Add(doubleClickGesture);
            ClickableWidget.Gestures.Add(dragGesture);

            while (true)
            {
                if (EditorParams.SelectAllOnFocus && !wasFocused && FocusableWidget.IsFocused())
                {
                    SelectAll();
                    CaretPos.TextPos = TextLength;
                }
                if (FocusableWidget.IsFocused())
                {
                    HandleKeys();
                    HandleTextInput();
                }
                if (clickGesture.WasRecognized())
                {
                    if (!FocusableWidget.IsFocused())
                    {
                        if (EditorParams.SelectAllOnFocus)
                        {
                            SelectAll();
                        }
                    }
                    else
                    {
                        HideSelection();
                    }
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                }
                if (doubleClickGesture.WasRecognized())
                {
                    if (IsTextReadable)
                    {
                        SelectWord();
                    }
                    else
                    {
                        SelectAll();
                    }
                }
                if (rightClickGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    ShowContextMenu(true);
                }
                if (dragGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.ToLocalMousePosition(dragGesture.MousePressPosition);
                    HideSelection();
                    EnsureSelection();
                    SelectionStart.AssignFrom(CaretPos);
                }
                else if (dragGesture.WasChanged())
                {
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                    EnsureSelection();
                    SelectionEnd.AssignFrom(CaretPos);
                }
                Text.SyncCaretPosition();
                AdjustSizeAndScrollToCaret();
                var isFocused = CaretPos.IsVisible = FocusableWidget.IsFocused();
                if (wasFocused && !isFocused)
                {
                    HideSelection();
                    if (History.CanUndo())
                    {
                        History.Clear();
                        Text.Submit();
                    }
                }
                wasFocused = isFocused;
                yield return(null);
            }
        }
Ejemplo n.º 2
0
 private void MoveCaretSelection(Action move)
 {
     EnsureSelection();
     move();
     SelectionEnd.AssignFrom(CaretPos);
 }