Skip to content

Commit

Permalink
Various bugfixes (anchor/toc jumping #2364, snippets folder #2369, wi…
Browse files Browse the repository at this point in the history
…kitext newfile #2362, virtual directory browser #2350) (PR #2370 by @hardhard1)

* Jump by a line identifier, not by id
* For all nodes, use eval
* Fixed bad key in snippet directory setting
* Fix virtual folders and wikitext underscores
  • Loading branch information
harshad1 authored Jul 27, 2024
1 parent be4ab7f commit 57aaf0f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,12 @@ private String replaceTokens(final String markup, final Map<String, List<String>
// Extension to add line numbers to headings
// ---------------------------------------------------------------------------------------------

public static String getIdForLineNumber(final int num) {
return "line-" + num;
}

private static class LineNumberIdProvider implements AttributeProvider {
@Override
public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
if (node instanceof com.vladsch.flexmark.ast.Heading) {
final Document document = node.getDocument();
final int lineNumber = document.getLineNumber(node.getStartOffset());
attributes.addValue("id", getIdForLineNumber(lineNumber));
}
final Document document = node.getDocument();
final int lineNumber = document.getLineNumber(node.getStartOffset());
attributes.addValue("line", "" + lineNumber);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,12 @@ public static void showHeadlineDialog(
final int line = headings.get(index).line;

TextViewUtils.selectLines(edit, line);

final String id = MarkdownTextConverter.getIdForLineNumber(line);
webView.loadUrl(String.format("javascript:document.getElementById('%s').scrollIntoView();", id));
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);
}
};

dopt.neutralButtonText = R.string.filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,15 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
final MarkorContextUtils cu = new MarkorContextUtils(getContext());
dialogBuilder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> dialogInterface.dismiss());
dialogBuilder.setPositiveButton(getString(android.R.string.ok), (dialogInterface, i) -> {
final FormatRegistry.Format fmt = formats.get(typeSpinner.getSelectedItemPosition());

final String title = getTitle.callback();
final String ext = extEdit.getText().toString().trim();
final String fileName = GsFileUtils.getFilteredFilenameWithoutDisallowedChars(title + ext);
String fileName = GsFileUtils.getFilteredFilenameWithoutDisallowedChars(title + ext);

if (fmt.format == FormatRegistry.FORMAT_WIKITEXT) {
fileName = fileName.replace(" ", "_");
}

// Get template string
// -------------------------------------------------------------------------------------
Expand All @@ -286,7 +291,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
// These are done even if the file isn't created
final String titleFormat = formatEdit.getText().toString().trim();
appSettings.setTemplateTitleFormat(templateAdapter.getItem(ti), titleFormat);
final FormatRegistry.Format fmt = formats.get(typeSpinner.getSelectedItemPosition());
appSettings.setTypeTemplate(fmt.format, (String) templateSpinner.getSelectedItem());
appSettings.setNewFileDialogLastUsedType(fmt.format);
appSettings.setNewFileDialogLastUsedExtension(extEdit.getText().toString().trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public File getDefaultTodoFile() {

public File getSnippetsDirectory() {
final File _default = new File(getNotebookDirectory(), ".app/snippets");
final File snf = new File(getString(R.string.pref_key__quicknote_filepath, _default.getAbsolutePath()));
final File snf = new File(getString(R.string.pref_key__snippet_directory_path, _default.getAbsolutePath()));
return snf.isDirectory() && snf.canRead() ? snf : _default;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,18 @@ private void loadFolder(final File folder, final @Nullable File toShow) {
virtualMapping.put(VIRTUAL_STORAGE_APP_DATA_PRIVATE, appDataFolder);
newData.add(VIRTUAL_STORAGE_APP_DATA_PRIVATE);
}
} else if (folder.isDirectory()) {
GsCollectionUtils.addAll(newData, folder.listFiles(GsFileBrowserListAdapter.this));
} else if (folder.equals(VIRTUAL_STORAGE_RECENTS)) {
newData.addAll(_dopt.recentFiles);
} else if (folder.equals(VIRTUAL_STORAGE_POPULAR)) {
newData.addAll(_dopt.popularFiles);
} else if (folder.equals(VIRTUAL_STORAGE_FAVOURITE)) {
newData.addAll(_dopt.favouriteFiles);
} else if (folder.getAbsolutePath().equals("/storage/emulated")) {
} else if (folder.isDirectory()) {
GsCollectionUtils.addAll(newData, folder.listFiles(GsFileBrowserListAdapter.this));
}

// Some special folders get special children
if (folder.getAbsolutePath().equals("/storage/emulated")) {
newData.add(new File(folder, "0"));
} else if (folder.getAbsolutePath().equals("/")) {
newData.add(new File(folder, "storage"));
Expand All @@ -663,15 +666,16 @@ private void loadFolder(final File folder, final @Nullable File toShow) {
}

for (final File externalFileDir : ContextCompat.getExternalFilesDirs(_context, null)) {
for (int i = 0; i < newData.size(); i++) {
final File file = newData.get(i);
if (!canWrite(file) && !file.getAbsolutePath().equals("/") && externalFileDir != null && externalFileDir.getAbsolutePath().startsWith(file.getAbsolutePath())) {
final int depth = GsTextUtils.countChars(file.getAbsolutePath(), '/')[0];
for (final File file : newData) {
final String absPath = file.getAbsolutePath();
final String absExt = externalFileDir.getAbsolutePath() ;
if (!canWrite(file) && !absPath.equals("/") && absExt.startsWith(absPath)) {
final int depth = GsTextUtils.countChars(absPath, '/')[0];
if (depth < 3) {
final File parent = file.getParentFile();
if (parent != null) {
final File remap = new File(parent.getAbsolutePath(), "appdata-public (" + file.getName() + ")");
virtualMapping.put(remap, new File(externalFileDir.getAbsolutePath()));
virtualMapping.put(remap, new File(absExt));
newData.add(remap);
}
}
Expand Down

0 comments on commit 57aaf0f

Please sign in to comment.