5package io.flutter.plugin.editing;
7import androidx.annotation.NonNull;
8import androidx.annotation.VisibleForTesting;
10import org.json.JSONException;
11import org.json.JSONObject;
16 private @NonNull CharSequence oldText;
17 private @NonNull CharSequence deltaText;
18 private int deltaStart;
20 private int newSelectionStart;
21 private int newSelectionEnd;
22 private int newComposingStart;
23 private int newComposingEnd;
25 private static final String TAG =
"TextEditingDelta";
28 @NonNull CharSequence oldEditable,
29 int replacementDestinationStart,
30 int replacementDestinationEnd,
31 @NonNull CharSequence replacementSource,
36 newSelectionStart = selectionStart;
37 newSelectionEnd = selectionEnd;
38 newComposingStart = composingStart;
39 newComposingEnd = composingEnd;
43 replacementSource.toString(),
44 replacementDestinationStart,
45 replacementDestinationEnd);
50 @NonNull CharSequence oldText,
55 newSelectionStart = selectionStart;
56 newSelectionEnd = selectionEnd;
57 newComposingStart = composingStart;
58 newComposingEnd = composingEnd;
60 setDeltas(oldText,
"", -1, -1);
87 return newSelectionStart;
92 return newSelectionEnd;
97 return newComposingStart;
102 return newComposingEnd;
105 private void setDeltas(
106 @NonNull CharSequence oldText, @NonNull CharSequence newText,
int newStart,
int newExtent) {
107 this.oldText = oldText;
109 deltaStart = newStart;
110 deltaEnd = newExtent;
115 JSONObject
delta =
new JSONObject();
118 delta.put(
"oldText", oldText.toString());
119 delta.put(
"deltaText", deltaText.toString());
120 delta.put(
"deltaStart", deltaStart);
121 delta.put(
"deltaEnd", deltaEnd);
122 delta.put(
"selectionBase", newSelectionStart);
123 delta.put(
"selectionExtent", newSelectionEnd);
124 delta.put(
"composingBase", newComposingStart);
125 delta.put(
"composingExtent", newComposingEnd);
126 }
catch (JSONException
e) {
127 Log.
e(
TAG,
"unable to create JSONObject: " +
e);
static void e(@NonNull String tag, @NonNull String message)
CharSequence getDeltaText()
int getNewSelectionStart()
CharSequence getOldText()
TextEditingDelta( @NonNull CharSequence oldText, int selectionStart, int selectionEnd, int composingStart, int composingEnd)
int getNewComposingStart()
TextEditingDelta( @NonNull CharSequence oldEditable, int replacementDestinationStart, int replacementDestinationEnd, @NonNull CharSequence replacementSource, int selectionStart, int selectionEnd, int composingStart, int composingEnd)