Skip to content

Commit

Permalink
Improve logic for auto-enable/-disable of scroll lock in TextConsoleV…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohat Sonu committed Sep 21, 2023
1 parent ca5ea10 commit b93c27c
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,35 @@ private void setScrollLock(boolean 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 isAtEndOfDocument() {
StyledText textWidget = getTextWidget();
if (textWidget != null && !textWidget.isDisposed()) {
ScrollBar scrollBar = textWidget.getVerticalBar();
int linesInAPage = scrollBar.getPageIncrement() / scrollBar.getIncrement();
int partialBottomIndex = JFaceTextUtil.getPartialBottomIndex(textWidget);
return textWidget.getLineCount() - partialBottomIndex <= linesInAPage;
int lastVisibleLineIndex = JFaceTextUtil.getPartialBottomIndex(textWidget);
int lineCount = textWidget.getLineCount();
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());
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;
}
Expand Down Expand Up @@ -315,6 +320,7 @@ public void keyPressed(KeyEvent e) {
document.addPositionUpdater(positionUpdater);
}


/**
* Sets the tab width used by this viewer.
*
Expand Down

0 comments on commit b93c27c

Please sign in to comment.