-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextConsoleViewer Scrolling #719
Open
sagarrohat
wants to merge
1
commit into
eclipse-platform:master
Choose a base branch
from
sagarrohat:TextConsoleViewer_Scrolling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
|
@@ -63,6 +62,7 @@ | |
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Listener; | ||
import org.eclipse.swt.widgets.ScrollBar; | ||
import org.eclipse.ui.internal.console.ConsoleDocumentAdapter; | ||
import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition; | ||
import org.eclipse.ui.progress.WorkbenchJob; | ||
|
@@ -124,10 +124,7 @@ public void documentChanged(DocumentEvent event) { | |
} | ||
}; | ||
|
||
// to store to user scroll lock action | ||
private final AtomicBoolean userHoldsScrollLock = new AtomicBoolean(false); | ||
|
||
WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {//$NON-NLS-1$ | ||
WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") { //$NON-NLS-1$ | ||
@Override | ||
public IStatus runInUIThread(IProgressMonitor monitor) { | ||
scrollToEndOfDocument(); | ||
|
@@ -147,51 +144,41 @@ private void scrollToEndOfDocument() { | |
|
||
// set the scroll Lock setting for Console Viewer and Console View | ||
private void setScrollLock(boolean lock) { | ||
userHoldsScrollLock.set(lock); | ||
if (scrollLockStateProvider != null && scrollLockStateProvider.getAutoScrollLock() != lock) { | ||
scrollLockStateProvider.setAutoScrollLock(lock); | ||
} | ||
} | ||
|
||
/* | ||
* Checks if at the end of document | ||
* Checks if last visible line is same as line count, implying end of the | ||
* document. | ||
*/ | ||
private boolean checkEndOfDocument() { | ||
private boolean isAtEndOfDocument() { | ||
StyledText textWidget = getTextWidget(); | ||
if (textWidget != null && !textWidget.isDisposed()) { | ||
int partialBottomIndex = JFaceTextUtil.getPartialBottomIndex(textWidget); | ||
int lastVisibleLineIndex = JFaceTextUtil.getPartialBottomIndex(textWidget); | ||
int lineCount = textWidget.getLineCount(); | ||
int delta = textWidget.getVerticalBar().getIncrement(); | ||
return lineCount - partialBottomIndex < delta; | ||
return lineCount == lastVisibleLineIndex + 1; | ||
} | ||
return false; | ||
} | ||
|
||
/* | ||
* Check if user preference is enabled for auto scroll lock and the document is empty or the line count is smaller than each | ||
* vertical scroll | ||
* Checks if user preference is enabled for auto scroll lock. and if the view is | ||
* empty or the content is minimal, implying no need for scrolling. | ||
*/ | ||
private boolean isAutoScrollLockNotApplicable() { | ||
if (!consoleAutoScrollLock) { | ||
return true; | ||
} | ||
StyledText textWidget = getTextWidget(); | ||
if (textWidget != null && !textWidget.isDisposed()) { | ||
return (textWidget.getLineCount() <= textWidget.getVerticalBar().getIncrement()); | ||
} | ||
return false; | ||
} | ||
|
||
/* | ||
* Checks if at the start of document | ||
*/ | ||
private boolean checkStartOfDocument() { | ||
StyledText textWidget = getTextWidget(); | ||
if (textWidget != null && !textWidget.isDisposed()) { | ||
int partialTopIndex = JFaceTextUtil.getPartialTopIndex(textWidget); | ||
int lineCount = textWidget.getLineCount(); | ||
int delta = textWidget.getVerticalBar().getIncrement(); | ||
return lineCount - partialTopIndex < delta; | ||
ScrollBar scrollBar = textWidget.getVerticalBar(); | ||
/** | ||
* Value for pageIncrement is only set when lines exceed one page, otherwise it | ||
* is 1 | ||
*/ | ||
return scrollBar.getPageIncrement() == 1; | ||
} | ||
return false; | ||
} | ||
|
@@ -253,30 +240,30 @@ public TextConsoleViewer(Composite parent, TextConsole console) { | |
styledText.addListener(SWT.MouseUp, mouseUpListener); | ||
// event listener used to send event to vertical scroll bar | ||
styledText.getVerticalBar().addSelectionListener(new SelectionAdapter() { | ||
|
||
@Override | ||
public void widgetSelected(SelectionEvent e) { | ||
if (isAutoScrollLockNotApplicable()) { | ||
return; | ||
} | ||
// scroll lock if vertical scroll bar dragged, OR selection on | ||
// vertical bar used | ||
if (e.detail == SWT.TOP || e.detail == SWT.HOME) { | ||
if (e.detail == SWT.HOME || e.detail == SWT.TOP) { | ||
// selecting TOP or HOME should lock | ||
setScrollLock(true); | ||
} | ||
if (e.detail == SWT.ARROW_UP || e.detail == SWT.PAGE_UP) { | ||
} else if (e.detail == SWT.PAGE_UP || e.detail == SWT.ARROW_UP) { | ||
setScrollLock(true); | ||
} else if (e.detail == SWT.END || e.detail == SWT.BOTTOM) { | ||
// selecting BOTTOM or END from vertical scroll makes it | ||
// reveal the end | ||
setScrollLock(false); | ||
} else if (e.detail == SWT.DRAG) { | ||
if (checkEndOfDocument()) { | ||
if (isAtEndOfDocument()) { | ||
setScrollLock(false); | ||
} else { | ||
setScrollLock(true); | ||
} | ||
} else if ((e.detail == SWT.PAGE_DOWN || e.detail == SWT.ARROW_DOWN) && checkEndOfDocument()) { | ||
} else if ((e.detail == SWT.PAGE_DOWN || e.detail == SWT.ARROW_DOWN) && isAtEndOfDocument()) { | ||
// unlock if Down at the end of document | ||
setScrollLock(false); | ||
} | ||
|
@@ -291,12 +278,12 @@ public void keyPressed(KeyEvent e) { | |
// lock the scroll if PAGE_UP ,HOME or TOP selected | ||
if (e.keyCode == SWT.HOME || e.keyCode == SWT.TOP) { | ||
setScrollLock(true); | ||
} else if ((e.keyCode == SWT.PAGE_UP || e.keyCode == SWT.ARROW_UP) && !checkStartOfDocument()) { | ||
} else if ((e.keyCode == SWT.PAGE_UP || e.keyCode == SWT.ARROW_UP)) { | ||
setScrollLock(true); | ||
} else if ((e.keyCode == SWT.END && (e.stateMask & SWT.CTRL) != 0) || e.keyCode == SWT.BOTTOM) { | ||
// pressing CTRL+END reveals the end | ||
setScrollLock(false); | ||
} else if ((e.keyCode == SWT.PAGE_DOWN || e.keyCode == SWT.ARROW_DOWN) && checkEndOfDocument()) { | ||
} else if ((e.keyCode == SWT.PAGE_DOWN || e.keyCode == SWT.ARROW_DOWN) && isAtEndOfDocument()) { | ||
// unlock if Down at the end of document | ||
setScrollLock(false); | ||
} | ||
|
@@ -306,11 +293,13 @@ public void keyPressed(KeyEvent e) { | |
if (isAutoScrollLockNotApplicable()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could rewrite this whole lambda like this: if (isAuto... || e.count == 0) {
return;
}
setScrollLock(e.count > 0 || !isAtEndOfDocument()); |
||
return; | ||
} | ||
if (e.count < 0) { // Mouse dragged down | ||
if (checkEndOfDocument()) { | ||
if (e.count < 0) { // Mouse scroll down | ||
if (isAtEndOfDocument()) { | ||
setScrollLock(false); | ||
} else { | ||
setScrollLock(true); | ||
} | ||
} else if (!userHoldsScrollLock.get()) { | ||
} else if (e.count > 0) { // Mouse scroll up | ||
setScrollLock(true); | ||
} | ||
}); | ||
|
@@ -331,6 +320,7 @@ public void keyPressed(KeyEvent e) { | |
document.addPositionUpdater(positionUpdater); | ||
} | ||
|
||
|
||
/** | ||
* Sets the tab width used by this viewer. | ||
* | ||
|
@@ -854,4 +844,4 @@ protected void internalRevealRange(int start, int end) { | |
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.