Exemple #1
0
        private void scintillaControl_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                //var curLine = scintilla1.LineFromPosition(e.Position);
                //var curLineText = scintilla1.Lines[curLine].Text;

                //var indent = Regex.Match(curLineText, @"^\s*");
                //e.Text += indent.Value; // Add indent following "\r\n"

                // Current line end with bracket?
                //if (Regex.IsMatch(curLineText, @"{\s*$"))
                //    e.Text += '\t'; // Add tab

                int indent   = _scintillaControl.zGetLineIndent(_scintillaControl.zGetCurrentLineNumber());
                int position = _scintillaControl.CurrentPosition - 1;
                if (position >= 0)
                {
                    char c = (char)_scintillaControl.GetCharAt(position);
                    if (c == '{')
                    {
                        indent += _tabWidth;
                    }
                }
                e.Text += new string(' ', indent); // Add indent following "\r\n"
            }
        }
        private static void ScintillaNet_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            DocumentView documentView = ((MainWindow)App.Current.MainWindow).ActiveDocument;

            if (documentView == null)
            {
                return;
            }

            ScintillaNET.WPF.ScintillaWPF scintilla = documentView.scintilla;
            var currentPos = scintilla.CurrentPosition;

            if (e.Text == "\u0013")
            {
                e.Text = string.Empty;
                return;
            }

            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine     = scintilla.LineFromPosition(e.Position);
                var curLineText = scintilla.Lines[curLine].Text.Replace("\r", "").Replace("\n", "");

                var indent = Regex.Match(curLineText, @"^\s*");
                e.Text += indent.Value;

                if (Regex.IsMatch(curLineText, @"{\s*$"))
                {
                    e.Text += '\t';
                }
            }
        }
Exemple #3
0
        // Identation
        private void mainEditor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine     = mainEditor.LineFromPosition(e.Position);
                var curLineText = mainEditor.Lines[curLine].Text;

                var indent = Regex.Match(curLineText, @"^[ \t]*");
                e.Text += indent.Value; // Add indent following "\r\n".

                // Current line end with bracket?
                if (selectedLanguage.Text == "C#" || selectedLanguage.Text == "C" || selectedLanguage.Text == "C++" || selectedLanguage.Text == "CSS" || selectedLanguage.Text == "Javascript")
                {
                    if (Regex.IsMatch(curLineText, @"{\s*$")) // {
                    {
                        e.Text += '\t';                       // Add tab.
                    }
                }
                else if (selectedLanguage.Text == "Python 2" || selectedLanguage.Text == "Python 3")
                {
                    if (Regex.IsMatch(curLineText, @":\s*$")) // :
                    {
                        e.Text += '\t';                       // Add tab.
                    }
                }
                else if (selectedLanguage.Text == "HTML")
                {
                    if (Regex.IsMatch(curLineText, @">\s*$")) // <
                    {
                        e.Text += '\t';                       // Add tab.
                    }
                }
            }
        }
        private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\n") || e.Text.EndsWith("\r")))
            {
                //Text until the caret so that the whitespace is always equal in every line.
                string curLineText    = GetCurrentLineText(e.Position);
                Match  curIndentMatch = Regex.Match(curLineText, "^[ \\t]*");
                string curIndent      = curIndentMatch.Value;

                var cline = curLineText
                            .ToLower()
                            .Replace("\r", "")
                            .Replace("\n", "")
                            .Trim();

                e.Text = (e.Text + curIndent);

                if (cline.StartsWith("function") ||
                    cline.EndsWith("do") ||
                    cline.EndsWith("then") ||
                    cline.EndsWith("else") ||
                    Regex.IsMatch(curLineText, "{\\s*$"))
                {
                    e.Text = (e.Text + @"    "); // 4 spaces
                }
            }
        }
