public void AddToPanel(Scintilla editor, Scintilla resultsPanel)
        {
            resultsPanel.ClearAll();

            var indicator = resultsPanel.Indicators[16];

            indicator.ForeColor           = Color.Red;
            indicator.Alpha               = 100;
            indicator.Style               = IndicatorStyle.RoundBox;
            indicator.Under               = true;
            resultsPanel.IndicatorCurrent = indicator.Index;

            //Write lines
            foreach (var item in this.Items)
            {
                var startLine = editor.LineFromPosition(item.cpMin);
                var endLine   = editor.LineFromPosition(item.cpMax);

                if (startLine == endLine)
                {
                    var resultsLinePrefix = $"Line {startLine + 1}: ";

                    resultsPanel.AppendText($"{resultsLinePrefix}{editor.Lines[startLine].Text}");
                }
            }

            //Highlight
            var resultLineIndex = 0;

            foreach (var item in this.Items)
            {
                var startLine = editor.LineFromPosition(item.cpMin);
                var endLine   = editor.LineFromPosition(item.cpMax);

                if (startLine == endLine)
                {
                    var resultsLinePrefix = $"Line {startLine + 1}: ";

                    var linePos        = editor.Lines[startLine].Position;
                    var startPosInLine = item.cpMin - linePos;

                    var lastLineStartPos = resultsPanel.Lines[resultLineIndex].Position;

                    resultsPanel.IndicatorFillRange(lastLineStartPos + resultsLinePrefix.Length + startPosInLine, item.cpMax - item.cpMin);

                    resultLineIndex++;
                }
            }
        }
Example #2
0
        private Scintilla NewScintilla(string Language, string text)
        {
            Scintilla Myediter;

            Myediter = new Scintilla();
            Myediter.Margins.Margin1.Width         = 1;
            Myediter.Margins.Margin0.Type          = MarginType.Number;
            Myediter.Margins.Margin0.Width         = 0x23;
            Myediter.ConfigurationManager.Language = Language;
            Myediter.Dock = DockStyle.Fill;
            Myediter.Scrolling.ScrollBars = ScrollBars.Both;
            Myediter.ConfigurationManager.IsBuiltInEnabled = true;
            Myediter.AppendText(text);
            Myediter.UndoRedo.EmptyUndoBuffer();
            return(Myediter);
        }
Example #3
0
        /// <summary>Scintilla Examples</summary>
        /// <param name="sci">Scintilla Control Name</param>
        public void Scintilla_TextModExamples(Scintilla sci)
        {
            sci.Text = "Hello";
            sci.AppendText(" World");     // 'Hello' -> 'Hello World'
            sci.DeleteRange(0, 5);        // 'Hello World' -> ' World'
            sci.InsertText(0, "Goodbye"); // ' World' -> 'Goodbye World'

            // Get the first 256 characters of the document
            var text = sci.GetTextRange(0, Math.Min(256, sci.TextLength));

            Console.WriteLine(text);

            sci.HideLines(3, 12);  // hide lines

            // find and replace plugin
            //https://github.com/Stumpii/ScintillaNET-FindReplaceDialog
        }
Example #4
0
        public void AddToPanel(Scintilla editor, Scintilla resultsPanel)
        {
            resultsPanel.ClearAll();
            foreach (var item in this.Items)
            {
                resultsPanel.AppendText($"Ln {item.LineNumber}, Col {item.LinePosition}: {item.Message}\n");
            }

            if (this.Items.Count == 1)
            {
                // Go to that single line immediately

                // There is a chance that the following happens:
                // - The panel is initially hidden
                // - The line to be selected is below the visible region of the editor
                // - The line gets selected before the panel is shown
                // - When shown, the panel hides the line
                // To prevent this from happening, we introduce a small delay to give the editor time to show the panel
                // TODO: Find a more robust way to achieve the same effect

                Task.Delay(100).ContinueWith(t => Application.Current.Dispatcher?.Invoke(() => this.GoToPosition(1, editor, resultsPanel)), TaskScheduler.Current);
            }
        }