Skip to content

Commit

Permalink
Start document at the last cursor position (closes gsantner#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Sep 24, 2018
1 parent ce15cfb commit fd2fa49
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ env:
- ANDROID_HOME=$HOME/android-sdk
matrix:
- TASK="clean build check -x lint --stacktrace"
- TASK="clean lintFlavorDefaultDebug --stacktrace"
# - TASK="clean lintFlavorDefaultDebug --stacktrace"
- TASK="clean testFlavorDefaultDebugUnitTest -x lint --stacktrace"

script: "./gradlew --no-daemon --parallel $TASK"
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
### v1.2.x <!-- [Blog post](https://gsantner.net/blog/android/2018/09/18/markor-release-v1.2.html) -->
**New features:**
- App-wide
- Add 'Auto' theme, switch light/dark theme by current hour
- App-wide
- Add 'Auto' theme, switch light/dark theme by current hour
- Editor
- Start document at the recent cursor position
- Jump to bottom on new documents and at special files

**Improved:**
- TextActions
- Don't list empty lines in simple search
- Edit picture supports now relative filepaths too
- Show import dialog for selected pictures too (like in file selection)
- TextActions
- Don't list empty lines in simple search
- Edit picture supports now relative filepaths too
- Show import dialog for selected pictures too (like in file selection)
- Preview
- Performance improvement for TOC & Math - only use when text contains headers/math
- Markdown: Underline h2 too (like h1, more common for two levels)

**Fixed:**
- Editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ public boolean saveDocument() {
boolean argAllowRename = getArguments() == null || getArguments().getBoolean(DocumentIO.EXTRA_ALLOW_RENAME, true);
ret = DocumentIO.saveDocument(_document, argAllowRename, _hlEditor.getText().toString());
updateLauncherWidgets();

if (_document != null && _document.getFile() != null){
new AppSettings(getContext()).setLastEditPosition(_document.getFile(), _hlEditor.getSelectionStart(), _hlEditor.getTop());
}
}
return ret;
}
Expand Down Expand Up @@ -364,9 +368,17 @@ public void onFragmentFirstTimeVisible() {
AppSettings as = new AppSettings(getContext());
if (_savedInstanceState == null || !_savedInstanceState.containsKey(SAVESTATE_CURSOR_POS)) {
// TODO
if (as.isEditorStartOnBotttom() && _hlEditor.length() > 0) {
_hlEditor.requestFocus();
_hlEditor.setSelection(_hlEditor.length());
if (_hlEditor.length() > 0) {
int lastPos;
if (_document != null && _document.getFile() != null && (lastPos = as.getLastEditPositionChar(_document.getFile())) >= 0 && lastPos <= _hlEditor.length()){
_hlEditor.requestFocus();
_hlEditor.setSelection(lastPos);
_hlEditor.scrollTo(0, as.getLastEditPositionScroll(_document.getFile()));
}
else if (as.isEditorStartOnBotttom()) {
_hlEditor.requestFocus();
_hlEditor.setSelection(_hlEditor.length());
}
}
}
}
Expand Down
33 changes: 31 additions & 2 deletions app/src/main/java/net/gsantner/markor/util/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -52,7 +51,7 @@ public boolean isDarkThemeEnabled() {
}
case "auto":
default: {
return !isCurrentHourOfDayBetween(9,17);
return !isCurrentHourOfDayBetween(9, 17);
}
}
}
Expand Down Expand Up @@ -281,6 +280,36 @@ public void addRecentDocument(File file) {
}
}

private static final String PREF_PREFIX_EDIT_POS_CHAR = "PREF_PREFIX_EDIT_POS_CHAR";
private static final String PREF_PREFIX_EDIT_POS_SCROLL = "PREF_PREFIX_EDIT_POS_SCROLL";

public void setLastEditPosition(File file, int pos, int scrolloffset) {
if (file == null || !file.exists()) {
return;
}
if (!file.equals(getTodoFile()) && !file.equals(getLinkBoxFile()) && !file.equals(getQuickNoteFile())) {
setInt(PREF_PREFIX_EDIT_POS_CHAR + file.getAbsolutePath(), pos, _prefCache);
setInt(PREF_PREFIX_EDIT_POS_SCROLL + file.getAbsolutePath(), scrolloffset, _prefCache);
}
}

public int getLastEditPositionChar(File file) {
if (file == null || !file.exists()) {
return -1;
}
if (file.equals(getTodoFile()) || file.equals(getLinkBoxFile()) || file.equals(getQuickNoteFile())) {
return -2;
}
return getInt(PREF_PREFIX_EDIT_POS_CHAR + file.getAbsolutePath(), -3, _prefCache);
}

public int getLastEditPositionScroll(File file) {
if (file == null || !file.exists()) {
return 0;
}
return getInt(PREF_PREFIX_EDIT_POS_SCROLL + file.getAbsolutePath(), 0, _prefCache);
}

private List<String> getPopularDocumentsSorted() {
List<String> popular = getRecentDocuments();
Collections.sort(popular, new Comparator<String>() {
Expand Down

0 comments on commit fd2fa49

Please sign in to comment.