Refactoring

pull/214/head
M66B 2 years ago
parent b640fef6c3
commit 696c2a5c60

@ -111,8 +111,9 @@ public class EditTextCompose extends FixedEditText {
boolean undo_manager = prefs.getBoolean("undo_manager", false); boolean undo_manager = prefs.getBoolean("undo_manager", false);
addTextChangedListener(new TextWatcher() { addTextChangedListener(new TextWatcher() {
private Integer left; private Integer replace;
private Integer right; private Integer length;
private String what;
private boolean replacing = false; private boolean replacing = false;
@Override @Override
@ -128,29 +129,29 @@ public class EditTextCompose extends FixedEditText {
if (c == '>' && if (c == '>' &&
text.charAt(index - 1) == '-' && text.charAt(index - 1) == '-' &&
text.charAt(index - 2) == '-') { text.charAt(index - 2) == '-') {
left = index - 2; replace = index - 2;
length = 3;
what = "→";
} else if (c == '-' && } else if (c == '-' &&
text.charAt(index - 1) == '-' && text.charAt(index - 1) == '-' &&
text.charAt(index - 2) == '<') { text.charAt(index - 2) == '<') {
right = index - 2; replace = index - 2;
length = 3;
what = "←";
} }
} }
} }
@Override @Override
public void afterTextChanged(Editable text) { public void afterTextChanged(Editable text) {
if (!replacing && (left != null || right != null)) if (!replacing && replace != null)
try { try {
replacing = true; replacing = true;
if (left != null) text.replace(replace, replace + length, what);
text.replace(left, left + 3, "\u2192"); // ←
else if (right != null)
text.replace(right, right + 3, "\u2190"); // →
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} finally { } finally {
left = null; replace = null;
right = null;
replacing = false; replacing = false;
} }
} }

Loading…
Cancel
Save