Exemple #5
0
        private void textBox_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            var text = e.Text;

            // Replace tabs with 3 spaces.
            text = text.Replace("\t", "   ");

            // Auto indent.
            if (text == "\r\n")
            {
                var curLine     = textBox.LineFromPosition(e.Position);
                var curLineText = textBox.Lines[curLine].Text;

                // Copy last line's indent.
                var indent = Regex.Match(curLineText, @"^[ \t]*");
                text += indent.Value;

                // For JSON, add one level of indent if the line ends with a bracket.
                if (textBox.Lexer == ScintillaNET.Lexer.Json && Regex.IsMatch(curLineText, @"[\[\{]\s*$"))
                {
                    text += "   ";
                }
            }

            // Return the modified text.
            e.Text = text;
        }
Exemple #6
0
 private void OnInsertCheck(object sender, InsertCheckEventArgs e)
 {
     if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
     {
         string         fragment    = this.Text.Substring(0, this.CurrentPosition);
         XmlDepthFinder depthfinder = new XmlDepthFinder();
         int            tabs        = depthfinder.GetDepth(fragment);
         e.Text += new string('\t', tabs);
     }
 }
Exemple #7
0
        private void scintilla1_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            bool   removed = false;
            string text    = e.Text;

            // remove ctrl-B code 0x02
            if (e.Text == "\u0002")
            {
                e.Text  = null;
                removed = true;
            }
            WriteMessage("insert \"{0}\" code {1}{2}", text, (int)text[0], removed ? " removed" : "");
        }
Exemple #8
0
        private void mScriptEditor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (!e.Text.EndsWith("\r") && !e.Text.EndsWith("\n"))
            {
                return;
            }

            int    curLine     = mScriptEditor.LineFromPosition(e.Position);
            string curLineText = mScriptEditor.Lines[curLine].Text;

            Match indent = Regex.Match(curLineText, @"^\s*");

            e.Text += indent.Value; // Add indent following "\r\n"
        }
 private void SingularityScintilla_InsertCheck(object sender, InsertCheckEventArgs e)
 {
     if (!Multiline)
     {
         e.Text = Regex.Replace(e.Text, @"\r\n?|\n", " ");
     }
     if (DisallowedChars != null)
     {
         foreach (char ch in DisallowedChars)
         {
             e.Text = e.Text.Replace(ch.ToString(), "");
         }
     }
 }
Exemple #10
0
        private void TxtEditor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine = this.txtEditor.LineFromPosition(e.Position);
                var curLineText = this.txtEditor.Lines[curLine].Text;

                var indent = Regex.Match(curLineText, @"^\s*");
                string txt = indent.Value.Replace("\r", "").Replace("\n", "");
                e.Text += txt;// Add indent following "\r\n"

                // Current line end with bracket?
                if (Regex.IsMatch(curLineText, @":\s*$") || this.txtEditor.GetCharAt(this.txtEditor.CurrentPosition - 1) == ':')
                    e.Text += '\t'; // Add tab
            }
        }
        private void codeBox_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (e.Text.EndsWith("\r") || e.Text.EndsWith("\n"))
            {
                int    startPos    = _codeBox.Lines[_codeBox.LineFromPosition(_codeBox.CurrentPosition)].Position;
                int    endPos      = e.Position;
                string curLineText = _codeBox.GetTextRange(startPos, (endPos - startPos));

                Match indent = Regex.Match(curLineText, "^[ \\t]*");
                e.Text = (e.Text + indent.Value);
                if (Regex.IsMatch(curLineText, "{\\s*$"))
                {
                    e.Text = (e.Text + "\t");
                }
            }
        }
Exemple #12
0
        private void templateEditor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\n") || e.Text.EndsWith("\r")))
            {
                int    startPos    = templateEditor.Lines[templateEditor.LineFromPosition(templateEditor.CurrentPosition)].Position;
                int    endPos      = e.Position;
                string curLineText = templateEditor.GetTextRange(startPos, (endPos - startPos)); //Text until the caret so that the whitespace is always equal in every line.

                Match indent = Regex.Match(curLineText, "^[ \\t]*");
                e.Text = (e.Text + indent.Value);
                if (Regex.IsMatch(curLineText, "{\\s*$"))
                {
                    e.Text = (e.Text + "    ");
                }
            }
        }
