From 4c7791105eeff60d7c716d667bd3798bb764a3a3 Mon Sep 17 00:00:00 2001 From: Nicolas Bros Date: Fri, 28 Oct 2011 14:17:22 -0700 Subject: bug 356283: Preview scrollbar jumps to beginning of document when saving https://bugs.eclipse.org/bugs/show_bug.cgi?id=356283 apply patch that maintains the current scroll position--- .../internal/wikitext/ui/editor/MarkupEditor.java | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java index 60bbbbcee..5b45d8edd 100644 --- a/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java +++ b/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 David Green and others. + * Copyright (c) 2007, 2011 David Green and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -129,6 +129,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage; * content assist, validation, and cheat-sheet help content. * * @author David Green + * @author Nicolas Bros */ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSource, CommandManager { private static final String RULER_CONTEXT_MENU_ID = "org.eclipse.mylyn.internal.wikitext.ui.editor.MarkupEditor.ruler"; //$NON-NLS-1$ @@ -289,7 +290,7 @@ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSo public void widgetSelected(SelectionEvent selectionevent) { if (isShowingPreview()) { - updatePreview(getNearestMatchingOutlineItem()); + updatePreview(); } } }); @@ -506,7 +507,7 @@ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSo } scheduleOutlineUpdate(); if (isShowingPreview()) { - updatePreview(null); + updatePreview(); } } @@ -530,9 +531,15 @@ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSo } } - private void updatePreview(final OutlineItem item) { - boolean revealItem = item != null; + private static final String JAVASCRIPT_GETSCROLLTOP = "function getScrollTop() { " //$NON-NLS-1$ + + " if(typeof pageYOffset!='undefined') return pageYOffset;" //$NON-NLS-1$ + + " else{var B=document.body;var D=document.documentElement;D=(D.clientHeight)?D:B;return D.scrollTop;}" //$NON-NLS-1$ + + "}; return getScrollTop();"; //$NON-NLS-1$ + + private void updatePreview() { if (previewDirty && browser != null) { + Object result = browser.evaluate(JAVASCRIPT_GETSCROLLTOP); + final int verticalScrollbarPos = result != null ? ((Double) result).intValue() : 0; String xhtml = null; if (document == null) { xhtml = ""; //$NON-NLS-1$ @@ -606,22 +613,16 @@ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSo xhtml = documentWriter.toString(); } } - if (revealItem) { - revealItem = false; - browser.addProgressListener(new ProgressAdapter() { - @Override - public void completed(ProgressEvent event) { - browser.removeProgressListener(this); - revealInBrowser(item); - } - }); - } + browser.addProgressListener(new ProgressAdapter() { + @Override + public void completed(ProgressEvent event) { + browser.removeProgressListener(this); + browser.execute(String.format("window.scrollTo(0,%d);", verticalScrollbarPos)); //$NON-NLS-1$ + } + }); browser.setText(xhtml); previewDirty = false; } - if (revealItem) { - revealInBrowser(item); - } } public IFile getFile() { -- cgit v1.2.3