Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize unnecessary cursor shifting at editor, various fixes & improvements #1839

Merged
merged 55 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7cbeadc
Don't shift on resize
harshad1 Sep 10, 2022
79524be
Tighter logic
harshad1 Sep 10, 2022
9b1a70f
Reverting some changes
harshad1 Sep 11, 2022
3e2daea
Many more fixes
harshad1 Sep 20, 2022
c99f047
Merge branch 'master' into minimize_shifting
harshad1 Sep 20, 2022
cc73725
Updated TodoTxtParser -> TodoTxtTask
harshad1 Sep 20, 2022
fc3a4f9
Respect dotfile hidden in widget
harshad1 Sep 21, 2022
fe0ff37
Fixed
harshad1 Sep 21, 2022
c3f8f4b
Improved jump prevention, bad load detection
harshad1 Sep 25, 2022
dbcad79
Removed unnecessary
harshad1 Sep 25, 2022
cb22b60
Cleanups
harshad1 Sep 25, 2022
2844cf0
Cleaned up handling
harshad1 Sep 25, 2022
83347cf
Fixed null state
harshad1 Sep 26, 2022
a0744f3
Merge remote-tracking branch 'upstream/master' into minimize_shifting
harshad1 Sep 26, 2022
9445d4a
Removed redundant functions
harshad1 Sep 26, 2022
2ca54c6
Attempt to solve onNewIntent crash in MainActivity
harshad1 Sep 27, 2022
10322aa
size based defence on write andmore loggin
harshad1 Sep 27, 2022
a04b319
post in fragments
harshad1 Sep 27, 2022
f0a5195
Fixed mime type detection
harshad1 Sep 28, 2022
bf01706
Merge branch 'master' into minimize_shifting
gsantner Sep 28, 2022
fb7e11a
Merge branch 'master' into minimize_shifting
gsantner Sep 28, 2022
a626a06
Cleanups, ordered snippets
harshad1 Sep 29, 2022
113ae3e
Tweaks to minimize issues
harshad1 Sep 29, 2022
31c4d60
Tweaks to minimize issues
harshad1 Sep 29, 2022
6fd11ff
Merge branch 'minimize_shifting' of github.com:harshad1/markor into m…
harshad1 Sep 29, 2022
c1f5861
Interpolate datetime in template as snippet
harshad1 Sep 30, 2022
a08388d
Start position in templates
harshad1 Sep 30, 2022
765ec9a
Merge branch 'master' into minimize_shifting
gsantner Oct 2, 2022
48b8fef
Merge branch 'master' into minimize_shifting
gsantner Oct 2, 2022
3a70629
Always reload folder, Interpolate when inserting snippet
harshad1 Oct 2, 2022
1295598
Merge branch 'master' into minimize_shifting
gsantner Oct 2, 2022
136209a
Also detect open in markor files as plain text
harshad1 Oct 2, 2022
cf3eb2a
Merge branch 'minimize_shifting' of github.com:harshad1/markor into m…
harshad1 Oct 2, 2022
5013ea4
heightSame tweaks
harshad1 Oct 2, 2022
babab87
Step 0 toward horking out bringPointIntoView
harshad1 Oct 2, 2022
3821462
Merge branch 'master' into minimize_shifting
gsantner Oct 3, 2022
f408850
Completely controlling bringing cursor into view
harshad1 Oct 6, 2022
10c2bb1
Merge branch 'master' into minimize_shifting
harshad1 Oct 6, 2022
311a0e2
Merge branch 'minimize_shifting' of github.com:harshad1/markor into m…
harshad1 Oct 6, 2022
b384414
Some cleanups
harshad1 Oct 6, 2022
2a471dc
Removed drag handling
harshad1 Oct 6, 2022
ae1c6e5
Separate dynamic / static highlighting
harshad1 Oct 7, 2022
abdfab7
Calling correct clear
harshad1 Oct 7, 2022
ae27a18
Merge branch 'master' into minimize_shifting
harshad1 Oct 9, 2022
32ef3a6
optimize code
gsantner Oct 9, 2022
5c09c44
rename error string id
gsantner Oct 9, 2022
356876a
Revert unneeded changes
gsantner Oct 9, 2022
12fa28b
Better bottom spacing, mime type fixes
harshad1 Oct 12, 2022
62e2942
Merge branch 'master' into minimize_shifting
harshad1 Oct 12, 2022
152c07a
Merge branch 'minimize_shifting' of github.com:harshad1/markor into m…
harshad1 Oct 12, 2022
3bd0651
Don't default preview state
harshad1 Oct 13, 2022
2c7cc2c
More changes to start in preview correctly
harshad1 Oct 13, 2022
9998ddb
Further tweaks
harshad1 Oct 13, 2022
f4637e1
Open correct file
harshad1 Oct 14, 2022
642c2c6
add filename to error
gsantner Oct 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// It may cause reads or writes to _silently fail_
// Instead we try to create it, and exit if that isn't possible
if (isStateBad()) {
Toast.makeText(activity, R.string.document_error_exit, Toast.LENGTH_LONG).show();
Toast.makeText(activity, R.string.document_error, Toast.LENGTH_LONG).show();
gsantner marked this conversation as resolved.
Show resolved Hide resolved
activity.finish();
return;
}
Expand Down Expand Up @@ -362,15 +362,24 @@ private void updateUndoRedoIconStates() {
}

