summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Bros2011-10-28 17:17:22 (EDT)
committerDavid Green2011-10-28 17:17:22 (EDT)
commit4c7791105eeff60d7c716d667bd3798bb764a3a3 (patch)
treeeb9b0616cd24b0d1411b204a6861824ae90cc635
parentc601c9943bf8fa0a7275fd9323fcd0c2e5b1a4c7 (diff)
downloadorg.eclipse.mylyn.docs-4c7791105eeff60d7c716d667bd3798bb764a3a3.zip
org.eclipse.mylyn.docs-4c7791105eeff60d7c716d667bd3798bb764a3a3.tar.gz
org.eclipse.mylyn.docs-4c7791105eeff60d7c716d667bd3798bb764a3a3.tar.bz2
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
-rw-r--r--org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java37
1 files 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 60bbbbc..5b45d8e 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 = "<?xml version=\"1.0\" ?><html xmlns=\"http://www.w3.org/1999/xhtml\"><body></body></html>"; //$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() {