InsertText() публичный Метод

Inserts text at the given position
public InsertText ( int position, string text ) : Range
position int The position to insert text in
text string Text to insert
Результат Range
Пример #1
0
        /// <summary> Tested ? Working ? </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        private void selectedScintilla_AutoCompleteAccepted(object sender, AutoCSelectionEventArgs e)
        {
            if (!hit)
            {
                //ahk.MsgBox(e.Text.ToString());
                hit = true;

                var    currentPos   = selectedScintilla.CurrentPosition;
                var    wordStartPos = selectedScintilla.WordStartPosition(currentPos, true);
                string SoFarText    = selectedScintilla.GetWordFromPosition(wordStartPos); // word typed so far

                var lenEntered = currentPos - wordStartPos;
                selectedScintilla.DeleteRange(wordStartPos, lenEntered);

                string NewPaste = SoFarText;

                //if (SoFarText == "List_String") { NewPaste = "List<string> list = new List<string>();\n"; }
                //if (SoFarText == "SQLiteGen") { ahk.MsgBox("Started Tool"); }
                selectedScintilla.InsertText(selectedScintilla.CurrentPosition, NewPaste);
                //selectedScintilla.CurrentPosition()
                //selectedScintilla.CurrentPosition(selectedScintilla.CurrentPosition + NewPaste.Length);
                //int currentline = scintilla1.CurrentLine;
                selectedScintilla.GotoPosition(selectedScintilla.CurrentPosition + NewPaste.Length);
                //ahk.MsgBox("Pasted: " + SoFarText);
            }
        }
Пример #2
0
        public void StreamComment()
        {
            if (string.IsNullOrEmpty(_streamCommentPrefix) || string.IsNullOrEmpty(_streamCommentSufix))
            {
                return;
            }

            NativeScintilla.BeginUndoAction();

            Range selRange = Scintilla.Selection.Range;

            Scintilla.InsertText(selRange.Start, _streamCommentPrefix);
            Scintilla.InsertText(selRange.End + _streamCommentPrefix.Length, _streamCommentSufix);
            selRange.End += _streamCommentPrefix.Length + _streamCommentSufix.Length;
            selRange.Select();

            NativeScintilla.EndUndoAction();
        }
Пример #3
0
        public void ToggleLineComment()
        {
            if (string.IsNullOrEmpty(_lineCommentPrefix))
            {
                return;
            }

            NativeScintilla.BeginUndoAction();

            Range selRange = Scintilla.Selection.Range;
            int   start    = selRange.StartingLine.Number;
            int   end      = selRange.EndingLine.Number;

            int offset = _lineCommentPrefix.Length;

            for (int i = start; i <= end; i++)
            {
                Line l             = Scintilla.Lines[i];
                int  firstWordChar = FindFirstNonWhitespaceChar(l.Text);
                if (firstWordChar >= 0)
                {
                    int   startPos     = l.StartPosition + firstWordChar;
                    Range commentRange = Scintilla.GetRange(startPos, startPos + offset);
                    if (commentRange.Text == _lineCommentPrefix)
                    {
                        commentRange.Text = string.Empty;
                        selRange.End     -= offset;
                    }
                    else
                    {
                        Scintilla.InsertText(l.StartPosition + firstWordChar, _lineCommentPrefix);
                        selRange.End += offset;
                    }
                }
            }

            NativeScintilla.EndUndoAction();
            selRange.Select();
        }
Пример #4
0
        public void LineComment()
        {
            if (string.IsNullOrEmpty(_lineCommentPrefix))
            {
                return;
            }

            // So the theory behind line commenting is that for every selected line
            // we look for the first non-whitespace character and insert the line
            // comment prefix. Lines without non-whitespace are skipped.
            NativeScintilla.BeginUndoAction();

            Range selRange = Scintilla.Selection.Range;
            int   start    = selRange.StartingLine.Number;
            int   end      = selRange.EndingLine.Number;

            // We're tracking the new _end of the selection range including
            // the amount it expands because we're inserting new text.
            int offset = _lineCommentPrefix.Length;

            for (int i = start; i <= end; i++)
            {
                Line l             = Scintilla.Lines[i];
                int  firstWordChar = FindFirstNonWhitespaceChar(l.Text);
                if (firstWordChar >= 0)
                {
                    Scintilla.InsertText(l.StartPosition + firstWordChar, _lineCommentPrefix);
                    selRange.End += offset;
                }
            }

            NativeScintilla.EndUndoAction();

            // An odd side-effect of InsertText is that we lose the current
            // selection. This is undesirable. This is why we were tracking
            // the _end position offset.
            selRange.Select();
        }
Пример #5
0
        //stolen from https://github.com/jacobslusser/ScintillaNET/wiki/Character-Autocompletion#finishing-touch
        private void InsertMatchedChars(CharAddedEventArgs e)
        {
            var caretPos = _codeArea.CurrentPosition;
            var docStart = caretPos == 1;
            var docEnd   = caretPos == _codeArea.Text.Length;

            var charPrev = docStart ? _codeArea.GetCharAt(caretPos) : _codeArea.GetCharAt(caretPos - 2);
            var charNext = _codeArea.GetCharAt(caretPos);

            var isCharPrevBlank = charPrev == ' ' || charPrev == '\t' ||
                                  charPrev == '\n' || charPrev == '\r';

            var isCharNextBlank = charNext == ' ' || charNext == '\t' ||
                                  charNext == '\n' || charNext == '\r' ||
                                  docEnd;

            var isEnclosed = (charPrev == '(' && charNext == ')') ||
                             (charPrev == '{' && charNext == '}') ||
                             (charPrev == '[' && charNext == ']');

            var isSpaceEnclosed = (charPrev == '(' && isCharNextBlank) || (isCharPrevBlank && charNext == ')') ||
                                  (charPrev == '{' && isCharNextBlank) || (isCharPrevBlank && charNext == '}') ||
                                  (charPrev == '[' && isCharNextBlank) || (isCharPrevBlank && charNext == ']');

            var isCharOrString = (isCharPrevBlank && isCharNextBlank) || isEnclosed || isSpaceEnclosed;

            var charNextIsCharOrString = charNext == '"' || charNext == '\'';

            switch (e.Char)
            {
            case '(':
                if (charNextIsCharOrString)
                {
                    return;
                }
                _codeArea.InsertText(caretPos, ")");
                break;

            case '{':
                if (charNextIsCharOrString)
                {
                    return;
                }
                _codeArea.InsertText(caretPos, "}");
                break;

            case '[':
                if (charNextIsCharOrString)
                {
                    return;
                }
                _codeArea.InsertText(caretPos, "]");
                break;

            case '"':
                // 0x22 = "
                if (charPrev == 0x22 && charNext == 0x22)
                {
                    _codeArea.DeleteRange(caretPos, 1);
                    _codeArea.GotoPosition(caretPos);
                    return;
                }

                if (isCharOrString)
                {
                    _codeArea.InsertText(caretPos, "\"");
                }
                break;

            case '\'':
                // 0x27 = '
                if (charPrev == 0x27 && charNext == 0x27)
                {
                    _codeArea.DeleteRange(caretPos, 1);
                    _codeArea.GotoPosition(caretPos);
                    return;
                }

                if (isCharOrString)
                {
                    _codeArea.InsertText(caretPos, "'");
                }
                break;
            }
        }