Flutter macOS Embedder
text_editing_delta.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
7 
8 #include <string>
9 
10 #include "flutter/fml/string_conversion.h"
12 
13 namespace flutter {
14 
15 /// A change in the state of an input field.
17  TextEditingDelta(const std::u16string& text_before_change,
18  const TextRange& range,
19  const std::u16string& text);
20 
21  TextEditingDelta(const std::string& text_before_change,
22  const TextRange& range,
23  const std::string& text);
24 
25  explicit TextEditingDelta(const std::u16string& text);
26 
27  explicit TextEditingDelta(const std::string& text);
28 
29  virtual ~TextEditingDelta() = default;
30 
31  /// Get the old_text_ value.
32  ///
33  /// All strings are stored as UTF16 but converted to UTF8 when accessed.
34  std::string old_text() const { return fml::Utf16ToUtf8(old_text_); }
35 
36  /// Get the delta_text value.
37  ///
38  /// All strings are stored as UTF16 but converted to UTF8 when accessed.
39  std::string delta_text() const { return fml::Utf16ToUtf8(delta_text_); }
40 
41  /// Get the delta_start_ value.
42  int delta_start() const { return delta_start_; }
43 
44  /// Get the delta_end_ value.
45  int delta_end() const { return delta_end_; }
46 
47  bool operator==(const TextEditingDelta& rhs) const = default;
48 
49  TextEditingDelta(const TextEditingDelta& other) = default;
50 
51  TextEditingDelta& operator=(const TextEditingDelta& other) = default;
52 
53  private:
54  std::u16string old_text_;
55  std::u16string delta_text_;
56  int delta_start_;
57  int delta_end_;
58 
59  void set_old_text(const std::u16string& old_text) { old_text_ = old_text; }
60 
61  void set_delta_text(const std::u16string& delta_text) {
62  delta_text_ = delta_text;
63  }
64 
65  void set_delta_start(int delta_start) { delta_start_ = delta_start; }
66 
67  void set_delta_end(int delta_end) { delta_end_ = delta_end; }
68 };
69 
70 } // namespace flutter
71 
72 #endif // FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
A change in the state of an input field.
std::string delta_text() const
bool operator==(const TextEditingDelta &rhs) const =default
int delta_start() const
Get the delta_start_ value.
virtual ~TextEditingDelta()=default
TextEditingDelta(const std::u16string &text_before_change, const TextRange &range, const std::u16string &text)
int delta_end() const
Get the delta_end_ value.
TextEditingDelta & operator=(const TextEditingDelta &other)=default
TextEditingDelta(const TextEditingDelta &other)=default
std::string old_text() const