[input][text] Slight rework of the new text edit API

Setting it up so that the work on its design can continue.

Change-Id: I7dcb96451748116ad68616dc965c616a5cbec978
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/692123
Reviewed-by: Konstantin Pozin <kpozin@google.com>
Reviewed-by: Alice Neels <neelsa@google.com>
API-Review: Alice Neels <neelsa@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Fuchsia-Auto-Submit: Filip Filmar <fmil@google.com>
diff --git a/sdk/fidl/fuchsia.input.text/text.fidl b/sdk/fidl/fuchsia.input.text/text.fidl
index 0f40266..695a09a 100644
--- a/sdk/fidl/fuchsia.input.text/text.fidl
+++ b/sdk/fidl/fuchsia.input.text/text.fidl
@@ -99,7 +99,11 @@
     /// Returns: A `TransactionId` that the text server must send in subsequent commands during this
     /// transaction.
     BeginTransaction(struct {
-        args BeginTransactionArgs;
+        /// The revision ID that the server believes to be current for the text field. Required.
+        ///
+        /// If this ID is out of date, then the server's view of the text field state is stale, so
+        /// the transaction must fail.
+        revision_id RevisionId;
     }) -> (struct {
         transaction_id TransactionId;
     }) error TextFieldError;
@@ -153,7 +157,11 @@
     /// `CompositionUpdate`s. If the user or the client cancels a composition, all edit transactions
     /// within it should be reverted.
     BeginComposition(struct {
-        args BeginCompositionArgs;
+        /// The revision ID that server believes to be current for the text field.
+        ///
+        /// If this ID is out of date, then the server's view of the text field state is stale, so
+        /// the composition must fail.
+        revision_id RevisionId;
     }) -> (struct {}) error TextFieldError;
 
     /// Commits the changes made so far in the transaction, updates the composition metdata, and
@@ -161,7 +169,10 @@
     ///
     /// This must be done inside a transaction, during a composition.
     CommitTransactionInComposition(struct {
-        args CommitCompositionInTransactionArgs;
+        transaction_id TransactionId;
+        ctic_options table {
+            1: composition_update CompositionUpdate;
+        };
     }) -> (struct {
         state TextFieldState;
     }) error TextFieldError;
@@ -183,28 +194,6 @@
     }) error TextFieldError;
 };
 
-type BeginTransactionArgs = table {
-    /// The revision ID that the server believes to be current for the text field. Required.
-    ///
-    /// If this ID is out of date, then the server's view of the text field state is stale, so
-    /// the transaction must fail.
-    1: revision_id RevisionId;
-};
-
-type BeginCompositionArgs = table {
-    /// The revision ID that server believes to be current for the text field.
-    ///
-    /// If this ID is out of date, then the server's view of the text field state is stale, so
-    /// the composition must fail.
-    1: revision_id RevisionId;
-};
-
-type CommitCompositionInTransactionArgs = table {
-    /// Required.
-    1: transaction_id TransactionId;
-    2: composition_update CompositionUpdate;
-};
-
 /// `TextField` represents an editable (usually) text widget inside a client application.
 protocol TextField {
     compose ReadableTextField;
diff --git a/src/ui/input/text/text-edit-controller/src/controller.rs b/src/ui/input/text/text-edit-controller/src/controller.rs
index 3f9c6b7..cc1b3110 100644
--- a/src/ui/input/text/text-edit-controller/src/controller.rs
+++ b/src/ui/input/text/text-edit-controller/src/controller.rs
@@ -103,10 +103,10 @@
                                 .map_err(Into::into);
                             responder.send(&mut result)?;
                         }
-                        BeginTransaction { args, responder } => {
+                        BeginTransaction { revision_id, responder } => {
                             let mut result = self_
                                 .clone()
-                                .begin_transaction(args.revision_id.as_ref())
+                                .begin_transaction(&revision_id)
                                 .await
                                 .map_err(Into::into);
                             responder.send(&mut result)?;
@@ -119,12 +119,16 @@
                                 .map_err(Into::into);
                             responder.send(&mut result)?;
                         }
-                        CommitTransactionInComposition { args, responder } => {
+                        CommitTransactionInComposition {
+                            transaction_id,
+                            ctic_options,
+                            responder,
+                        } => {
                             let mut result = self_
                                 .clone()
                                 .commit_transaction_in_composition(
-                                    args.transaction_id,
-                                    args.composition_update,
+                                    transaction_id,
+                                    ctic_options.composition_update,
                                 )
                                 .await
                                 .map_err(Into::into);
@@ -138,10 +142,10 @@
                                 .map_err(Into::into);
                             responder.send(&mut result)?;
                         }
-                        BeginComposition { args, responder } => {
+                        BeginComposition { revision_id, responder, .. } => {
                             let mut result = self_
                                 .clone()
-                                .begin_composition(args.revision_id.as_ref())
+                                .begin_composition(&revision_id)
                                 .await
                                 .map_err(Into::into);
                             responder.send(&mut result)?;
@@ -206,10 +210,8 @@
 
     async fn begin_transaction(
         self,
-        revision_id: Option<&ftext::RevisionId>,
+        revision_id: &ftext::RevisionId,
     ) -> Result<ftext::TransactionId, TextFieldError> {
-        let revision_id = revision_id
-            .ok_or_else(|| TextFieldError::BadRevisionId { expected: None, found: None })?;
         self.inner.lock().await.model.begin_transaction(revision_id)
     }
 
@@ -224,11 +226,9 @@
 
     async fn commit_transaction_in_composition(
         self,
-        transaction_id: Option<ftext::TransactionId>,
+        transaction_id: ftext::TransactionId,
         composition_update: Option<FidlCompositionUpdate>,
     ) -> Result<ftext::TextFieldState, TextFieldError> {
-        let transaction_id = transaction_id
-            .ok_or_else(|| TextFieldError::BadTransactionId { expected: None, found: None })?;
         let composition_update =
             composition_update.ok_or_else(|| TextFieldError::InvalidArgument)?.try_into()?;
         let model = &mut self.inner.lock().await.model;
@@ -247,10 +247,8 @@
 
     async fn begin_composition(
         self,
-        revision_id: Option<&ftext::RevisionId>,
+        revision_id: &ftext::RevisionId,
     ) -> Result<(), TextFieldError> {
-        let revision_id = revision_id
-            .ok_or_else(|| TextFieldError::BadRevisionId { expected: None, found: None })?;
         self.inner.lock().await.model.begin_composition(revision_id)
     }
 
@@ -521,14 +519,10 @@
             let fields = self.fields.lock().await;
             let state =
                 fields.get(&text_field).expect("registered field").state.as_ref().expect("state");
-            let revision_id = state.revision_id.as_ref().map(|x| x.clone()).expect("revision_id");
-            let mut transaction_id = text_field
-                .begin_transaction(ftext::BeginTransactionArgs {
-                    revision_id: Some(revision_id),
-                    ..ftext::BeginTransactionArgs::EMPTY
-                })
-                .await?
-                .to_anyhow_error()?;
+            let mut revision_id =
+                state.revision_id.as_ref().map(|x| x.clone()).expect("revision_id");
+            let mut transaction_id =
+                text_field.begin_transaction(&mut revision_id).await?.to_anyhow_error()?;
             let old_selection = state.selection.ok_or_else(|| format_err!("Missing selection"))?;
             let old_range = old_selection.into_range();
             match command {