示例#1
0
文件: TextStore.cs 项目: mind0n/hive
        private bool IsCompositionRecordShifted(CompositionEventRecord record)
        {
            //
            // _previousCompositionStartOffset is set in OnUpdateComposition IME callback.
            // At this point it reflects the current offsets of the composition text.
            //

            if ((((0 <= record.StartOffsetBefore) && (0 <= _previousCompositionStartOffset))
                && (record.StartOffsetBefore < _previousCompositionStartOffset)) ||
                record.IsShiftUpdate)
            {
                return true;
            }

            return false;
        }
示例#2
0
文件: TextStore.cs 项目: mind0n/hive
        public void OnUpdateComposition(UnsafeNativeMethods.ITfCompositionView view, UnsafeNativeMethods.ITfRange rangeNew)
        {
            // If UiScope has a ToolTip and it is open, any keyboard/mouse activity should close the tooltip.
            this.TextEditor.CloseToolTip();

            Invariant.Assert(_isComposing);
            Invariant.Assert(_previousCompositionStartOffset != -1);

            ITextPointer oldStart;
            ITextPointer oldEnd;

            GetCompositionPositions(view, out oldStart, out oldEnd);

            ITextPointer newStart = null;
            ITextPointer newEnd = null;

            bool compositionRangeShifted = false;

            if (rangeNew != null)
            {
                TextPositionsFromITfRange(rangeNew, out newStart, out newEnd);
                compositionRangeShifted = (newStart.Offset != oldStart.Offset || newEnd.Offset != oldEnd.Offset);
            }

            string compositionText = TextRangeBase.GetTextInternal(oldStart, oldEnd);

            if (compositionRangeShifted)
            {
                // Add internal shift record to process it later when we raise events in RaiseCompositionEvents.
                CompositionEventRecord record = new CompositionEventRecord(CompositionStage.UpdateComposition, _previousCompositionStartOffset, _previousCompositionEndOffset, compositionText, true);
                this.CompositionEventList.Add(record);

                _previousCompositionStartOffset = newStart.Offset;
                _previousCompositionEndOffset = newEnd.Offset;

                _lastCompositionText = null;
            }
            else
            {
                // Add the composition message into the composition message list.
                // This composition message list will be handled all together after release the lock.

                CompositionEventRecord record = new CompositionEventRecord(CompositionStage.UpdateComposition, _previousCompositionStartOffset, _previousCompositionEndOffset, compositionText);
                CompositionEventRecord previousRecord = (this.CompositionEventList.Count == 0) ? null : this.CompositionEventList[this.CompositionEventList.Count - 1];

                if (_lastCompositionText == null ||
                    String.CompareOrdinal(compositionText, _lastCompositionText) != 0)
                {
                    // Add the new update event.
                    this.CompositionEventList.Add(record);
                }

                _previousCompositionStartOffset = oldStart.Offset;
                _previousCompositionEndOffset = oldEnd.Offset;
                _lastCompositionText = compositionText;
            }

            // Composition event is completed, so new composition undo unit will be opened.
            BreakTypingSequence(oldEnd);
        }