示例#1
0
        /// <summary>
        /// Try to keep the selection from including any of the characters in a writing system label.
        /// See LT-8396.
        /// </summary>
        protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
        {
            base.HandleSelectionChange(prootb, vwselNew);
            // 1) We don't want to recurse into here.
            // 2) If the selection is invalid we can't use it.
            // 3) If the selection is entirely formattable ("IsSelectionInOneFormattableProp"), we don't need to do
            //    anything.
            if (s_fProcessingSelectionChanged || !vwselNew.IsValid || EditingHelper.IsSelectionInOneFormattableProp())
            {
                return;
            }
            try
            {
                s_fProcessingSelectionChanged = true;

                SelectionHelper hlpr         = SelectionHelper.Create(vwselNew, this);
                bool            fRange       = hlpr.IsRange;
                bool            fChangeRange = false;
                if (fRange)
                {
                    bool fAnchorEditable = vwselNew.IsEditable;
                    hlpr.GetIch(SelectionHelper.SelLimitType.Anchor);
                    int tagAnchor = hlpr.GetTextPropId(SelectionHelper.SelLimitType.Anchor);
                    hlpr.GetIch(SelectionHelper.SelLimitType.End);
                    int  tagEnd           = hlpr.GetTextPropId(SelectionHelper.SelLimitType.End);
                    bool fEndBeforeAnchor = vwselNew.EndBeforeAnchor;
                    if (fEndBeforeAnchor)
                    {
                        if (fAnchorEditable && tagAnchor > 0 && tagEnd < 0)
                        {
                            hlpr.SetTextPropId(SelectionHelper.SelLimitType.End, tagAnchor);
                            hlpr.SetIch(SelectionHelper.SelLimitType.End, 0);
                            fChangeRange = true;
                        }
                    }
                    else
                    {
                        if (!fAnchorEditable && tagAnchor < 0 && tagEnd > 0)
                        {
                            hlpr.SetTextPropId(SelectionHelper.SelLimitType.Anchor, tagEnd);
                            hlpr.SetIch(SelectionHelper.SelLimitType.Anchor, 0);
                            fChangeRange = true;
                        }
                    }
                }
                if (fChangeRange)
                {
                    hlpr.SetSelection(true);
                }
            }
            finally
            {
                s_fProcessingSelectionChanged = false;
            }
        }
示例#2
0
            /// <summary>
            /// Try to keep the selection from including any of the characters in a writing system label.
            /// Also update the writing system label if needed.
            /// </summary>
            protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
            {
                base.HandleSelectionChange(prootb, vwselNew);

                // 1) We don't want to recurse into here.
                // 2) If the selection is invalid we can't use it.
                if (s_fProcessingSelectionChanged || !vwselNew.IsValid)
                {
                    return;
                }
                try
                {
                    s_fProcessingSelectionChanged = true;

                    // If the selection is entirely formattable ("IsSelectionInOneFormattableProp"), we don't need to do
                    // the following selection truncation.
                    var hlpr = SelectionHelper.Create(vwselNew, this);
                    if (!EditingHelper.IsSelectionInOneFormattableProp())
                    {
                        var fRange       = hlpr.IsRange;
                        var fChangeRange = false;
                        if (fRange)
                        {
                            var fAnchorEditable = vwselNew.IsEditable;
                            hlpr.GetIch(SelectionHelper.SelLimitType.Anchor);
                            var tagAnchor = hlpr.GetTextPropId(SelectionHelper.SelLimitType.Anchor);
                            hlpr.GetIch(SelectionHelper.SelLimitType.End);
                            var tagEnd           = hlpr.GetTextPropId(SelectionHelper.SelLimitType.End);
                            var fEndBeforeAnchor = vwselNew.EndBeforeAnchor;
                            if (fEndBeforeAnchor)
                            {
                                if (fAnchorEditable && tagAnchor > 0 && tagEnd < 0)
                                {
                                    hlpr.SetTextPropId(SelectionHelper.SelLimitType.End, tagAnchor);
                                    hlpr.SetIch(SelectionHelper.SelLimitType.End, 0);
                                    fChangeRange = true;
                                }
                            }
                            else
                            {
                                if (!fAnchorEditable && tagAnchor < 0 && tagEnd > 0)
                                {
                                    hlpr.SetTextPropId(SelectionHelper.SelLimitType.Anchor, tagEnd);
                                    hlpr.SetIch(SelectionHelper.SelLimitType.Anchor, 0);
                                    fChangeRange = true;
                                }
                            }
                        }
                        if (fChangeRange)
                        {
                            hlpr.SetSelection(true);
                        }
                    }
                    if (m_fShowWsLabel)
                    {
                        // Might not be, especially when messing with the selection during Undoing the creation of a record.
                        if (Cache.ServiceLocator.IsValidObjectId(m_hvoObj))
                        {
                            var tss = m_rootb.DataAccess.get_StringProp(m_hvoObj, m_flid);
                            var ttp = tss.get_Properties(0);
                            int var;
                            var ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);
                            if (ws != 0 && m_vc is StringSliceVc && ws != (m_vc as StringSliceVc).WsLabel)
                            {
                                m_rootb.Reconstruct();
                                hlpr.SetSelection(true);
                            }
                        }
                    }
                }
                finally
                {
                    s_fProcessingSelectionChanged = false;
                }
            }