Example #1
0
        public void AddComment()
        {
            if (_editor.SelectedText == Environment.NewLine)
            {
                return;
            }
            int start     = _editor.SelectionStart;
            int end       = _editor.SelectionEnd;
            var lineStart = _editor.Lines.FirstOrDefault(
                x =>
            {
                return(x.Position <= start && x.EndPosition > start);
            });
            var lineEnd = _editor.Lines.FirstOrDefault(
                x =>
            {
                return(x.Position < end && x.EndPosition >= end);
            });

            if (lineStart == null || lineEnd == null)
            {
                return;
            }
            _editor.SetSelection(lineStart.Position, lineEnd.EndPosition);

            string textSelect = _editor.SelectedText;

            string[]          strsSplit  = System.Text.RegularExpressions.Regex.Split(textSelect, System.Environment.NewLine);
            Func <char, bool> funcSearch = x => { return(!(x == '\r' || x == '\n' || x == ' ')); };

            for (int i = 0; i < strsSplit.Length; i++)
            {
                if (strsSplit[i] == null || strsSplit[i].FirstOrDefault(funcSearch) == char.MinValue)
                {
                    continue;
                }
                strsSplit[i] = strsSplit[i].Insert(StringIndex(strsSplit[i], funcSearch), "--");
            }
            _editor.ReplaceSelection(string.Join(System.Environment.NewLine, strsSplit));
            _editor.SetSelection(lineStart.Position, lineEnd.EndPosition);
        }
Example #2
0
        public static void Find(bool next, bool incremental)
        {
            bool first = LastSearch != SearchBox.Text;

            LastSearch = SearchBox.Text;
            if (LastSearch.Length > 0)
            {
                if (next)
                {
                    // SEARCH FOR THE NEXT OCCURANCE

                    // Search the document at the last search index
                    TextArea.TargetStart = LastSearchIndex - 1;
                    TextArea.TargetEnd   = LastSearchIndex + (LastSearch.Length + 1);
                    TextArea.SearchFlags = ScintillaNET.SearchFlags.None;

                    // Search, and if not found..
                    if (!incremental || TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        // Search the document from the caret onwards
                        TextArea.TargetStart = TextArea.CurrentPosition;
                        TextArea.TargetEnd   = TextArea.TextLength;
                        TextArea.SearchFlags = ScintillaNET.SearchFlags.None;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(LastSearch) == -1)
                        {
                            // Search again from top
                            TextArea.TargetStart = 0;
                            TextArea.TargetEnd   = TextArea.TextLength;

                            // Search, and if not found..
                            if (TextArea.SearchInTarget(LastSearch) == -1)
                            {
                                // clear selection and exit
                                TextArea.ClearSelections();
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // SEARCH FOR THE PREVIOUS OCCURANCE

                    // Search the document from the beginning to the caret
                    TextArea.TargetStart = 0;
                    TextArea.TargetEnd   = TextArea.CurrentPosition;
                    TextArea.SearchFlags = ScintillaNET.SearchFlags.None;

                    // Search, and if not found..
                    if (TextArea.SearchInTarget(LastSearch) == -1)
                    {
                        // Search again from the caret onwards
                        TextArea.TargetStart = TextArea.CurrentPosition;
                        TextArea.TargetEnd   = TextArea.TextLength;

                        // Search, and if not found..
                        if (TextArea.SearchInTarget(LastSearch) == -1)
                        {
                            // clear selection and exit
                            TextArea.ClearSelections();
                            return;
                        }
                    }
                }

                // Select the occurance
                LastSearchIndex = TextArea.TargetStart;
                TextArea.SetSelection(TextArea.TargetEnd, TextArea.TargetStart);
                TextArea.ScrollCaret();
            }

            SearchBox.Focus();
        }