Skip to content

Commit

Permalink
Many small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Aug 13, 2023
1 parent 7faa0db commit c7b0cd7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
final boolean newState = !_hlEditor.getLineNumbersEnabled();
_appSettings.setDocumentLineNumbersEnabled(_document.getPath(), newState);
_hlEditor.setLineNumbersEnabled(newState);
_hlEditor.invalidate();
updateMenuToggleStates(0);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ public String convertMarkupShowInWebView(Document document, String content, Acti
html = "Please report at project issue tracker: " + e;
}

String baseFolder = ApplicationObject.settings().getNotebookDirectory().getAbsolutePath();
if (document.getFile().getParentFile() != null) {
baseFolder = document.getFile().getParent();
String baseFolder = document.getFile().getParent();
if (baseFolder == null) {
baseFolder = "file://" + baseFolder + "/";
}
baseFolder = "file://" + baseFolder + "/";
webView.loadDataWithBaseURL(baseFolder, html, getContentType(), UTF_CHARSET, null);

// When TOKEN_TEXT_CONVERTER_MAX_ZOOM_OUT_BY_DEFAULT is contained in text zoom out as far possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ public class MarkdownTextConverter extends TextConverterBase {
public String convertMarkup(String markup, Context context, boolean lightMode, boolean lineNum, File file) {
String converted = "", onLoadJs = "", head = "";

MutableDataSet options = new MutableDataSet();
final MutableDataSet options = new MutableDataSet();

if (lineNum) {
// Add code blocks Line numbers extension
ArrayList<Extension> extensions = new ArrayList<>(flexmarkExtensions);
final ArrayList<Extension> extensions = new ArrayList<>(flexmarkExtensions);
extensions.add(LineNumbersExtension.create());
options.set(Parser.EXTENSIONS, extensions);
} else {
Expand Down Expand Up @@ -274,8 +274,7 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
}

// Enable View (block) code syntax highlighting
final String xt = getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", lineNum);
head += xt;
head += getViewHlPrismIncludes(GsContextUtils.instance.isDarkModeEnabled(context) ? "-tomorrow" : "", lineNum);

// Jekyll: Replace {{ site.baseurl }} with ..--> usually used in Jekyll blog _posts folder which is one folder below repository root, for reference to e.g. pictures in assets folder
markup = markup.replace("{{ site.baseurl }}", "..").replace(TOKEN_SITE_DATE_JEKYLL, TOKEN_POST_TODAY_DATE);
Expand All @@ -297,11 +296,9 @@ public String convertMarkup(String markup, Context context, boolean lightMode, b
fmaText = HTML_FRONTMATTER_CONTAINER_S + fmaText + HTML_FRONTMATTER_CONTAINER_E + "\n";
}


////////////
// Markup parsing - afterwards = HTML
converted = flexmarkRenderer.withOptions(options).render(flexmarkParser.parse(markup));
converted = fmaText + converted;
converted = fmaText + flexmarkRenderer.withOptions(options).render(flexmarkParser.parse(markup));

// After render changes: Fixes for Footnotes (converter creates footnote + <br> + ref#(click) --> remove line break)
if (converted.contains("footnote-")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private void drawLineNumbers(final Canvas canvas) {
final int offsetY = getPaddingTop();
final int maxLayoutLine = layout.getLineCount();

// Set gutter size and padding
// Only update if needed
final int lineX;
if (_numXPos < 0) {
Expand All @@ -173,11 +174,12 @@ private void drawLineNumbers(final Canvas canvas) {
// Draw the right border
_paint.setColor(Color.LTGRAY);
canvas.drawLine(lineX, top, lineX, bottom, _paint);
_paint.setColor(Color.GRAY);

// Draw the numbers
int line = 0;
int number = 1;
int yPos = top;
_paint.setColor(Color.GRAY);

while(line < maxLayoutLine && yPos < bottom) {
final int start = layout.getLineStart(line);
Expand Down Expand Up @@ -281,13 +283,11 @@ public boolean getLineNumbersEnabled() {
return _numEnabled;
}

public boolean setLineNumbersEnabled(final boolean enable) {
final boolean prev = _numEnabled;

if (enable != _numEnabled) {
_numEnabled = enable;
public void setLineNumbersEnabled(final boolean enable) {
if (enable ^ _numEnabled) {
post(this::invalidate);
}
return prev;
_numEnabled = enable;
}

// Region to highlight
Expand Down

0 comments on commit c7b0cd7

Please sign in to comment.