Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

TextEditingDelta support for iOS#28418

Merged
fluttergithubbot merged 119 commits intoflutter:masterfrom
Renzo-Olivares:text_editing_deltas_ios
Sep 16, 2021
Merged

TextEditingDelta support for iOS#28418
fluttergithubbot merged 119 commits intoflutter:masterfrom
Renzo-Olivares:text_editing_deltas_ios

Conversation

@Renzo-Olivares
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares commented Sep 2, 2021

Description

Design Doc

This change aims to collect the changes made to the editing value in the iOS text input plugin, and send them to the framework through a platform channel.

Framework PR: flutter/flutter#88477

Related Issues

Partially fixes flutter/flutter#87972

Tests

  • Added tests for FlutterTextEditingDelta verifying the creation of various deltas.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks super straightforward, identical to the Android approach except even simpler because no pending deltas, right? I'm on board, the only thing is the duplication of the FlutterTextEditingDelta class with the Android one that I mentioned in the comments. We should verify that it's not doable in Dart somehow if you haven't already.

@@ -0,0 +1,125 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be so nice if we could figure out a way to do this sort of stuff in Dart and not duplicate all of this logic and the tests for each platform, but I'm still not sure if it's really possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic that I was referring to has been moved to the framework since I last reviewed 🎉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas, it is Flutter's burden to carry. The more platform stuff we do, the less the developer has to worry as things will "just work"

[self setSelectedTextRangeLocal:[FlutterTextRange
rangeWithNSRange:[self clampSelection:selectedRange
forText:self.text]]];
_currentTextEditingDelta = [[FlutterTextEditingDelta alloc]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this here just for updating the selection etc. with an equality delta?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah an equality delta is one where no text has changed, but the selection and/or composing regions have potentially been updated, so here we just set the current delta to an equality one for a selection update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably need to release the current _currentTextEditingDelta object before you assign a new one?

if (_enableDeltaModel) {
[self updateEditingStateWithDelta];
} else {
NSLog(@"We should never be here");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over logs you can ignore them.

@Renzo-Olivares Renzo-Olivares force-pushed the text_editing_deltas_ios branch from 6df00c2 to 041dd40 Compare September 4, 2021 21:44
[self updateEditingState];

if (_enableDeltaModel) {
[self updateEditingStateWithDelta:[[FlutterTextEditingDelta alloc] initWithNonText:self.text]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new FlutterTextEditingDelta will leak if you don't autorelease it. You can either:

  1. change the initializer to be a static method with a different name that returns an autoreleased FlutterTextEditingDelta (new, alloc implies you own the object so the ref count is going to be +1).
  2. call autorelease every time you alloc a new FlutterTextEditingDelta.

Since the deltas are turned into json immediately I'd recommend approach 1.

newText:(NSString*)newTxt
deltaStart:(NSInteger)newStart
deltaEnd:(NSInteger)newEnd {
_oldText = oldText;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh since the delta objects are immediately turned into json, not claiming the ownership of these strings should be fine.

}

NSDictionary* deltaToFramework = @{
@"oldText" : [NSString stringWithString:delta.oldText],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are already copies I think? You should be able to directly use delta.oldText?

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter's text input plugin should report deltas instead of full text blocks

5 participants