Exemple #13
0
        private void scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine     = scintilla.LineFromPosition(e.Position);
                var curLineText = scintilla.Lines[curLine].Text;

                var indent = Regex.Match(curLineText, @"^\s*");
                e.Text += indent.Value; // Add indent following "\r\n"

                // Current line end with bracket?
                if (Regex.IsMatch(curLineText, @"{\s*$"))
                {
                    e.Text += '\t'; // Add tab
                }
            }
        }
Exemple #14
0
        private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\n") || e.Text.EndsWith("\r")))
            {
                //Text until the caret so that the whitespace is always equal in every line.
                string curLineText    = GetCurrentLineText(e.Position);
                Match  curIndentMatch = Regex.Match(curLineText, "^[ \\t]*");
                string curIndent      = curIndentMatch.Value;

                e.Text = (e.Text + curIndent);

                if (Regex.IsMatch(curLineText, @"\[\s*$") ||
                    Regex.IsMatch(curLineText, @"{\s*$"))
                {
                    e.Text = (e.Text + "  ");
                }
            }
        }
        static private void editor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            Scintilla editor = (Scintilla)sender;

            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine     = editor.LineFromPosition(e.Position);
                var curLineText = editor.Lines[curLine].Text;

                var indent = System.Text.RegularExpressions.Regex.Match(curLineText, @"^\s*");
                e.Text += indent.Value; // Add indent following "\r\n"

                // Current line end with bracket?
                if (System.Text.RegularExpressions.Regex.IsMatch(curLineText, @"{\s*$"))
                {
                    e.Text += '\t'; // Add tab
                }
            }
        }
Exemple #16
0
        private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            // This (C): https://gist.github.com/Ahmad45123/f2910192987a73a52ab4
            var scintilla = (Scintilla)sender;

            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                int    startPos    = scintilla.Lines[scintilla.LineFromPosition(scintilla.CurrentPosition)].Position;
                int    endPos      = e.Position;
                string curLineText = scintilla.GetTextRange(startPos, (endPos - startPos)); //Text until the caret so that the whitespace is always equal in every line.

                Match indent = Regex.Match(curLineText, "^[ \\t]*");
                e.Text = (e.Text + indent.Value);
                if (Regex.IsMatch(curLineText, "{\\s*$"))
                {
                    e.Text = (e.Text + "\t");
                }
            }
        }
Exemple #17
0
        private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (e.Text.Length == 1)
            {
                var caretPos = Scintilla.CurrentPosition;
                var charNext = Scintilla.GetCharAt(caretPos);

                if (charNext == ')' && e.Text.ToLower() == ")" || charNext == '}' && e.Text.ToLower() == "}" ||
                    charNext == ']' && e.Text.ToLower() == "]")
                {
                    var shouldSkip = charNext == ')' ||
                                     charNext == '}' ||
                                     charNext == ']';

                    if (shouldSkip)
                    {
                        e.Text = "";
                        Scintilla.GotoPosition(Scintilla.CurrentPosition + 1);
                    }
                }
            }

            if (!e.Text.EndsWith("\r") && !e.Text.EndsWith("\n"))
            {
                return;
            }

            var line     = Scintilla.Lines[Scintilla.LineFromPosition(Scintilla.CurrentPosition)];
            var startPos = Scintilla.Lines[Scintilla.LineFromPosition(Scintilla.CurrentPosition)].Position;
            var endPos   = e.Position;

            var curLineText = Scintilla.GetTextRange(startPos, endPos - startPos);

            var indent = Regex.Match(curLineText, "^[ \\t]*");

            e.Text += indent.Value;

            if (Regex.IsMatch(curLineText, "{\\s*$") && !line.Text.Trim().EndsWith("}"))
            {
                e.Text += "\t";
            }
        }
