Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
11#include "flutter/shell/platform/common/text_range.h"
12
13namespace 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 {
48 return old_text_ == rhs.old_text_ && delta_text_ == rhs.delta_text_ &&
49 delta_start_ == rhs.delta_start_ && delta_end_ == rhs.delta_end_;
50 }
51
52 bool operator!=(const TextEditingDelta& rhs) const { return !(*this == rhs); }
53
54 TextEditingDelta(const TextEditingDelta& other) = default;
55
57
58 private:
59 std::u16string old_text_;
60 std::u16string delta_text_;
61 int delta_start_;
62 int delta_end_;
63
64 void set_old_text(const std::u16string& old_text) { old_text_ = old_text; }
65
66 void set_delta_text(const std::u16string& delta_text) {
67 delta_text_ = delta_text;
68 }
69
70 void set_delta_start(int delta_start) { delta_start_ = delta_start; }
71
72 void set_delta_end(int delta_end) { delta_end_ = delta_end; }
73};
74
75} // namespace flutter
76
77#endif // FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
std::u16string text
std::string Utf16ToUtf8(const std::u16string_view string)
A change in the state of an input field.
bool operator==(const TextEditingDelta &rhs) const
std::string delta_text() const
int delta_start() const
Get the delta_start_ value.
virtual ~TextEditingDelta()=default
TextEditingDelta & operator=(const TextEditingDelta &other)=default
int delta_end() const
Get the delta_end_ value.
bool operator!=(const TextEditingDelta &rhs) const
TextEditingDelta(const TextEditingDelta &other)=default
std::string old_text() const