Skip to content

Commit

Permalink
Tweaks to selection handle after formating matrices. Yes, there are d…
Browse files Browse the repository at this point in the history
…ebug logs. Still buggy.
  • Loading branch information
Will Harmon committed Jul 15, 2015
1 parent da0af65 commit c8e2c39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Expand Up @@ -96,22 +96,34 @@ public int compare(MathSpannable a, MathSpannable b) {
// Start formatting, but skip the parts that involve spans
StringBuilder builder = new StringBuilder();

Log.d("TEST", "Parsing " + editable);
for (int i = 0; i < spans.length + 1; i++) {
int start = i == 0 ? 0 : s.getSpanEnd(spans[i - 1]);
int end = i == spans.length ? s.length() : s.getSpanStart(spans[i]);
Log.d("TEST", "I'm looking at the range " + start + " to " + end);

String text = editable.substring(start, end);
if (selectionHandle.intValue() >= start && selectionHandle.intValue() < end) {
Log.d("TEST", "I grabbed " + text);
Log.d("TEST", "My selection handle is " + selectionHandle);
boolean chunkBeforeSelectionHandle = end <= selectionHandle.intValue();
boolean selectionHandleInChunk = selectionHandle.intValue() >= start && selectionHandle.intValue() < end;
if (chunkBeforeSelectionHandle || selectionHandleInChunk) {
int length = Math.min(text.length(), selectionHandle.intValue() - start);
// Special case -- keep track of the selection handle
String cs = text.substring(0, selectionHandle.intValue() - start);
String cs = text.substring(0, length);
selectionHandle.subtract(TextUtil.countOccurrences(cs, getSolver().getBaseModule().getSeparator()));
text = formatText(removeFormatting(text), selectionHandle);
} else {
text = formatText(removeFormatting(text), selectionHandle);
}
text = formatText(removeFormatting(text), selectionHandle);
Log.d("TEST", "I formatted it to look like " + text);
builder.append(text);
if (i < spans.length) {
builder.append(spans[i].getEquation());
Log.d("TEST", "Adding my span too: " + spans[i].getEquation());
}
}
Log.d("TEST", "My end result is: " + builder.toString());

// Update the text with formatted (comas, etc) text
setText(Html.fromHtml(builder.toString()));
Expand Down
Expand Up @@ -239,14 +239,15 @@ protected String removeFormatting(String input) {
}

protected String formatText(String input, MutableInteger selectionHandle) {
int customHandle = input.indexOf(BaseModule.SELECTION_HANDLE);
if (customHandle >= 0) {
selectionHandle.set(customHandle);
input = input.replace(Character.toString(BaseModule.SELECTION_HANDLE), "");
}

if (mSolver != null) {
// Add grouping, and then split on the selection handle
// which is saved as a unique char
int customHandle = input.indexOf(BaseModule.SELECTION_HANDLE);
if (customHandle >= 0) {
selectionHandle.set(customHandle);
input = input.replace(Character.toString(BaseModule.SELECTION_HANDLE), "");
}
String grouped = mEquationFormatter.addComas(mSolver, input, selectionHandle.intValue());
if (grouped.contains(String.valueOf(BaseModule.SELECTION_HANDLE))) {
String[] temp = grouped.split(String.valueOf(BaseModule.SELECTION_HANDLE));
Expand All @@ -257,7 +258,6 @@ protected String formatText(String input, MutableInteger selectionHandle) {
}
} else {
input = grouped;
selectionHandle.set(input.length());
}
}

Expand All @@ -284,6 +284,10 @@ public MutableInteger(int value) {
this.value = value;
}

public MutableInteger(MutableInteger value) {
this.value = value.intValue();
}

public void set(int value) {
this.value = value;
}
Expand Down
Expand Up @@ -102,7 +102,7 @@ public MatrixSpannable(Context context, String equation) {
}
mBackground.getPadding(mBackgroundPadding);

mMinColumnWidth = mContext.getResources().getDisplayMetrics().density * 10;
mMinColumnWidth = mContext.getResources().getDisplayMetrics().density * 50;
}

private int getColumnSize(Paint paint, int column) {
Expand Down

0 comments on commit c8e2c39

Please sign in to comment.