public boolean loadDocument() {
return loadDocument(false);
}

public boolean loadDocument(final boolean forceReload) {
if (isSdStatusBad() || isStateBad()) {
errorClipText();
return false;
}

// Only trigger the load process if constructing or file updated
if (_document.hasFileChangedSinceLastLoad()) {
// Only trigger the load process if constructing or file updated or force reload
if (forceReload || _document.hasFileChangedSinceLastLoad()) {
gsantner marked this conversation as resolved.
Show resolved Hide resolved

final String content = _document.loadContent(getContext());
if (content == null) {
errorClipText();
return false;
}
gsantner marked this conversation as resolved.
Show resolved Hide resolved

if (!_document.isContentSame(_hlEditor.getText())) {

final int[] sel = TextViewUtils.getSelection(_hlEditor);
Expand Down Expand Up @@ -431,7 +440,7 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
return true;
}
case R.id.action_reload: {
if (loadDocument()) {
if (loadDocument(true)) {
Toast.makeText(activity, "✔", Toast.LENGTH_SHORT).show();
}
return true;
Expand Down Expand Up @@ -655,6 +664,9 @@ private void setHorizontalScrollMode(final boolean wrap) {

final int[] sel = TextViewUtils.getSelection(_hlEditor);

final boolean hlEnabled = _hlEditor.getHighlightingEnabled();
_hlEditor.setHighlightingEnabled(false);
gsantner marked this conversation as resolved.
Show resolved Hide resolved

_primaryScrollView.removeAllViews();
if (_hsView != null) {
_hsView.removeAllViews();
Expand All @@ -670,8 +682,10 @@ private void setHorizontalScrollMode(final boolean wrap) {
_primaryScrollView.addView(_hlEditor);
}

_hlEditor.setHighlightingEnabled(hlEnabled);

// Run after layout() of immediate parent completes
(wrap ? _primaryScrollView : _hsView).post(() -> TextViewUtils.setSelectionAndShow(_hlEditor, sel[0], sel[1]));
(wrap ? _primaryScrollView : _hsView).post(() -> TextViewUtils.setSelectionAndShow(_hlEditor, sel));
}
}

Expand All @@ -686,8 +700,9 @@ public void errorClipText() {
Context context = getContext();
context = context == null ? ApplicationObject.get().getApplicationContext() : context;
new MarkorContextUtils(context).setClipboard(getContext(), text);
Toast.makeText(getContext(), R.string.document_error_clip, Toast.LENGTH_LONG).show();
}
// Always show error message
Toast.makeText(getContext(), R.string.document_error, Toast.LENGTH_LONG).show();
}

public boolean isSdStatusBad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import net.gsantner.markor.R;
import net.gsantner.markor.format.FormatRegistry;
import net.gsantner.markor.format.plaintext.PlaintextSyntaxHighlighter;
import net.gsantner.markor.format.todotxt.TodoTxtParser;
gsantner marked this conversation as resolved.
Show resolved Hide resolved
import net.gsantner.markor.format.todotxt.TodoTxtTask;
import net.gsantner.markor.frontend.NewFileDialog;
import net.gsantner.markor.frontend.filebrowser.MarkorFileBrowserFactory;
import net.gsantner.markor.frontend.settings.MarkorPermissionChecker;
Expand Down Expand Up @@ -197,10 +197,15 @@ private void appendToExistingDocument(final File file, final String separator, f
final String shareIntoFormat = _cu.formatDateTime(context, _appSettings.getShareIntoPrefix(), System.currentTimeMillis());
final boolean isTodoTxt = FormatRegistry.CONVERTER_TODOTXT.isFileOutOfThisFormat(file.getAbsolutePath());

final String newContent = document.loadContent(context).replaceAll("(^[\\r\\n]+|[\\r\\n]+$)", "")
+ separator
+ (isTodoTxt ? _sharedText : formatOrPrefixSharedText(shareIntoFormat, _sharedText));
document.saveContent(context, newContent);
final String oldContent = document.loadContent(context);
if (oldContent != null) {
final String newContent = oldContent.replaceAll("(^[\\r\\n]+|[\\r\\n]+$)", "")
+ separator
+ (isTodoTxt ? _sharedText : formatOrPrefixSharedText(shareIntoFormat, _sharedText));
document.saveContent(context, newContent);
} else {
Toast.makeText(context, R.string.document_error, Toast.LENGTH_LONG).show();
}

if (showEditor) {
showInDocumentActivity(document);
Expand Down Expand Up @@ -311,7 +316,7 @@ public Boolean onPreferenceClicked(Preference preference, String key, int keyId)
if (permc.doIfExtStoragePermissionGranted()) {
String sep = "\n";
if (_appSettings.getDocumentAutoFormatEnabled(this._appSettings.getTodoFile().getAbsolutePath())) {
sep += TodoTxtParser.getToday() + " ";
sep += TodoTxtTask.getToday() + " ";
}
appendToExistingDocument(this._appSettings.getTodoFile(), sep, false);
close = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ protected void openActivityAndClose(final Intent openIntent, File file) {
file.getParentFile().mkdirs();
}
if (!file.exists() && !file.isDirectory()) {
GsFileUtils.writeFile(file, "", new GsFileUtils.FileInfo().withBom(_appSettings.getNewFileDialogLastUsedUtf8Bom()));
final GsFileUtils.FileInfo info = new GsFileUtils.FileInfo();
info.hasBom = _appSettings.getNewFileDialogLastUsedUtf8Bom();
GsFileUtils.writeFile(file, "", info);
}
openIntent.putExtra(Document.EXTRA_PATH, openIntent.hasExtra(Document.EXTRA_PATH) ? openIntent.getSerializableExtra(Document.EXTRA_PATH) : file);
_cu.animateToActivity(this, openIntent, true, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ protected int getFormatActionsKey() {
@SuppressLint("NonConstantResourceId")
@Override
public boolean onActionClick(final @StringRes int action) {
final List<TodoTxtParser> selTasks = TodoTxtParser.getSelectedTasks(_hlEditor);
final List<TodoTxtTask> selTasks = TodoTxtTask.getSelectedTasks(_hlEditor);

switch (action) {
case R.string.abid_todotxt_toggle_done: {
final String doneMark = "x" + (_appSettings.isTodoAddCompletionDateEnabled() ? (" " + TodoTxtParser.getToday()) : "") + " ";
final String doneMark = "x" + (_appSettings.isTodoAddCompletionDateEnabled() ? (" " + TodoTxtTask.getToday()) : "") + " ";
final String bodyWithPri = "(.*)(\\spri:([A-Z])(?=\\s|$))(.*)"; // +1 = pre, +2 = full tag, +3 = pri, +4 = post
final String doneWithDate = "^([Xx]\\s(?:" + TodoTxtParser.PT_DATE + "\\s)?)";
final String doneWithDate = "^([Xx]\\s(?:" + TodoTxtTask.PT_DATE + "\\s)?)";
final String startingPriority = "^\\(([A-Z])\\)\\s";
runRegexReplaceAction(
// If task not done and starts with a priority and contains a pri tag
Expand All @@ -106,17 +106,17 @@ public boolean onActionClick(final @StringRes int action) {
}
case R.string.abid_todotxt_add_context: {
final List<String> contexts = new ArrayList<>();
contexts.addAll(TodoTxtParser.getContexts(TodoTxtParser.getAllTasks(_hlEditor.getText())));
contexts.addAll(new TodoTxtParser(_appSettings.getTodotxtAdditionalContextsAndProjects()).getContexts());
contexts.addAll(TodoTxtTask.getContexts(TodoTxtTask.getAllTasks(_hlEditor.getText())));
contexts.addAll(new TodoTxtTask(_appSettings.getTodotxtAdditionalContextsAndProjects()).getContexts());
MarkorDialogFactory.showSttContextDialog(getActivity(), contexts, (context) -> {
insertUniqueItem((context.charAt(0) == '@') ? context : "@" + context);
});
return true;
}
case R.string.abid_todotxt_add_project: {
final List<String> projects = new ArrayList<>();
projects.addAll(TodoTxtParser.getProjects(TodoTxtParser.getAllTasks(_hlEditor.getText())));
projects.addAll(new TodoTxtParser(_appSettings.getTodotxtAdditionalContextsAndProjects()).getProjects());
projects.addAll(TodoTxtTask.getProjects(TodoTxtTask.getAllTasks(_hlEditor.getText())));
projects.addAll(new TodoTxtTask(_appSettings.getTodotxtAdditionalContextsAndProjects()).getProjects());
MarkorDialogFactory.showSttProjectDialog(getActivity(), projects, (project) -> {
insertUniqueItem((project.charAt(0) == '+') ? project : "+" + project);
});
Expand All @@ -126,10 +126,10 @@ public boolean onActionClick(final @StringRes int action) {
MarkorDialogFactory.showPriorityDialog(getActivity(), selTasks.get(0).getPriority(), (priority) -> {
ArrayList<ReplacePattern> patterns = new ArrayList<>();
if (priority.length() > 1) {
patterns.add(new ReplacePattern(TodoTxtParser.PATTERN_PRIORITY_ANY, ""));
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, ""));
} else if (priority.length() == 1) {
final String _priority = String.format("(%c) ", priority.charAt(0));
patterns.add(new ReplacePattern(TodoTxtParser.PATTERN_PRIORITY_ANY, _priority));
patterns.add(new ReplacePattern(TodoTxtTask.PATTERN_PRIORITY_ANY, _priority));
patterns.add(new ReplacePattern("^\\s*", _priority));
}
runRegexReplaceAction(patterns);
Expand All @@ -145,17 +145,17 @@ public boolean onActionClick(final @StringRes int action) {
MarkorDialogFactory.showSttArchiveDialog(getActivity(), (callbackPayload) -> {
callbackPayload = Document.normalizeFilename(callbackPayload);

final ArrayList<TodoTxtParser> keep = new ArrayList<>();
final ArrayList<TodoTxtParser> move = new ArrayList<>();
final List<TodoTxtParser> allTasks = TodoTxtParser.getAllTasks(_hlEditor.getText());
final ArrayList<TodoTxtTask> keep = new ArrayList<>();
final ArrayList<TodoTxtTask> move = new ArrayList<>();
final List<TodoTxtTask> allTasks = TodoTxtTask.getAllTasks(_hlEditor.getText());

final int[] sel = TextViewUtils.getSelection(_hlEditor);
final CharSequence text = _hlEditor.getText();
final int[] selStart = TextViewUtils.getLineOffsetFromIndex(text, sel[0]);
final int[] selEnd = TextViewUtils.getLineOffsetFromIndex(text, sel[1]);

for (int i = 0; i < allTasks.size(); i++) {
final TodoTxtParser task = allTasks.get(i);
final TodoTxtTask task = allTasks.get(i);
if (task.isDone()) {
move.add(task);
if (i <= selStart[0]) selStart[0]--;
Expand All @@ -170,11 +170,11 @@ public boolean onActionClick(final @StringRes int action) {
if (doneFile.exists() && doneFile.canRead()) {
doneFileContents = GsFileUtils.readTextFileFast(doneFile).first.trim() + "\n";
}
doneFileContents += TodoTxtParser.tasksToString(move) + "\n";
doneFileContents += TodoTxtTask.tasksToString(move) + "\n";

// Write to done file
if (new Document(doneFile).saveContent(getActivity(), doneFileContents)) {
final String tasksString = TodoTxtParser.tasksToString(keep);
final String tasksString = TodoTxtTask.tasksToString(keep);
_hlEditor.setText(tasksString);
_hlEditor.setSelection(
TextViewUtils.getIndexFromLineOffset(tasksString, selStart),
Expand All @@ -190,9 +190,9 @@ public boolean onActionClick(final @StringRes int action) {
MarkorDialogFactory.showSttSortDialogue(getActivity(), (orderBy, descending) -> new Thread() {
@Override
public void run() {
final List<TodoTxtParser> tasks = TodoTxtParser.getAllTasks(_hlEditor.getText());
TodoTxtParser.sortTasks(tasks, orderBy, descending);
setEditorTextAsync(TodoTxtParser.tasksToString(tasks));
final List<TodoTxtTask> tasks = TodoTxtTask.getAllTasks(_hlEditor.getText());
TodoTxtTask.sortTasks(tasks, orderBy, descending);
setEditorTextAsync(TodoTxtTask.tasksToString(tasks));
_appSettings.setStringList(LAST_SORT_ORDER_KEY, Arrays.asList(orderBy, Boolean.toString(descending)));
}
}.start());
Expand All @@ -219,9 +219,9 @@ public boolean onActionLongClick(final @StringRes int action) {
case R.string.abid_todotxt_sort_todo: {
final List<String> last = _appSettings.getStringList(LAST_SORT_ORDER_KEY);
if (last != null && last.size() == 2) {
final List<TodoTxtParser> tasks = TodoTxtParser.getAllTasks(_hlEditor.getText());
TodoTxtParser.sortTasks(tasks, last.get(0), Boolean.parseBoolean(last.get(1)));
setEditorTextAsync(TodoTxtParser.tasksToString(tasks));
final List<TodoTxtTask> tasks = TodoTxtTask.getAllTasks(_hlEditor.getText());
TodoTxtTask.sortTasks(tasks, last.get(0), Boolean.parseBoolean(last.get(1)));
setEditorTextAsync(TodoTxtTask.tasksToString(tasks));
}
return true;
}
Expand Down Expand Up @@ -289,13 +289,13 @@ private void insertInline(String thing) {
}

private static Calendar parseDateString(final String dateString, final Calendar fallback) {
if (dateString == null || dateString.length() != TodoTxtParser.DATEF_YYYY_MM_DD_LEN) {
if (dateString == null || dateString.length() != TodoTxtTask.DATEF_YYYY_MM_DD_LEN) {
return fallback;
}

try {
Calendar calendar = Calendar.getInstance();
calendar.setTime(TodoTxtParser.DATEF_YYYY_MM_DD.parse(dateString));
calendar.setTime(TodoTxtTask.DATEF_YYYY_MM_DD.parse(dateString));
return calendar;
} catch (ParseException e) {
return fallback;
Expand All @@ -311,7 +311,7 @@ private void setDate() {
DatePickerDialog.OnDateSetListener listener = (_view, year, month, day) -> {
Calendar fmtCal = Calendar.getInstance();
fmtCal.set(year, month, day);
final String newDate = TodoTxtParser.DATEF_YYYY_MM_DD.format(fmtCal.getTime());
final String newDate = TodoTxtTask.DATEF_YYYY_MM_DD.format(fmtCal.getTime());
text.replace(sel[0], sel[1], newDate);
};

Expand All @@ -324,24 +324,24 @@ private void setDate() {


private void setDueDate(final int offset) {
final String dueString = TodoTxtParser.getSelectedTasks(_hlEditor).get(0).getDueDate();
final String dueString = TodoTxtTask.getSelectedTasks(_hlEditor).get(0).getDueDate();
Calendar initDate = parseDateString(dueString, Calendar.getInstance());
initDate.add(Calendar.DAY_OF_MONTH, (dueString == null || dueString.isEmpty()) ? offset : 0);

final DatePickerDialog.OnDateSetListener listener = (_view, year, month, day) -> {
Calendar fmtCal = Calendar.getInstance();
fmtCal.set(year, month, day);
final String newDue = "due:" + TodoTxtParser.DATEF_YYYY_MM_DD.format(fmtCal.getTime());
final String newDue = "due:" + TodoTxtTask.DATEF_YYYY_MM_DD.format(fmtCal.getTime());
runRegexReplaceAction(
// Replace due date
new ReplacePattern(TodoTxtParser.PATTERN_DUE_DATE, "$1" + newDue + "$4"),
new ReplacePattern(TodoTxtTask.PATTERN_DUE_DATE, "$1" + newDue + "$4"),
// Add due date to end if none already exists. Will correctly handle trailing whitespace.
new ReplacePattern("\\s*$", " " + newDue)
);
};

final DatePickerDialog.OnClickListener clear = (dialog, which) -> {
runRegexReplaceAction(new ReplacePattern(TodoTxtParser.PATTERN_DUE_DATE, "$4"));
runRegexReplaceAction(new ReplacePattern(TodoTxtTask.PATTERN_DUE_DATE, "$4"));
};

new DateFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public CharSequence filter(CharSequence source, int start, int end, Spanned dest
}

private CharSequence autoIndent(CharSequence source) {
return source + TodoTxtParser.DATEF_YYYY_MM_DD.format(new Date()) + " ";
return source + TodoTxtTask.DATEF_YYYY_MM_DD.format(new Date()) + " ";
}
}
Loading