Exemple #18
0
        //Auto Indent
        private void AutoIndent_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (_styler != null)
            {
                if (e.Text.EndsWith("\r") || e.Text.EndsWith("\n"))
                {
                    int    startPos    = Lines[LineFromPosition(CurrentPosition)].Position;
                    int    endPos      = e.Position;
                    string curLineText = GetTextRange(startPos, (endPos - startPos));
                    //Text until the caret so that the whitespace is always equal in every line.

                    Match indent = Regex.Match(curLineText, "^[ \\t]*");
                    e.Text = (e.Text + indent.Value);
                    if (Regex.IsMatch(curLineText, _styler.IndentChar + "\\s*$"))
                    {
                        e.Text = (e.Text + "    ");
                    }
                }
            }
        }
Exemple #19
0
        private void scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            Scintilla scintilla = sender as Scintilla;

            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                int    currLineIndex = scintilla.LineFromPosition(e.Position);
                Line   currLine      = scintilla.Lines[currLineIndex];
                string currLineText  = currLine.Text;

                Match indent = Regex.Match(currLineText, @"^\s*");

                int indentLen = e.Position - currLine.Position;
                if (indentLen > indent.Length)
                {
                    indentLen = indent.Length;
                }

                e.Text += indent.Value.Substring(0, indentLen);
            }
        }
Exemple #20
0
        private void Scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (!e.Text.EndsWith("\n"))
            {
                return;
            }

            var indent = luaEditor.Lines[luaEditor.CurrentLine].Indentation;
            var text   = Scintilla_TrimText(GetCurrentText(e.Position));

            if (text.StartsWith("function") ||
                text.StartsWith("local function") ||
                text.EndsWith("do") ||
                text.EndsWith("then") ||
                text.EndsWith("else") ||
                text == "repeat" ||
                Regex.IsMatch(text, "{\\s*$"))
            {
                indent += 4;
            }

            e.Text = e.Text + new string(' ', Math.Max(0, indent));
        }
Exemple #21
0
        //Auto-indent
        private void editor_InsertCheck(object sender, InsertCheckEventArgs e)
        {
            if ((e.Text.EndsWith("\r") || e.Text.EndsWith("\n")))
            {
                var curLine     = editor.LineFromPosition(e.Position);
                var curLineText = editor.Lines[curLine].Text;

                if (curLineText.Trim() == "")
                {
                    e.Text += curLineText.TrimEnd('\r', '\n');
                }
                else
                {
                    var indent = Regex.Match(curLineText, @"^\s*");
                    e.Text += indent.Value; // Add indent following "\r\n"

                    // Current line end with bracket?
                    if (Regex.IsMatch(curLineText, @"{\s*$"))
                    {
                        e.Text += "\t"; // Add tab
                    }
                }
            }
        }
        private void OnEditorInsertCheck(object sender, InsertCheckEventArgs e)
        {
            if (!Properties.Settings.Default.AutoIndent)
            {
                return;
            }

            if (!e.Text.EndsWith("\r") && !e.Text.EndsWith("\n"))
            {
                return;
            }

            var startPos    = this.Editor.Lines[this.Editor.LineFromPosition(this.Editor.CurrentPosition)].Position;
            var endPos      = e.Position;
            var curLineText = this.Editor.GetTextRange(startPos, endPos - startPos); // Text until the caret
            var indent      = Regex.Match(curLineText, "^[ \\t]*");

            e.Text += indent.Value;
            if (Regex.IsMatch(curLineText, "[^/]>\\s*$"))
            {
                // If the previous line finished with an open tag, add an indentation level to the next one
                e.Text += new string(' ', Properties.Settings.Default.TabWidth);
            }
        }
Exemple #23
0
 private void OnInsertCheck(object sender, InsertCheckEventArgs e)
 {
 }
Exemple #24
0
 //Validate the inserted characters for a given Scintilla TextArea control, before they're inserted.
 public static void ValidateInputCharacters(object sender, InsertCheckEventArgs e)
 {
     e.Text = RemoveControlCharacters(e.Text);
 }