Fcitx
surroundingtext.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_SURROUNDINGTEXT_H_
8 #define _FCITX_SURROUNDINGTEXT_H_
9 
10 #include <memory>
11 #include <string>
12 #include <fcitx-utils/log.h>
13 #include <fcitx-utils/macros.h>
14 #include "fcitxcore_export.h"
15 
16 /// \addtogroup FcitxCore
17 /// \{
18 /// \file
19 /// \brief Local cache for surrounding text
20 
21 namespace fcitx {
22 
23 class SurroundingTextPrivate;
24 
25 /**
26  * Class represents the current state of surrounding text of an input context.
27  */
28 class FCITXCORE_EXPORT SurroundingText {
29 public:
31  FCITX_DECLARE_VIRTUAL_DTOR_COPY_AND_MOVE(SurroundingText);
32 
33  /// Reset surrounding text to invalid state.
34  void invalidate();
35  /// Return whether surrounding text is valid.
36  bool isValid() const;
37  /// offset of anchor in character.
38  unsigned int anchor() const;
39  /// offset of anchor in character.
40  unsigned int cursor() const;
41  const std::string &text() const;
42  std::string selectedText() const;
43 
44  /**
45  * Set current of surrounding text.
46  *
47  * If cursor and anchor are out of range, it will be reset to invalid state.
48  *
49  * @param text text
50  * @param cursor offset of cursor in character.
51  * @param anchor offset of anchor in character.
52  */
53  void setText(const std::string &text, unsigned int cursor,
54  unsigned int anchor);
55 
56  /**
57  * Set current cursor and anchor of surrounding text.
58  *
59  * If cursor and anchor are out of range, it will be reset to invalid state.
60  * This function is useful to safe some bandwidth.
61  *
62  * @param cursor offset of cursor in character.
63  * @param anchor offset of anchor in character.
64  */
65  void setCursor(unsigned int cursor, unsigned int anchor);
66 
67  /**
68  * Delete surrounding text with offset and size.
69  *
70  * This can be used to update the local state of surrounding text before
71  * client send it back.
72  * @param offset offset to cursor position.
73  * @param size length of text to delete.
74  */
75  void deleteText(int offset, unsigned int size);
76 
77 private:
78  std::unique_ptr<SurroundingTextPrivate> d_ptr;
79  FCITX_DECLARE_PRIVATE(SurroundingText);
80 };
81 
82 FCITXCORE_EXPORT
83 LogMessageBuilder &operator<<(LogMessageBuilder &log,
84  const SurroundingText &surroundingText);
85 
86 } // namespace fcitx
87 
88 #endif // _FCITX_SURROUNDINGTEXT_H_
Definition: action.cpp:12
Class represents the current state of surrounding text of an input context.
Log utilities.