Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ScintillaNET control from auto scrolling?

I am using a ScintillaNET control in my C# Winforms application. I am trying to implement an auto-tag feature that will auto-complete the tag before, for example, when a user types <html>, auto-complete feature will trigger and insert </html>.

I'm using the ScintillaNET CharAdded function for this implementation:

if (caretPos != 0)
        {
            //If the characters before the caret are "ml>" (last three chars from "<html>")
            if (TextArea.Text[caretPos - 1] == '>' && TextArea.Text[caretPos - 2] == 'l' && TextArea.Text[caretPos - 3] == 'm')
            {
                TextArea.Text = TextArea.Text.Insert(caretPos, "</html>");
                TextArea.SelectionStart = caretPos + 0;
                TextArea.Selections.First();
                TextArea.ScrollCaret();
            }
        }

Problem

My problem is, the Scintilla control keeps scrolling either all the way up or all the way down. I thought the ScrollCaret() function would work, but it keeps happening. Any ideas?

like image 242
Kirtstar web Avatar asked Jun 11 '20 10:06

Kirtstar web


1 Answers

I've struggled with this problem too. Thought it was a bug. Even the solutions given on the Github issues page didn't help. But then i found out that if you insert a text using:

TextArea.Text = TextArea.Text.Insert(caretPos, "");

Then that itself will be the problem. ScintillaNET already has a function for Text.Insert. Using InsertText will prevent the control from scrolling.

EDIT

Found the problem also issued here

like image 55
ROUBINSKI Avatar answered Oct 15 '22 18:10

ROUBINSKI