Skip to content

Commit

Permalink
Fix various minor issues/crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Nov 4, 2024
1 parent 1d89d9d commit 38a0394
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private boolean runHighlight(final boolean recompute) {
private void updateHighlighting() {
if (runHighlight(false)) {
// Do not batch as we do not want to reflow
_hl.clearDynamic().applyDynamic(hlRegion());
_hl.clearDynamic().applyDynamic(hlRegion());
_oldHlRect.set(_hlRect);
}
}
Expand Down Expand Up @@ -692,7 +692,12 @@ public void draw(final Canvas canvas) {
final int count = layout.getLineCount();
final int offsetY = _editor.getPaddingTop();
for (; i < count; i++) {
final int start = layout.getLineStart(i);
int start;
try {
start = layout.getLineStart(i);
} catch (IndexOutOfBoundsException ex) {
break; // Even though the drawing is against count, might throw IndexOutOfBounds during drawing
}
if (start == 0 || text.charAt(start - 1) == '\n') {
final int y = layout.getLineBaseline(i);
if (y > _lineNumbersArea.bottom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public SyntaxHighlighterBase applyStatic() {

boolean hasStatic = false;
for (final SpanGroup group : _groups) {
if (group.isStatic) {
if (group != null && group.isStatic) {
hasStatic = true;
_spannable.setSpan(group.span, group.start, group.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public Map<File, File> getVirtualFolders() {
}

for (final File file : ContextCompat.getExternalFilesDirs(_context, null)) {
//noinspection DataFlowIssue
if (file == null || file.getParentFile() == null) {
continue;
}
final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + file.getParentFile().toString().replace("/", "-").substring(1) + ")");
map.put(remap, file);
}
Expand Down Expand Up @@ -750,7 +752,10 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl
}
}

if (folderChanged || modSumChanged || !newData.equals(_adapterData)) {
if (_recyclerView == null) {
//noinspection UnnecessaryReturnStatement
return;
} else if (folderChanged || modSumChanged || !newData.equals(_adapterData)) {
_recyclerView.post(() -> {
// Modify all these values in the UI thread
_adapterData.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ public void undo() {
final int end = start + (edit.after != null ? edit.after.length() : 0);

mIsUndoOrRedo = true;
text.replace(start, end, edit.before);
try {
text.replace(start, end, edit.before);
} catch (Exception ex){
// In case a undo would crash the app, don't do it instead
return;
}
mIsUndoOrRedo = false;

// This will get rid of underlines inserted when editor tries to come
Expand Down

0 comments on commit 38a0394

Please sign in to comment.