Пример #1
0
        /// <summary>
        /// Moves char position to edit position.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <param name="charPos">Char position</param>
        /// <returns>Edit position.</returns>
        public static OTAEditPos CharPosToEditPos(IOTASourceEditor sourceEditor, OTACharPos charPos)
        {
            IOTAEditView _EditView = GetEditView(sourceEditor);
            OTAEditPos _EditPos = new OTAEditPos();

            if (_EditView != null)
            {
                _EditView.ConvertPos(false, ref _EditPos, ref charPos);
            }

            return _EditPos;
        }
Пример #2
0
        /// <summary>
        /// Moves edit position to char position.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <param name="editPos">Edit position</param>
        /// <returns></returns>
        public static OTACharPos EditPosToCharPos(IOTASourceEditor sourceEditor, OTAEditPos editPos)
        {
            IOTAEditView _EditView = GetEditView(sourceEditor);
            OTACharPos _CharPos = new OTACharPos();

            if (_EditView != null)
            {
                _EditView.ConvertPos(true, ref editPos, ref _CharPos);
            }

            return _CharPos;
        }
Пример #3
0
        /// <summary>
        /// Replaces inclusive and exclusive.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <param name="editView">Edit view</param>
        /// <param name="isInclusive">Is inclusive flag</param>
        /// <param name="start">Start</param>
        /// <param name="after">After</param>
        /// <param name="text">Text</param>
        private static void ReplaceInclusiveExclusive(IOTASourceEditor sourceEditor,
                                                      IOTAEditView editView,
                                                      bool isInclusive,
                                                      OTACharPos start, OTACharPos
                                                      after, string text)
        {

            if (sourceEditor == null || editView == null)
            {
                return;
            }

            bool _FirstCharInLineDeleted;

            if (!isInclusive)
            {
                _FirstCharInLineDeleted = (after.CharIndex == 1);

                if (after.CharIndex > 0)
                {
                    after.CharIndex -= 1;
                }
            }
            else
            {
                _FirstCharInLineDeleted = false;
            }

            int _StartPos = editView.CharPosToPos(start);
            int _AfterPos = editView.CharPosToPos(after);

            IOTAFileWriter _Writer = sourceEditor.CreateWriter();

            _Writer.CopyTo(_StartPos);
            int _DeleteToPos = _AfterPos;

            if (after.CharIndex == 0 && ((after.Line - start.Line) == 1))
            {
                _DeleteToPos -= 2;

                if (_FirstCharInLineDeleted)
                {
                    _DeleteToPos = +3;
                }
            }
            else
            {
                if (_FirstCharInLineDeleted)
                {
                    _DeleteToPos++;
                }
                else if (after.CharIndex > 0)
                {
                    _DeleteToPos++;
                }
            }

            if (_DeleteToPos > _StartPos)
            {
                _Writer.DeleteTo(_DeleteToPos);
            }

            _Writer.Insert(text);
            _Writer.CopyTo(Int32.MaxValue);
            _Writer.Close();
        }
Пример #4
0
        /// <summary>
        /// Moves char position of source editor to buffer position.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <param name="charPos">Char position</param>
        /// <returns></returns>
        public static int CharPosToBufferPos(IOTASourceEditor sourceEditor, OTACharPos charPos)
        {
            IOTAEditView _EditView = GetEditView(sourceEditor);

            if (_EditView != null)
            {
                return _EditView.CharPosToPos(charPos);
            }

            return -1;
        }
Пример #5
0
        /// <summary>
        /// Gets source editor text position.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <returns>-1 if wrong.</returns>
        public static int GetSourceEditorTextPos(IOTASourceEditor sourceEditor)
        {
            IOTAEditView _EditView = GetEditView(sourceEditor);

            if (_EditView != null)
            {
                OTAEditPos _EditPos = _EditView.CursorPos;
                OTACharPos _CharPos = new OTACharPos();

                _EditView.ConvertPos(true, ref _EditPos, ref _CharPos);

                return _EditView.CharPosToPos(_CharPos);
            }
            else
            {
                return -1;
            }
        }