Caret position moves to the end while moving mouse

Apr 19, 2013 at 1:47 PM
Hallo
I have got a strange problem. When I type a text in the middle of the document and the mouse cursor is moving just a little bit, the caret always moves to the end of the document.
How can I prevent the caret from moving to the end of the document? No mouse clicks, just moving the mouse will occur this problem

I have tried a work around by capturing the caret position when typing. It works.
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern bool GetCaretPos(ref Point pt);
But I cannot set the caret at the last typing position. The curser remains at the end of the document.
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern int SetCaretPos(int x, int 
Oct 20, 2014 at 11:17 AM
Edited Oct 20, 2014 at 11:20 AM
In file HtmlEditor.xaml.cs replace
        private void NotifyBindingContentChanged()
        {
            if (myBindingContent != this.ContentHtml)
            {
                BindingContent = this.ContentHtml;
            }
        }
this
    private void NotifyBindingContentChanged()
        {
            if (myBindingContent != this.ContentHtml && !VisualEditor.Focused)
            {
                BindingContent = this.ContentHtml;
            }
        }
:)
Marked as answer by KPhoenix on 10/20/2014 at 5:05 AM
Oct 20, 2014 at 12:05 PM
It works. Thank you very very much :)
Nov 26, 2014 at 1:38 PM
Thanks again for your answer steryd.
This code leads to another problem. I can work with the editor and everything works fine until I want to change the font (bold, italic,...). In this case, the whole document is selected und everything is getting bold/italic..

If I open a html document and want to change the font of one selected word, it works very well.
But if I open a document and change something (insert blank, append a text), chaning font doesn't work. First, everything is getting selected and so every word is getting bold/italic.

Any idea?
Thanks
Stefan
Oct 30, 2015 at 11:32 AM
Edited Oct 30, 2015 at 11:38 AM
I always use shortkeys and I didn't notice the error.

You can try comment NotifyBindingContentChanged, but binding data will not work on two way. You can add button to change bindingcontent.
   private void NotifyBindingContentChanged()
        {
            //if (myBindingContent != this.ContentHtml && !VisualEditor.Focused)
            //{
            //    BindingContent = this.ContentHtml;
            //}
        }
and add to evry command executed method add
VisualEditor.Document.Focus();
        private void BoldExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (htmldoc != null)
            {
                htmldoc.Bold();
                VisualEditor.Document.Focus();
            }
        }

        private void ItalicExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (htmldoc != null)
            {
                htmldoc.Italic();
                VisualEditor.Document.Focus();
            }
        }

        private void UnderlineExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (htmldoc != null) 
            {
                htmldoc.Underline();
                VisualEditor.Document.Focus();
            }
        }