Пример #1
0
        /// <summary>
        /// Reset the selection and optionally cancel any open compositions.
        /// </summary>
        /// <param name="cancel">Set to <c>true</c> to also cancel the open composition.</param>
        /// <returns><c>true</c> if there was an open composition that we cancelled, otherwise
        /// <c>false</c>.</returns>
        private bool Reset(bool cancel)
        {
            if (m_InReset)
            {
                return(false);
            }

            bool retVal = false;

            m_InReset = true;
            try
            {
                if (cancel)
                {
                    if (m_ActionHandler != null &&
                        (m_ActionHandler.get_TasksSinceMark(true) || m_Depth != m_ActionHandler.CurrentDepth))
                    {
                        m_ActionHandler.Rollback(m_Depth);
                        retVal = true;
                    }
                    else if (m_InitialSelection != null && m_EndOfPreedit != null)
                    {
                        var selHelper = SetupForTypingEventHandler(false, true);
                        if (selHelper != null)
                        {
                            // Update selection so that we can delete the preedit-text
                            UpdateSelectionForReplacingPreeditText(selHelper, 0);
                            selHelper.SetSelection(true);

                            if (selHelper.IsValid && selHelper.IsRange)
                            {
                                var tss = CreateTsStringUsingSelectionProps(string.Empty, null, false);
                                selHelper.Selection.ReplaceWithTsString(tss);
                            }
                        }
                    }
                }
                m_ActionHandler = null;

                if (m_InitialSelection != null)
                {
                    m_InitialSelection.RestoreSelection();
                }

                m_InitialSelection = null;
                m_EndOfPreedit     = null;
                return(retVal);
            }
            finally
            {
                m_InReset = false;
                OnPreeditClosed();
            }
        }