예제 #1
0
        /// <summary>
        /// Reverses the change, addition or deletion of a line of text in the page
        /// </summary>
        /// <param name="changeType"></param>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private void UndoChangeGeneric(DiffChangeMode changeType, int left, int right)
        {
            if (!txtEdit.Enabled)
                return;

            try
            {
                int caretPosition = txtEdit.SelectionStart;
                GetDiff(); // to pick up any manual changes from edit box

                switch (changeType)
                {
                    case DiffChangeMode.Change:
                        txtEdit.Text = Diff.UndoChange(left, right);
                        break;
                    case DiffChangeMode.Deletion:
                        txtEdit.Text = Diff.UndoDeletion(left, right);
                        break;
                    case DiffChangeMode.Addition:
                        txtEdit.Text = Diff.UndoAddition(right);
                        break;
                }

                GetDiff();

                // now put caret back where it was
                txtEdit.Select(Math.Min(caretPosition, txtEdit.Text.Length), 0);
                txtEdit.ScrollToCaret();
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Reverses the change, addition or deletion of a line of text in the page
        /// </summary>
        /// <param name="changeType"></param>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private void UndoChangeGeneric(DiffChangeMode changeType, int left, int right)
        {
            if (!txtEdit.Enabled)
                return;

            try
            {
                int caretPosition = txtEdit.SelectionStart;
                // see http://stackoverflow.com/questions/1277691/how-to-retrieve-the-scrollbar-position-of-the-webbrowser-control-in-net
                int webBrowserYScroll = webBrowser.Document.GetElementsByTagName("HTML")[0].ScrollTop;
                GetDiff(); // to pick up any manual changes from edit box

                switch (changeType)
                {
                    case DiffChangeMode.Change:
                        txtEdit.Text = Diff.UndoChange(left, right);
                        break;
                    case DiffChangeMode.Deletion:
                        txtEdit.Text = Diff.UndoDeletion(left, right);
                        break;
                    case DiffChangeMode.Addition:
                        txtEdit.Text = Diff.UndoAddition(right);
                        break;
                }

                GetDiff();

                // scroll back to where user was
                object[] ob = {"window.scrollTo(0, " + webBrowserYScroll.ToString() + @")"};
                webBrowser.Document.InvokeScript("eval", ob);

                // now put caret back where it was
                txtEdit.Select(Math.Min(caretPosition, txtEdit.Text.Length), 0);
                txtEdit.ScrollToCaret();
            }
            catch (Exception ex)
            {
                ErrorHandler.HandleException(ex);
            }
        }