-
Notifications
You must be signed in to change notification settings - Fork 6k
TextEditingDelta Support for the Web #28527
Changes from 1 commit
86885dd
9ef2c43
b93b043
d3201a1
9f99a66
8d69317
3ba145c
728055a
efbdf5b
1c330f3
0dd249a
37b757e
fd1396f
cb6ef96
4f610e0
f772bf1
f6e4d32
704d4f9
577aa59
0dcf1f2
a2e5525
95fe97b
5921215
a2a8b9d
1fbab86
928f186
03d63c3
51eabc8
125580e
26668cb
5a33dbf
e47a3ed
04020c2
13ca351
73c1411
be578c3
2df95b0
5e2b294
ac3407b
fa1d886
6ced401
15868f6
059fe74
26e676a
9196226
38bc244
cc0bb16
b7a91da
a600e9e
98fad47
786a528
3f260ce
b9db35a
41765f8
8ff4f2d
f4a858a
cbb6b6b
b596600
5a8a5f7
6645a0b
da90e99
6217ea9
b5e0b55
7a5aff9
c4c9cf6
9d97c88
0fc279d
fc823e9
6bf2ca7
acbc0de
7722380
0bb7f30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -457,7 +457,6 @@ class TextEditingDeltaState { | |
| TextEditingDeltaState({ | ||
| this.oldText = '', | ||
| this.deltaText = '', | ||
| this.inputType = '', | ||
| this.deltaStart = -1, | ||
| this.deltaEnd = -1, | ||
| this.baseOffset = -1, | ||
|
|
@@ -471,10 +470,15 @@ class TextEditingDeltaState { | |
|
|
||
| if (lastTextEditingDeltaState.deltaText.isEmpty && lastTextEditingDeltaState.deltaEnd != -1) { | ||
| // We are removing text. | ||
| // When text is deleted outside of the composing region or is cut using the native toolbar, | ||
| // we calculate the length of the deleted text by comparing the new and old editing state lengths. | ||
| // This value is then subtracted from the end position of the delta to capture the deleted range. | ||
| final int deletedLength = lastTextEditingDeltaState.oldText.length - newEditingState.text!.length; | ||
| lastTextEditingDeltaState.deltaStart = lastTextEditingDeltaState.deltaEnd - deletedLength; | ||
|
||
| } else if (lastTextEditingDeltaState.deltaText.isNotEmpty && !previousSelectionWasCollapsed) { | ||
| // We are replacing text at a selection. | ||
| // When a selection of text is replaced by a copy/paste operation we set the starting range | ||
| // of the delta to be the beginning of the selection of the previous editing state. | ||
| lastTextEditingDeltaState.deltaStart = lastEditingState!.baseOffset!; | ||
| } | ||
|
|
||
|
|
@@ -547,7 +551,6 @@ class TextEditingDeltaState { | |
|
|
||
| String oldText; | ||
| String deltaText; | ||
| String inputType; | ||
| int deltaStart; | ||
| int deltaEnd; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If empty strings and -1 are meaningful values for these fields, let's explain what they mean. Something tells me that the 3 fields above could be combined into a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think since the selection and composing region change when the text is mutated they should be together with |
||
| int baseOffset; | ||
|
|
@@ -1190,15 +1193,13 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy { | |
| final String? inputType = getJsProperty<void>(event, 'inputType') as String?; | ||
|
|
||
| if (inputType != null) { | ||
| editingDelta.inputType = inputType; | ||
|
|
||
| if (inputType.contains('delete')) { | ||
| // The deltaStart is set in handleChange because there is where we get access | ||
| // to the new selection baseOffset which is our new deltaStart. | ||
| editingDelta.deltaText = ''; | ||
| editingDelta.deltaEnd = lastEditingState!.extentOffset!; | ||
| } else if (inputType == 'insertLineBreak'){ | ||
| // event.data is null, so we manually set deltaText as a line break by setting it to '\n'. | ||
| // event.data is null on a line break, so we manually set deltaText as a line break by setting it to '\n'. | ||
| editingDelta.deltaText = '\n'; | ||
| editingDelta.deltaStart = lastEditingState!.extentOffset!; | ||
| editingDelta.deltaEnd = lastEditingState!.extentOffset!; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider extracting complex conditions into named variables. Less needs to be explained this way. E.g.: