Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
guanglinn committed Sep 4, 2024
1 parent b03e0b8 commit 7ec4056
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
13 changes: 3 additions & 10 deletions app/src/main/assets/scroll-sync/scroll-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ function edit2Preview(lineNumber) {

/**
* Find the target line number, that is the value of data-line attribute of target element (generally the first visible element).
* Params: lineNumber - as a base position.
* Return: 0 if the line number found is around lineNumber (it means there is no need to adjust scrolling for this minor change),
* -1 if the target element cannot not be found.
* Return: -1 if the target element cannot not be found.
*/
function preview2Edit(lineNumber) {
function preview2Edit() {
const elements = document.querySelectorAll("[data-line]");
if (elements == null || elements.length == 0) {
return -1;
Expand All @@ -59,12 +57,7 @@ function preview2Edit(lineNumber) {
const top = element.getBoundingClientRect().top;
const bottom = element.getBoundingClientRect().bottom;
if (top > TOP_MARGIN && bottom > 0 && bottom < BOTTOM_MARGIN) {
const number = parseInt(element.getAttribute("data-line"));
if (number > lineNumber - 3 && number < lineNumber + 3) {
return 0;
} else {
return number;
}
return parseInt(element.getAttribute("data-line"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,12 +875,11 @@ public void setViewModeVisibility(boolean show, final boolean animate) {
_webView.requestFocus();
GsContextUtils.fadeInOut(_webView, _primaryScrollView, animate);
} else {
// _webViewClient.setRestoreScrollY(_webView.getScrollY());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
_webView.evaluateJavascript("preview2Edit(" + _firstVisibleLineNumber + ");", result -> {
_webView.evaluateJavascript("preview2Edit();", result -> {
if (Character.isDigit(result.charAt(0))) {
final int lineNumber = Integer.parseInt(result);
if (lineNumber > 0) {
if (lineNumber > 0 && (lineNumber < _firstVisibleLineNumber - 2 || lineNumber > _firstVisibleLineNumber + 2)) {
TextViewUtils.selectLines(_hlEditor, false, Collections.singletonList(lineNumber));
}
}
Expand All @@ -889,8 +888,8 @@ public void setViewModeVisibility(boolean show, final boolean animate) {
_hlEditor.requestFocus();
GsContextUtils.fadeInOut(_primaryScrollView, _webView, animate);
}
_nextConvertToPrintMode = false;
_isPreviewVisible = show;
_nextConvertToPrintMode = false;
((AppCompatActivity) activity).supportInvalidateOptionsMenu();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ public void runSpecialKeyAction() {
public void runJumpBottomTopAction(ActionItem.DisplayMode displayMode) {
if (displayMode == ActionItem.DisplayMode.EDIT) {
final int pos = _hlEditor.getSelectionStart();
if (pos == 0) {
if (pos < 1) {
_hlEditor.setSelection(_hlEditor.getText().length());
} else if (pos == _hlEditor.getText().length()) {
_hlEditor.setSelection(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ public <T extends GsContextUtils> T showSoftKeyboard(final Activity activity, fi
if (show) {
imm.showSoftInput(focus, InputMethodManager.SHOW_IMPLICIT);
} else if (token != null) {
imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.hideSoftInputFromWindow(token, 0);
}
}
}
Expand Down

0 comments on commit 7ec4056

Please sign in to comment.