Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Fills buffer from string.
 /// </summary>
 /// <param name="sourceEditor">Source editor</param>
 /// <param name="source">Source string</param>
 public static void FillBufferFromString(IOTASourceEditor sourceEditor, string source)
 {
     if (sourceEditor != null)
     {
         IOTAFileWriter _Writer = sourceEditor.CreateWriter();
         _Writer.CopyTo(0);
         _Writer.DeleteTo(MAX_READ_SIZE);
         _Writer.Insert(source);
         _Writer.Close();
     }
 }