From 7ec4056e1db8d5def40e8207ccf98a7d0cce351d Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Wed, 4 Sep 2024 15:48:04 +0800 Subject: [PATCH] minor improvements --- app/src/main/assets/scroll-sync/scroll-sync.js | 13 +++---------- .../activity/DocumentEditAndViewFragment.java | 7 +++---- .../gsantner/markor/format/ActionButtonBase.java | 2 +- .../java/net/gsantner/opoc/util/GsContextUtils.java | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/src/main/assets/scroll-sync/scroll-sync.js b/app/src/main/assets/scroll-sync/scroll-sync.js index 2ffafd3ee..e5a812a5a 100644 --- a/app/src/main/assets/scroll-sync/scroll-sync.js +++ b/app/src/main/assets/scroll-sync/scroll-sync.js @@ -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; @@ -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")); } } diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java index 5d3093619..f154544f2 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java @@ -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)); } } @@ -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(); } diff --git a/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java b/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java index 47d1c9430..dad792598 100644 --- a/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java +++ b/app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java @@ -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); diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java index ac7b188d4..e50cba848 100644 --- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java @@ -2537,7 +2537,7 @@ public 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); } } }