From cdd623ef7a620ce839091b0bbe5034dc54a46dec Mon Sep 17 00:00:00 2001
From: Li Guanglin <60415467+guanglinn@users.noreply.github.com>
Date: Wed, 25 Sep 2024 07:07:47 +0800
Subject: [PATCH] Improvements for HeadlineDialog scroll restoration and copy
code block button (PR #2406)
---
CONTRIBUTORS.md | 6 +--
.../activity/DocumentEditAndViewFragment.java | 40 +++++++++----------
.../markdown/MarkdownActionButtons.java | 3 +-
.../markdown/MarkdownTextConverter.java | 2 +-
.../wikitext/WikitextActionButtons.java | 3 +-
.../markor/frontend/MarkorDialogFactory.java | 15 +------
.../frontend/textview/HighlightingEditor.java | 2 +-
.../frontend/GsSearchOrCustomTextDialog.java | 2 +
.../res/values/string-not_translatable.xml | 21 +++++-----
.../prism/plugins/toolbar/prism-toolbar.css | 25 ++++++------
10 files changed, 56 insertions(+), 63 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/activity/DocumentEditAndViewFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java
index 3cb59fc36d..49ae64042d 100644
--- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java
+++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditAndViewFragment.java
@@ -148,7 +148,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
return;
}
- if (_appSettings.getSetWebViewFulldrawing() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.getSetWebViewFulldrawing()) {
WebView.enableSlowWholeDocumentDraw();
}
@@ -172,7 +172,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 (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
}
@@ -193,15 +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 by loadDocument, se the undo-redo helper 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 +214,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();
@@ -328,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);
@@ -523,7 +522,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.file),
+ converter.convertMarkup(getTextString(), getActivity(), false, _hlEditor.isLineNumbersEnabled(), _document.file),
"text/" + (item.getItemId() == R.id.action_share_html ? "html" : "plain")
);
}
@@ -546,9 +545,11 @@ 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) {
- _cu.printOrCreatePdfFromWebview(_webView, _document, getTextString().contains("beamer\n"));
- } else if (item.getItemId() != R.id.action_share_pdf) {
+ 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);
}
@@ -610,7 +611,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.path, newState);
_hlEditor.setLineNumbersEnabled(newState);
updateMenuToggleStates(0);
@@ -721,7 +722,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());
@@ -841,8 +842,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/format/markdown/MarkdownActionButtons.java b/app/src/main/java/net/gsantner/markor/format/markdown/MarkdownActionButtons.java
index e5e4e319e9..d9f7d4971b 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/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;
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 c54ce8ab2f..5f6ee624b1 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 275a703ef2..e34b8e79ac 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;
@@ -790,12 +789,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
*
@@ -809,7 +802,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
@@ -837,7 +830,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 -> {
@@ -848,8 +840,6 @@ public static void showHeadlineDialog(
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);
}
};
@@ -880,11 +870,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/markor/frontend/textview/HighlightingEditor.java b/app/src/main/java/net/gsantner/markor/frontend/textview/HighlightingEditor.java
index 5914b3ae1c..38f2e1f12e 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
@@ -251,7 +251,7 @@ public boolean setHighlightingEnabled(final boolean enable) {
return prev;
}
- public boolean getLineNumbersEnabled() {
+ public boolean isLineNumbersEnabled() {
return _numEnabled;
}
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 9d79309add..75dc91e766 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 {
diff --git a/app/src/main/res/values/string-not_translatable.xml b/app/src/main/res/values/string-not_translatable.xml
index 6066dc02a3..b84dc19ae0 100644
--- a/app/src/main/res/values/string-not_translatable.xml
+++ b/app/src/main/res/values/string-not_translatable.xml
@@ -72,20 +72,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
]]>
diff --git a/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css b/app/thirdparty/assets/prism/plugins/toolbar/prism-toolbar.css
index efb9afa332..0b7f9f8502 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);
- border-radius: 0.4em;
+ background: rgba(215, 215, 215, 0.4);
+ box-shadow: 0 2px 0 0 rgba(150,150,150,0.8);
+ border-radius: 0.5em;
display: inline-block;
- min-width: 75%;
- max-height: 1.6em;
- padding-left: 0.35em;
- padding-right: 0.35em;
- padding-top: 0.2em;
- padding-bottom: 0.4em;
+ min-width: 80%;
+ max-height: 1.75em;
+ padding-left: 0.45em;
+ padding-right: 0.45em;
+ padding-top: 0.1em;
+ 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;
}