From 2c02ec3911d61f9619b4321e4138ee1bc301bbd2 Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Sun, 4 Aug 2024 16:51:53 +0800 Subject: [PATCH 1/8] improve history scroll restoration for HeadlineDialog --- .../markdown/MarkdownActionButtons.java | 3 ++- .../wikitext/WikitextActionButtons.java | 3 ++- .../markor/frontend/MarkorDialogFactory.java | 19 +++---------------- .../frontend/GsSearchOrCustomTextDialog.java | 2 ++ 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownActionButtons.java b/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownActionButtons.java index 65c257b1bb..b7eb0a0bd2 100644 --- a/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownActionButtons.java +++ b/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownActionButtons.java @@ -22,6 +22,7 @@ import net.gsantner.markor.frontend.textview.AutoTextFormatter; import net.gsantner.markor.frontend.textview.TextViewUtils; import net.gsantner.markor.model.Document; +import net.gsantner.opoc.frontend.GsSearchOrCustomTextDialog; import net.gsantner.opoc.util.GsContextUtils; import net.gsantner.opoc.util.GsFileUtils; @@ -35,7 +36,7 @@ public class MarkdownActionButtons extends ActionButtonBase { private static final Pattern WEB_URL = Pattern.compile("https?://[^\\s/$.?#].[^\\s]*"); - private final MarkorDialogFactory.HeadlineDialogState _headlineDialogState = new MarkorDialogFactory.HeadlineDialogState(); + private final GsSearchOrCustomTextDialog.DialogState _headlineDialogState = new GsSearchOrCustomTextDialog.DialogState(); public static final String LINE_PREFIX = "^(>\\s|#{1,6}\\s|\\s*[-*+](?:\\s\\[[ xX]\\])?\\s|\\s*\\d+[.)]\\s)?"; diff --git a/app/src/main/java/net/gsantner/markor/format/wikitext/WikitextActionButtons.java b/app/src/main/java/net/gsantner/markor/format/wikitext/WikitextActionButtons.java index f5a6bff117..2eea811951 100644 --- a/app/src/main/java/net/gsantner/markor/format/wikitext/WikitextActionButtons.java +++ b/app/src/main/java/net/gsantner/markor/format/wikitext/WikitextActionButtons.java @@ -20,6 +20,7 @@ import net.gsantner.markor.frontend.textview.AutoTextFormatter; import net.gsantner.markor.frontend.textview.TextViewUtils; import net.gsantner.markor.model.Document; +import net.gsantner.opoc.frontend.GsSearchOrCustomTextDialog; import java.io.File; import java.text.SimpleDateFormat; @@ -31,7 +32,7 @@ public class WikitextActionButtons extends ActionButtonBase { - private MarkorDialogFactory.HeadlineDialogState _headlineDialogState = new MarkorDialogFactory.HeadlineDialogState(); + private GsSearchOrCustomTextDialog.DialogState _headlineDialogState = new GsSearchOrCustomTextDialog.DialogState(); public WikitextActionButtons(@NonNull Context context, Document document) { super(context, document); diff --git a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java index 3607d122e9..e098c10852 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java @@ -38,7 +38,6 @@ import net.gsantner.markor.ApplicationObject; import net.gsantner.markor.R; -import net.gsantner.markor.format.markdown.MarkdownTextConverter; import net.gsantner.markor.format.todotxt.TodoTxtBasicSyntaxHighlighter; import net.gsantner.markor.format.todotxt.TodoTxtFilter; import net.gsantner.markor.format.todotxt.TodoTxtTask; @@ -789,12 +788,6 @@ private static class Heading { } } - public static class HeadlineDialogState { - public Set disabledLevels = new HashSet<>(); - public String searchQuery = ""; - public int listPosition = -1; - } - /** * Show a dialog to select a heading * @@ -808,7 +801,7 @@ public static void showHeadlineDialog( final Activity activity, final EditText edit, final WebView webView, - final HeadlineDialogState state, + final GsSearchOrCustomTextDialog.DialogState state, final GsCallback.r3 levelCallback ) { // Get all headings and their levels @@ -836,7 +829,6 @@ public static void showHeadlineDialog( dopt.searchHintText = R.string.search; dopt.isSearchEnabled = true; dopt.isSoftInputVisible = false; - dopt.listPosition = state.listPosition; dopt.defaultText = state.searchQuery; dopt.positionCallback = result -> { @@ -845,11 +837,7 @@ public static void showHeadlineDialog( TextViewUtils.selectLines(edit, line); final String jumpJs = "document.querySelector('[line=\"" + line + "\"]').scrollIntoView();"; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript(jumpJs, null); - } else { - webView.loadUrl("javascript:" + jumpJs); - } + webView.evaluateJavascript(jumpJs, null); }; dopt.neutralButtonText = R.string.filter; @@ -879,11 +867,10 @@ public static void showHeadlineDialog( }; dopt.dismissCallback = (d) -> { - state.listPosition = dopt.listPosition; state.searchQuery = dopt.defaultText; }; - GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt); + GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt, state); } public static void showIndentSizeDialog(final Activity activity, final int indent, final GsCallback.a1 callback) { diff --git a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java index 9d435cd6e8..5219feed26 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/GsSearchOrCustomTextDialog.java @@ -129,7 +129,9 @@ public static class DialogOptions { public static class DialogState { public int listPosition = -1; public String defaultText = ""; + public String searchQuery = ""; public Parcelable instanceState; + public Set disabledLevels = new HashSet<>(); // For HeadlineDialog } public static class Adapter extends BaseAdapter { From 4fb2997aa45f637cd91b5646225e5eadd6d9cdef Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Sun, 4 Aug 2024 16:09:17 +0800 Subject: [PATCH 2/8] fix line numbers cannot be applied when directly entering view-mode --- .../activity/DocumentEditAndViewFragment.java | 20 +++++++++---------- .../frontend/textview/HighlightingEditor.java | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) 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 5b0d2af9b3..d0143d1781 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java @@ -147,7 +147,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { return; } - if (_appSettings.getSetWebViewFulldrawing() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (_appSettings.getSetWebViewFulldrawing()) { WebView.enableSlowWholeDocumentDraw(); } @@ -170,7 +170,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { webSettings.setAllowUniversalAccessFromFileURLs(false); webSettings.setMediaPlaybackRequiresUserGesture(false); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { + if (BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); // Inspect on computer chromium browser: chrome://inspect/#devices } @@ -195,7 +195,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { _hlEditor.setSaveInstanceState(false); // We will reload from disk _document.resetChangeTracking(); // force next reload - loadDocument(); // If not set by loadDocument, se the undo-redo helper here if (_editTextUndoRedoHelper == null) { @@ -219,6 +218,8 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { } _webView.setBackgroundColor(Color.TRANSPARENT); + loadDocument(); + // Various settings setHorizontalScrollMode(isDisplayedAtMainActivity() || _appSettings.getDocumentWrapState(_document.getPath())); updateMenuToggleStates(0); @@ -326,7 +327,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.findItem(R.id.submenu_tools).setVisible(isText); menu.findItem(R.id.submenu_per_file_settings).setVisible(isText); - menu.findItem(R.id.action_share_pdf).setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT); + menu.findItem(R.id.action_share_pdf).setVisible(true); menu.findItem(R.id.action_share_image).setVisible(true); menu.findItem(R.id.action_load_epub).setVisible(isExperimentalFeaturesEnabled); @@ -522,7 +523,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) { if (saveDocument(false)) { TextConverterBase converter = FormatRegistry.getFormat(_document.getFormat(), activity, _document).getConverter(); _cu.shareText(getActivity(), - converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.getLineNumbersEnabled(), _document.getFile()), + converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.isLineNumbersEnabled(), _document.getFile()), "text/" + (item.getItemId() == R.id.action_share_html ? "html" : "plain") ); } @@ -545,7 +546,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) { setViewModeVisibility(true); Toast.makeText(activity, R.string.please_wait, Toast.LENGTH_LONG).show(); _webView.postDelayed(() -> { - if (item.getItemId() == R.id.action_share_pdf && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (item.getItemId() == R.id.action_share_pdf) { _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n")); } else if (item.getItemId() != R.id.action_share_pdf) { Bitmap bmp = _cu.getBitmapFromWebView(_webView, item.getItemId() == R.id.action_share_image); @@ -609,7 +610,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { return true; } case R.id.action_line_numbers: { - final boolean newState = !_hlEditor.getLineNumbersEnabled(); + final boolean newState = !_hlEditor.isLineNumbersEnabled(); _appSettings.setDocumentLineNumbersEnabled(_document.getPath(), newState); _hlEditor.setLineNumbersEnabled(newState); updateMenuToggleStates(0); @@ -718,7 +719,7 @@ private void updateMenuToggleStates(final int selectedFormatActionId) { mi.setChecked(_hlEditor.getHighlightingEnabled()); } if ((mi = _fragmentMenu.findItem(R.id.action_line_numbers)) != null) { - mi.setChecked(_hlEditor.getLineNumbersEnabled()); + mi.setChecked(_hlEditor.isLineNumbersEnabled()); } if ((mi = _fragmentMenu.findItem(R.id.action_enable_auto_format)) != null) { mi.setChecked(_hlEditor.getAutoFormatEnabled()); @@ -838,8 +839,7 @@ private boolean isDisplayedAtMainActivity() { } public void updateViewModeText() { - final String text = getTextString(); - _format.getConverter().convertMarkupShowInWebView(_document, text, getActivity(), _webView, _nextConvertToPrintMode, _hlEditor.getLineNumbersEnabled()); + _format.getConverter().convertMarkupShowInWebView(_document, getTextString(), getActivity(), _webView, _nextConvertToPrintMode, _hlEditor.isLineNumbersEnabled()); } public void setViewModeVisibility(final boolean show) { diff --git a/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java b/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java index d5dfc845c5..a0393d0ee0 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java +++ b/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java @@ -203,7 +203,7 @@ public boolean setHighlightingEnabled(final boolean enable) { return prev; } - public boolean getLineNumbersEnabled() { + public boolean isLineNumbersEnabled() { return _numEnabled; } From 75df8ef0fa5b488a504143613bf36f48d571efb2 Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Sun, 4 Aug 2024 14:35:28 +0800 Subject: [PATCH 3/8] improve appearance of copying code block button --- .../prism/plugins/toolbar/prism-toolbar.css | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css b/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css index efb9afa332..a7f100bc7c 100644 --- a/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css +++ b/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css @@ -42,20 +42,19 @@ div.code-toolbar > .toolbar > .toolbar-item > button { div.code-toolbar > .toolbar > .toolbar-item > a, div.code-toolbar > .toolbar > .toolbar-item > button, div.code-toolbar > .toolbar > .toolbar-item > span { - color: #bbb; + color: #aaa; font-size: 0.8em; text-transform: none; - background: #f5f2f0; - background: rgba(224, 224, 224, 0.3); - box-shadow: 0 2px 0 0 rgba(0,0,0,0.2); + background: rgba(215, 215, 215, 0.4); + box-shadow: 0 2px 0 0 rgba(150,150,150,0.8); border-radius: 0.4em; display: inline-block; - min-width: 75%; - max-height: 1.6em; - padding-left: 0.35em; - padding-right: 0.35em; + min-width: 80%; + max-height: 1.8em; + padding-left: 0.5em; + padding-right: 0.5em; padding-top: 0.2em; - padding-bottom: 0.4em; + padding-bottom: 0.2em; } div.code-toolbar > .toolbar > .toolbar-item > a:hover, @@ -63,7 +62,7 @@ div.code-toolbar > .toolbar > .toolbar-item > a:focus, div.code-toolbar > .toolbar > .toolbar-item > button:hover, div.code-toolbar > .toolbar > .toolbar-item > button:focus, div.code-toolbar > .toolbar > .toolbar-item > span:hover, -/* div.code-toolbar > .toolbar > .toolbar-item > span:focus */ { - color: inherit; +div.code-toolbar > .toolbar > .toolbar-item > span:focus { + color: rgba(0, 0, 200, 0.8); text-decoration: none; } From 91284149c45ef819ac6db4bd41b498205593753e Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Sun, 4 Aug 2024 10:53:40 +0800 Subject: [PATCH 4/8] reformat default inject-head code --- .../res/values/string-not_translatable.xml | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/app/src/main/res/values/string-not_translatable.xml b/app/src/main/res/values/string-not_translatable.xml index bf3c0ac8cf..d3f7722cef 100644 --- a/app/src/main/res/values/string-not_translatable.xml +++ b/app/src/main/res/values/string-not_translatable.xml @@ -73,20 +73,21 @@ work. If not, see . CSS, JavaScript]]> - \nhtml,body { - \n /*font-family: sans-serif-condensed;*/ - \n /*font-size: 80%;*/ + \nhtml, body { + \n/* + \nfont-family: sans-serif-condensed; + \nfont-size: 80%; + \n*/ \n} \n \n - \n \n ]]> @@ -294,38 +295,38 @@ work. If not, see . - role - underline - role - overline - role - linethrough - role - nobreak - role - nowrap - role - prewrap + role - underline + role - overline + role - linethrough + role - nobreak + role - nowrap + role - prewrap - inline - highlight + inline - highlight - inline - subscript - inline - superscript + inline - subscript + inline - superscript - block - comment - block - example - block - listing - block - literal - block - open - block - sidebar - block - table - block - pass - block - quote - - block - code + block - comment + block - example + block - listing + block - literal + block - open + block - sidebar + block - table + block - pass + block - quote + + block - code block - collapsible break - thematic - break - page + break - page abid_wikitext_h1 From d0b8783b35baf35018914a75c0298aa36d5a43e2 Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Sun, 4 Aug 2024 14:39:22 +0800 Subject: [PATCH 5/8] minor improvements --- CONTRIBUTORS.md | 6 +++--- .../markor/format/markdown/MarkdownTextConverter.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7e8f944f56..f774bc57ce 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -30,7 +30,7 @@ Where: * **[Kanthi Subramanian](https://github.com/subkanthi)**
~° File Info Dialog * **[Emanuele Petriglia](https://github.com/ema-pe)**
~° Italian translation * **[Tiago Danin](https://tiagodanin.github.io)**
~° Brazilian Portuguese translation -* **[Jesica Chu](https://github.com/jesicachu)**
~° Spanish and Traiditonal Chinese translation +* **[Jesica Chu](https://github.com/jesicachu)**
~° Spanish and Traditional Chinese translation * **[Ankush S Shetkar](https://www.linkedin.com/in/livelycoder/)**
~° Added Chrome custom tabs for urls * **[Lars Pontoppidan](https://github.com/larpon)**
~° Danish translation * **[Amaya Lim](https://github.com/nightrainlily)**
~° Improved project description @@ -42,7 +42,7 @@ Where: * **[Vladislav Glinsky](https://github.com/cl0ne)**
~° Ukrainian/Russian translations * **[David Hebbeker](https://david.hebbeker.info/)**
~° Added tooltips for text actions * **[Harshad Srinivasan](https://github.com/harshad1)**
~° Added functionality to handle leading spaces in lists -* **[Niels](https://stackoverflow.com/users/432115/niels)**
~° Added encryption for textfile contents +* **[Niels](https://stackoverflow.com/users/432115/niels)**
~° Added encryption for text file contents * **[Helguli](https://github.com/Helguli)**
~° Added fast scroll to editor * **[Patricia Heimfarth](https://github.com/PatriciaHeimfarth)**
~° Added checkbox for todo completion date * **[Peter Schwede](https://github.com/pschwede)**
~° Added Zim-Wiki support @@ -52,5 +52,5 @@ Where: * **[Li Guanglin](https://github.com/guanglinn)**
~° Added line numbers support * **[bigger124](https://github.com/bigger124)**
~° Added OrgMode-Support * **[Ayowel](https://github.com/ayowel)**
~° Mermaid update -* **[Matthew White](https://github.com/mehw)**
~° Zim-Wiki link/attachment conformance. +* **[Matthew White](https://github.com/mehw)**
~° Zim-Wiki link/attachment conformance * **[Markus Paintner](https://github.com/goli4thus)**
~° Added duplicate lines action diff --git a/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java b/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java index d93047b13a..1c8d084fb8 100644 --- a/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java +++ b/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownTextConverter.java @@ -90,7 +90,7 @@ public class MarkdownTextConverter extends TextConverterBase { //######################## //## Injected CSS / JS / HTML //######################## - public static final String CSS_BODY = CSS_S + "body{margin:0;padding:0.25vh 3.5vw}" + CSS_E; + public static final String CSS_BODY = CSS_S + "body{margin:0;padding:0.5vh 3.5vw}" + CSS_E; public static final String CSS_HEADER_UNDERLINE = CSS_S + " .header_no_underline { text-decoration: none; color: " + TOKEN_BW_INVERSE_OF_THEME + "; } h1 < a.header_no_underline { border-bottom: 2px solid #eaecef; } " + CSS_E; public static final String CSS_H1_H2_UNDERLINE = CSS_S + " h1,h2 { border-bottom: 2px solid " + TOKEN_BW_INVERSE_OF_THEME_HEADER_UNDERLINE + "; } " + CSS_E; public static final String CSS_BLOCKQUOTE_VERTICAL_LINE = CSS_S + "blockquote{padding:0px 14px;border-" + TOKEN_TEXT_DIRECTION + ":3.5px solid #dddddd;margin:4px 0}" + CSS_E; From e0253ff1f4d249c9e31d4f0c4d69d97dc9e4c5ca Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Wed, 4 Sep 2024 16:43:53 +0800 Subject: [PATCH 6/8] minor improvements --- .../gsantner/markor/frontend/MarkorDialogFactory.java | 4 +++- .../assets/prism/plugins/toolbar/prism-toolbar.css | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java index e098c10852..97d841f499 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/MarkorDialogFactory.java @@ -837,7 +837,9 @@ public static void showHeadlineDialog( TextViewUtils.selectLines(edit, line); final String jumpJs = "document.querySelector('[line=\"" + line + "\"]').scrollIntoView();"; - webView.evaluateJavascript(jumpJs, null); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + webView.evaluateJavascript(jumpJs, null); + } }; dopt.neutralButtonText = R.string.filter; diff --git a/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css b/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css index a7f100bc7c..0b7f9f8502 100644 --- a/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css +++ b/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css @@ -47,13 +47,13 @@ div.code-toolbar > .toolbar > .toolbar-item > span { text-transform: none; background: rgba(215, 215, 215, 0.4); box-shadow: 0 2px 0 0 rgba(150,150,150,0.8); - border-radius: 0.4em; + border-radius: 0.5em; display: inline-block; min-width: 80%; - max-height: 1.8em; - padding-left: 0.5em; - padding-right: 0.5em; - padding-top: 0.2em; + max-height: 1.75em; + padding-left: 0.45em; + padding-right: 0.45em; + padding-top: 0.1em; padding-bottom: 0.2em; } From 9653fc0bfd8bc0d4b5add460bd160ed5369fde22 Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Thu, 5 Sep 2024 10:01:44 +0800 Subject: [PATCH 7/8] reorganise loadDocument() to original location --- .../activity/DocumentEditAndViewFragment.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 d0143d1781..c828cb1eb7 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java @@ -147,7 +147,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { return; } - if (_appSettings.getSetWebViewFulldrawing()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.getSetWebViewFulldrawing()) { WebView.enableSlowWholeDocumentDraw(); } @@ -170,7 +170,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { webSettings.setAllowUniversalAccessFromFileURLs(false); webSettings.setMediaPlaybackRequiresUserGesture(false); - if (BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && BuildConfig.IS_TEST_BUILD && BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); // Inspect on computer chromium browser: chrome://inspect/#devices } @@ -194,9 +194,9 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { } _hlEditor.setSaveInstanceState(false); // We will reload from disk - _document.resetChangeTracking(); // force next reload - - // If not set by loadDocument, se the undo-redo helper here + _document.resetChangeTracking(); // Force next reload + loadDocument(); + // If not set the undo-redo helper by loadDocument, set it here if (_editTextUndoRedoHelper == null) { _editTextUndoRedoHelper = new TextViewUndoRedo(_hlEditor); } @@ -218,8 +218,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { } _webView.setBackgroundColor(Color.TRANSPARENT); - loadDocument(); - // Various settings setHorizontalScrollMode(isDisplayedAtMainActivity() || _appSettings.getDocumentWrapState(_document.getPath())); updateMenuToggleStates(0); @@ -547,8 +545,10 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) { Toast.makeText(activity, R.string.please_wait, Toast.LENGTH_LONG).show(); _webView.postDelayed(() -> { if (item.getItemId() == R.id.action_share_pdf) { - _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n")); - } else if (item.getItemId() != R.id.action_share_pdf) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n")); + } + } else { Bitmap bmp = _cu.getBitmapFromWebView(_webView, item.getItemId() == R.id.action_share_image); _cu.shareImage(getContext(), bmp, null); } From 2c1eb746dc8cf243e77492516781b0797ea9bb29 Mon Sep 17 00:00:00 2001 From: Li Guanglin Date: Thu, 5 Sep 2024 10:18:55 +0800 Subject: [PATCH 8/8] reorganise to fix line numbers cannot be enabled directly entering view-mode --- .../activity/DocumentEditAndViewFragment.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 c828cb1eb7..c1034d358b 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java @@ -193,14 +193,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { setViewModeVisibility(startInPreview, false); } - _hlEditor.setSaveInstanceState(false); // We will reload from disk - _document.resetChangeTracking(); // Force next reload - loadDocument(); - // If not set the undo-redo helper by loadDocument, set it here - if (_editTextUndoRedoHelper == null) { - _editTextUndoRedoHelper = new TextViewUndoRedo(_hlEditor); - } - // Configure the editor. Doing so after load helps prevent some errors // --------------------------------------------------------- _hlEditor.setLineSpacing(0, _appSettings.getEditorLineSpacing()); @@ -223,6 +215,14 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { updateMenuToggleStates(0); // --------------------------------------------------------- + _hlEditor.setSaveInstanceState(false); // We will reload from disk + _document.resetChangeTracking(); // Force next reload + loadDocument(); + // If not set the undo-redo helper by loadDocument, set it here + if (_editTextUndoRedoHelper == null) { + _editTextUndoRedoHelper = new TextViewUndoRedo(_hlEditor); + } + final Runnable debounced = TextViewUtils.makeDebounced(500, () -> { checkTextChangeState(); updateUndoRedoIconStates();