Revisão | 03f84de68d102be02eecc03615b2dd3e6b266224 (tree) |
---|---|
Hora | 2017-10-22 23:10:20 |
Autor | <exeal@user...> |
Introduced kernel.DocumentAccess and kernel.PositionAccess meta-functions.
@@ -10,6 +10,7 @@ | ||
10 | 10 | #include <ascension/corelib/basic-exceptions.hpp> |
11 | 11 | #include <ascension/corelib/signals.hpp> |
12 | 12 | #include <ascension/direction.hpp> |
13 | +#include <ascension/kernel/access.hpp> | |
13 | 14 | |
14 | 15 | namespace ascension { |
15 | 16 | namespace kernel { |
@@ -0,0 +1,107 @@ | ||
1 | +/** | |
2 | + */ | |
3 | + | |
4 | +#ifndef ASCENSION_KERNEL_ACCESS_HPP | |
5 | +#define ASCENSION_KERNEL_ACCESS_HPP | |
6 | +#include <ascension/corelib/future/type-traits.hpp> | |
7 | +#include <ascension/kernel/position.hpp> | |
8 | + | |
9 | +namespace ascension { | |
10 | + namespace kernel { | |
11 | + class Document; | |
12 | + | |
13 | + /** | |
14 | + * Metafunction to access the document. | |
15 | + * @tparam T The document-related object type | |
16 | + */ | |
17 | + template<typename T> | |
18 | + struct DocumentAccess { | |
19 | + /** | |
20 | + * Returns the document of the given document-related object. | |
21 | + * @param object The object to query | |
22 | + * @return The document | |
23 | + */ | |
24 | + static auto get(T& object) BOOST_NOEXCEPT -> decltype(object.document()) { | |
25 | + return object.document(); | |
26 | + } | |
27 | + }; | |
28 | + | |
29 | + /** | |
30 | + * Metafunction to access the position. | |
31 | + * @tparam T The object type | |
32 | + */ | |
33 | + template<typename T> | |
34 | + struct PositionAccess { | |
35 | + /** | |
36 | + * Returns the position value of the given positional object. | |
37 | + * @param p The positional object | |
38 | + * @return The position value | |
39 | + */ | |
40 | + static inline auto get(T& p) BOOST_NOEXCEPT -> decltype(p.position()) { | |
41 | + return p.position(); | |
42 | + } | |
43 | + }; | |
44 | + | |
45 | + template<> | |
46 | + struct PositionAccess<Position> { | |
47 | + static Position& get(Position& p) BOOST_NOEXCEPT { | |
48 | + return p; | |
49 | + } | |
50 | + }; | |
51 | + | |
52 | + template<> | |
53 | + struct PositionAccess<const Position> { | |
54 | + static const Position& get(const Position& p) BOOST_NOEXCEPT { | |
55 | + return p; | |
56 | + } | |
57 | + }; | |
58 | + | |
59 | + /** | |
60 | + * Returns the document of the given document-related object. | |
61 | + * @tparam T The type of @a object | |
62 | + * @param object The object to query | |
63 | + * @return A reference to the document | |
64 | + */ | |
65 | + template<typename T> | |
66 | + inline auto document(T& object) BOOST_NOEXCEPT -> decltype(DocumentAccess<T>::get(object)) { | |
67 | + return DocumentAccess<T>::get(object); | |
68 | + } | |
69 | + | |
70 | + /** | |
71 | + * Returns the position value of the given positional object. | |
72 | + * @tparam T The type of @a p | |
73 | + * @param p The positional object | |
74 | + * @return The position value | |
75 | + */ | |
76 | + template<typename T> | |
77 | + inline auto position(T& p) BOOST_NOEXCEPT -> decltype(PositionAccess<T>::get(p)) { | |
78 | + return PositionAccess<T>::get(p); | |
79 | + } | |
80 | + | |
81 | + /** | |
82 | + * Returns the line number of the given positional object. | |
83 | + * @tparam T The type of @a p. This should be able to pass to @c position function | |
84 | + * @param p The positional object | |
85 | + * @return The line number. Not a reference | |
86 | + */ | |
87 | + template<typename T> | |
88 | + BOOST_CONSTEXPR inline Index line(const T& p) BOOST_NOEXCEPT { | |
89 | + return position(p).line; | |
90 | + } | |
91 | + | |
92 | + /** | |
93 | + * Returns the offset in the line of the given positional object. | |
94 | + * @tparam T The type of @a p. This should be able to pass to @c position function | |
95 | + * @param p The positional object | |
96 | + * @return The offset in the line. Not a reference | |
97 | + */ | |
98 | + template<typename T> | |
99 | + BOOST_CONSTEXPR inline Index offsetInLine(const T& p) BOOST_NOEXCEPT { | |
100 | + return position(p).offsetInLine; | |
101 | + } | |
102 | + | |
103 | + /// @} | |
104 | + } | |
105 | +} | |
106 | + | |
107 | +#endif // !ASCENSION_KERNEL_ACCESS_HPP |
@@ -103,10 +103,12 @@ | ||
103 | 103 | return position_; |
104 | 104 | } |
105 | 105 | |
106 | - /// @overload | |
107 | - inline const Position& position(const DocumentCharacterIterator& i) BOOST_NOEXCEPT { | |
108 | - return i.tell(); | |
109 | - } | |
106 | + template<> | |
107 | + struct PositionAccess<const DocumentCharacterIterator> { | |
108 | + static const Position& get(const DocumentCharacterIterator& i) BOOST_NOEXCEPT { | |
109 | + return i.tell(); | |
110 | + } | |
111 | + }; | |
110 | 112 | } |
111 | 113 | } // namespace ascension.kernel |
112 | 114 |
@@ -529,12 +529,14 @@ | ||
529 | 529 | |
530 | 530 | /** |
531 | 531 | * Returns the content type of the partition contains the specified position. |
532 | + * @tparam The type of @a p (@c locations#PointProxy) | |
532 | 533 | * @param p The position in the document |
533 | 534 | * @throw ... Any exception thrown by @c DocumentPartitioner#contentType method |
534 | 535 | * @return The content type |
535 | 536 | */ |
536 | - inline ContentType contentType(const std::pair<const Document&, Position>& p) { | |
537 | - return std::get<0>(p).partitioner().contentType(std::get<1>(p)); | |
537 | + template<typename T> | |
538 | + inline ContentType contentType(const T& p) { | |
539 | + return document(p).partitioner().contentType(position(p)); | |
538 | 540 | } |
539 | 541 | |
540 | 542 | /** |
@@ -566,8 +568,9 @@ | ||
566 | 568 | |
567 | 569 | namespace detail { |
568 | 570 | /// @internal Returns the @c text#IdentifierSyntax object corresponds to the given point. |
569 | - inline const text::IdentifierSyntax& identifierSyntax(const std::pair<const Document&, Position>& p) { | |
570 | - return std::get<0>(p).contentTypeInformation().getIdentifierSyntax(contentType(p)); | |
571 | + template<typename T> | |
572 | + inline const text::IdentifierSyntax& identifierSyntax(const T& p) { | |
573 | + return document(p).contentTypeInformation().getIdentifierSyntax(contentType(p)); | |
571 | 574 | } |
572 | 575 | } |
573 | 576 | } |
@@ -35,21 +35,7 @@ | ||
35 | 35 | GLYPH_CLUSTER ///< A glyph is a character (not implemented). |
36 | 36 | }; |
37 | 37 | |
38 | - /** | |
39 | - * Describes a position in the document. | |
40 | - * @see viewer#locations#PointProxy | |
41 | - */ | |
42 | - typedef std::pair<const Document&, Position> PointProxy; | |
43 | - | |
44 | - /** | |
45 | - * Returns a @c PointProxy from the given document and position. | |
46 | - * @param document The document | |
47 | - * @param position The position | |
48 | - * @return A @c PointProxy | |
49 | - */ | |
50 | - inline PointProxy makePointProxy(const Document& document, const Position& position) BOOST_NOEXCEPT { | |
51 | - return std::make_pair(std::ref(document), position); | |
52 | - } | |
38 | + struct PointProxy; | |
53 | 39 | |
54 | 40 | /// @defgroup special_locations_in_document Special Locations in Document |
55 | 41 | /// Free functions related to special locations. |
@@ -0,0 +1,50 @@ | ||
1 | +/** | |
2 | + * @file kernel/point-proxy.hpp | |
3 | + * Defines @c kernel#locations#PointProxy class. | |
4 | + * @author exeal | |
5 | + * @date 2017-10-17 Separated from visual-locations.hpp. | |
6 | + * @see kernel/point-proxy.hpp | |
7 | + */ | |
8 | + | |
9 | +#ifndef ASCENSION_KERNEL_POINT_PROXY_HPP | |
10 | +#define ASCENSION_KERNEL_POINT_PROXY_HPP | |
11 | +#include <ascension/kernel/access.hpp> | |
12 | + | |
13 | +namespace ascension { | |
14 | + namespace kernel { | |
15 | + class Document; | |
16 | + | |
17 | + namespace locations { | |
18 | + /** | |
19 | + * Describes a position in the document. | |
20 | + * @see viewer#locations#PointProxy | |
21 | + */ | |
22 | + struct PointProxy { | |
23 | + /// The document. | |
24 | + const Document& document; | |
25 | + /// The position. | |
26 | + const Position position; | |
27 | + /// Creates a @c PointProxy instance. | |
28 | + PointProxy(const Document& document, const Position& position) BOOST_NOEXCEPT : document(document), position(position) {} | |
29 | + /// Returns a reference to @c #position. | |
30 | + operator const Position&() const BOOST_NOEXCEPT {return position;} | |
31 | + }; | |
32 | + } | |
33 | + | |
34 | + template<> | |
35 | + struct DocumentAccess<const locations::PointProxy> { | |
36 | + static const Document& get(const locations::PointProxy& p) BOOST_NOEXCEPT { | |
37 | + return p.document; | |
38 | + } | |
39 | + }; | |
40 | + | |
41 | + template<> | |
42 | + struct PositionAccess<const locations::PointProxy> { | |
43 | + static const Position& get(const locations::PointProxy& p) BOOST_NOEXCEPT { | |
44 | + return p.position; | |
45 | + } | |
46 | + }; | |
47 | + } | |
48 | +} | |
49 | + | |
50 | +#endif // !ASCENSION_KERNEL_POINT_PROXY_HPP |
@@ -7,7 +7,7 @@ | ||
7 | 7 | #ifndef ASCENSION_KERNEL_POINT_HPP |
8 | 8 | #define ASCENSION_KERNEL_POINT_HPP |
9 | 9 | #include <ascension/kernel/abstract-point.hpp> |
10 | -#include <ascension/kernel/position.hpp> | |
10 | +#include <ascension/kernel/point-proxy.hpp> | |
11 | 11 | #include <boost/operators.hpp> |
12 | 12 | |
13 | 13 | namespace ascension { |
@@ -19,7 +19,7 @@ | ||
19 | 19 | explicit Point(Document& document, const Position& position = kernel::Position::zero()); |
20 | 20 | Point(const Point& other); |
21 | 21 | virtual ~Point() BOOST_NOEXCEPT; |
22 | - operator std::pair<const Document&, Position>() const; | |
22 | + operator locations::PointProxy() const; | |
23 | 23 | |
24 | 24 | /// @name Core Attribute |
25 | 25 | const Position& position() const BOOST_NOEXCEPT; |
@@ -60,17 +60,12 @@ | ||
60 | 60 | return lhs.position() < rhs.position(); |
61 | 61 | } |
62 | 62 | |
63 | - /// @overload | |
64 | - inline const Position& position(const Point& p) BOOST_NOEXCEPT { | |
65 | - return p.position(); | |
66 | - } | |
67 | - | |
68 | 63 | |
69 | 64 | // Point method inline implementation ///////////////////////////////////////////////////// |
70 | 65 | |
71 | 66 | /// Conversion operator for convenience. |
72 | - inline Point::operator std::pair<const Document&, Position>() const { | |
73 | - return std::make_pair(std::ref(document()), position()); | |
67 | + inline Point::operator locations::PointProxy() const { | |
68 | + return locations::PointProxy(document(), position()); | |
74 | 69 | } |
75 | 70 | |
76 | 71 | /** |
@@ -112,40 +112,6 @@ | ||
112 | 112 | private: |
113 | 113 | const boost::optional<Position> requestedPosition_; |
114 | 114 | }; |
115 | - | |
116 | - /// @defgroup position_accessors Position Accessors | |
117 | - /// @{ | |
118 | - /** | |
119 | - * Returns the line number of the given positional object. | |
120 | - * @tparam T The type of @a p. This should be able to pass to @c position function | |
121 | - * @param p The positional object | |
122 | - * @return The line number | |
123 | - */ | |
124 | - template<typename T> | |
125 | - BOOST_CONSTEXPR inline Index line(const T& p) BOOST_NOEXCEPT { | |
126 | - return position(p).line; | |
127 | - } | |
128 | - | |
129 | - /** | |
130 | - * Returns the offset in the line of the given positional object. | |
131 | - * @tparam T The type of @a p. This should be able to pass to @c position function | |
132 | - * @param p The positional object | |
133 | - * @return The offset in the line | |
134 | - */ | |
135 | - template<typename T> | |
136 | - BOOST_CONSTEXPR inline Index offsetInLine(const T& p) BOOST_NOEXCEPT { | |
137 | - return position(p).offsetInLine; | |
138 | - } | |
139 | - | |
140 | - /** | |
141 | - * Returns the position value of the given positional object. | |
142 | - * @param p The positional object | |
143 | - * @return The position value | |
144 | - */ | |
145 | - inline const Position& position(const Position& p) BOOST_NOEXCEPT { | |
146 | - return p; | |
147 | - } | |
148 | - /// @} | |
149 | 115 | } |
150 | 116 | } // namespace ascension.kernel |
151 | 117 |
@@ -7,7 +7,7 @@ | ||
7 | 7 | |
8 | 8 | #ifndef ASCENSION_REGION_HPP |
9 | 9 | #define ASCENSION_REGION_HPP |
10 | -#include <ascension/kernel/position.hpp> | |
10 | +#include <ascension/kernel/access.hpp> | |
11 | 11 | #include <boost/range/irange.hpp> |
12 | 12 | #include <utility> // std.max, std.min, std.pair, std.swap |
13 | 13 |
@@ -13,6 +13,7 @@ | ||
13 | 13 | #include <ascension/corelib/text/newline.hpp> |
14 | 14 | #include <ascension/kernel/document-observers.hpp> |
15 | 15 | #include <ascension/viewer/caret-painter.hpp> |
16 | +#include <ascension/viewer/point-proxy.hpp> | |
16 | 17 | #include <ascension/viewer/selected-region.hpp> |
17 | 18 | #include <ascension/viewer/visual-point.hpp> |
18 | 19 | #include <ascension/viewer/detail/input-method.hpp> |
@@ -78,10 +79,10 @@ | ||
78 | 79 | |
79 | 80 | /// @name The Anchor and The Caret |
80 | 81 | /// @{ |
81 | - const VisualPoint& anchor() const BOOST_NOEXCEPT; | |
82 | - const VisualPoint& beginning() const BOOST_NOEXCEPT; | |
82 | + locations::PointProxy anchor() const BOOST_NOEXCEPT; | |
83 | + locations::PointProxy beginning() const BOOST_NOEXCEPT; | |
83 | 84 | Caret& enableAutoShow(bool enable = true) BOOST_NOEXCEPT; |
84 | - const VisualPoint& end() const BOOST_NOEXCEPT; | |
85 | + locations::PointProxy end() const BOOST_NOEXCEPT; | |
85 | 86 | bool isAutoShowEnabled() const BOOST_NOEXCEPT; |
86 | 87 | /// @} |
87 | 88 |
@@ -311,11 +312,13 @@ | ||
311 | 312 | // inline implementations ///////////////////////////////////////////////////////////////// |
312 | 313 | |
313 | 314 | /// Returns the anchor of the selection. |
314 | - inline const VisualPoint& Caret::anchor() const BOOST_NOEXCEPT {return *anchor_;} | |
315 | + inline locations::PointProxy Caret::anchor() const BOOST_NOEXCEPT { | |
316 | + return locations::PointProxy(textArea(), boost::get_optional_value_or(anchor_, hit())); | |
317 | + } | |
315 | 318 | |
316 | 319 | /// Returns the neighborhood to the beginning of the document among the anchor and this point. |
317 | - inline const VisualPoint& Caret::beginning() const BOOST_NOEXCEPT { | |
318 | - return std::min(static_cast<const VisualPoint&>(*this), static_cast<const VisualPoint&>(*anchor_)); | |
320 | + inline locations::PointProxy Caret::beginning() const BOOST_NOEXCEPT { | |
321 | + return locations::PointProxy(textArea(), std::min(hit(), anchor().hit)); | |
319 | 322 | } |
320 | 323 | |
321 | 324 | /** |
@@ -341,8 +344,8 @@ | ||
341 | 344 | } |
342 | 345 | |
343 | 346 | /// Returns the neighborhood to the end of the document among the anchor and this point. |
344 | - inline const VisualPoint& Caret::end() const BOOST_NOEXCEPT { | |
345 | - return std::max(static_cast<const VisualPoint&>(*this), static_cast<const VisualPoint&>(*anchor_)); | |
347 | + inline locations::PointProxy Caret::end() const BOOST_NOEXCEPT { | |
348 | + return locations::PointProxy(textArea(), std::max(hit(), anchor().hit)); | |
346 | 349 | } |
347 | 350 | |
348 | 351 | /// Returns @c true if the point will be shown automatically when moved. Default is @c true. |
@@ -426,6 +429,34 @@ | ||
426 | 429 | } // namespace viewer |
427 | 430 | |
428 | 431 | namespace kernel { |
432 | + template<> | |
433 | + struct DocumentAccess<viewer::Caret> { | |
434 | + static Document& get(viewer::Caret& p) BOOST_NOEXCEPT { | |
435 | + return p.document(); | |
436 | + } | |
437 | + }; | |
438 | + | |
439 | + template<> | |
440 | + struct PositionAccess<viewer::Caret> { | |
441 | + static Position get(viewer::Caret& p) BOOST_NOEXCEPT { | |
442 | + return viewer::insertionPosition(p); | |
443 | + } | |
444 | + }; | |
445 | + | |
446 | + template<> | |
447 | + struct DocumentAccess<const viewer::Caret> { | |
448 | + static const Document& get(const viewer::Caret& p) BOOST_NOEXCEPT { | |
449 | + return p.document(); | |
450 | + } | |
451 | + }; | |
452 | + | |
453 | + template<> | |
454 | + struct PositionAccess<const viewer::Caret> { | |
455 | + static Position get(const viewer::Caret& p) BOOST_NOEXCEPT { | |
456 | + return viewer::insertionPosition(p); | |
457 | + } | |
458 | + }; | |
459 | + | |
429 | 460 | /** |
430 | 461 | * @overload |
431 | 462 | * @note There is no @c offsetInLine for @c viewer#Caret. |
@@ -0,0 +1,50 @@ | ||
1 | +/** | |
2 | + * @file viewer/point-proxy.hpp | |
3 | + * Defines @c viewer#locations#PointProxy class. | |
4 | + * @author exeal | |
5 | + * @date 2017-10-17 Separated from visual-locations.hpp. | |
6 | + * @see kernel/point-proxy.hpp | |
7 | + */ | |
8 | + | |
9 | +#ifndef ASCENSION_VIEWER_POINT_PROXY_HPP | |
10 | +#define ASCENSION_VIEWER_POINT_PROXY_HPP | |
11 | +#include <ascension/kernel/point-proxy.hpp> | |
12 | +#include <ascension/viewer/text-hit.hpp> | |
13 | + | |
14 | +namespace ascension { | |
15 | + namespace viewer { | |
16 | + class TextArea; | |
17 | + | |
18 | + namespace locations { | |
19 | + /** | |
20 | + * Describes a position in the @c TextArea. | |
21 | + * @see kernel#locations#PointProxy | |
22 | + */ | |
23 | + struct PointProxy { | |
24 | + /// The text area. | |
25 | + const TextArea& textArea; | |
26 | + /// The text hit. | |
27 | + const TextHit hit; | |
28 | + /// Creates a @c PointProxy instance. | |
29 | + PointProxy(const TextArea& textArea, const TextHit& hit) BOOST_NOEXCEPT : textArea(textArea), hit(hit) {} | |
30 | + /// Returns a reference to @c #hit. | |
31 | + operator const TextHit&() const BOOST_NOEXCEPT {return hit;} | |
32 | + }; | |
33 | + } | |
34 | + | |
35 | + kernel::locations::PointProxy insertionPosition(const locations::PointProxy& p); | |
36 | + } | |
37 | + | |
38 | + namespace kernel { | |
39 | + template<> | |
40 | + struct DocumentAccess<const viewer::locations::PointProxy> { | |
41 | + static std::shared_ptr<const Document> get(const viewer::locations::PointProxy& p) BOOST_NOEXCEPT; | |
42 | + }; | |
43 | + template<> | |
44 | + struct PositionAccess<const viewer::locations::PointProxy> { | |
45 | + static Position get(const viewer::locations::PointProxy& p) BOOST_NOEXCEPT; | |
46 | + }; | |
47 | + } | |
48 | +} | |
49 | + | |
50 | +#endif // !ASCENSION_VIEWER_POINT_PROXY_HPP |
@@ -12,6 +12,7 @@ | ||
12 | 12 | #include <ascension/graphics/font/text-renderer.hpp> |
13 | 13 | #include <ascension/graphics/font/text-viewport-base.hpp> |
14 | 14 | #include <ascension/graphics/font/visual-lines-listener.hpp> |
15 | +#include <ascension/kernel/access.hpp> | |
15 | 16 | #include <ascension/kernel/document-observers.hpp> |
16 | 17 | #include <ascension/presentation/flow-relative-two-axes.hpp> |
17 | 18 | #include <ascension/viewer/detail/weak-reference-for-points.hpp> |
@@ -158,12 +159,6 @@ | ||
158 | 159 | caretMotionConnection_, defaultFontChangedConnection_, matchBracketsChangedConnection_, selectionShapeChangedConnection_; |
159 | 160 | }; |
160 | 161 | |
161 | - /// @addtogroup shortcuts_to_main_objects | |
162 | - /// @{ | |
163 | - kernel::Document& document(TextArea& textArea); | |
164 | - const kernel::Document& document(const TextArea& textArea); | |
165 | - /// @} | |
166 | - | |
167 | 162 | |
168 | 163 | /// Returns the caret, or @c nullptr if not installed. |
169 | 164 | inline std::shared_ptr<Caret> TextArea::caret() BOOST_NOEXCEPT { |
@@ -205,6 +200,17 @@ | ||
205 | 200 | return viewport_; |
206 | 201 | } |
207 | 202 | } |
203 | + | |
204 | + namespace kernel { | |
205 | + template<> | |
206 | + struct DocumentAccess<viewer::TextArea> { | |
207 | + static std::shared_ptr<Document> get(viewer::TextArea& textArea) BOOST_NOEXCEPT; | |
208 | + }; | |
209 | + template<> | |
210 | + struct DocumentAccess<const viewer::TextArea> { | |
211 | + static std::shared_ptr<const Document> get(const viewer::TextArea& textArea) BOOST_NOEXCEPT; | |
212 | + }; | |
213 | + } | |
208 | 214 | } |
209 | 215 | |
210 | 216 | #endif // !ASCENSION_TEXT_AREA_HPP |
@@ -18,9 +18,17 @@ | ||
18 | 18 | namespace ascension { |
19 | 19 | namespace kernel { |
20 | 20 | class Document; |
21 | + | |
22 | + namespace locations { | |
23 | + struct PointProxy; | |
24 | + } | |
21 | 25 | } |
22 | 26 | |
23 | 27 | namespace viewer { |
28 | + namespace locations { | |
29 | + struct PointProxy; | |
30 | + } | |
31 | + | |
24 | 32 | /** |
25 | 33 | * Used by procedures which move @c VisualPoint. |
26 | 34 | * @see graphics#font#TextHit |
@@ -30,11 +30,7 @@ | ||
30 | 30 | * @see kernel#locations |
31 | 31 | */ |
32 | 32 | namespace locations { |
33 | - /** | |
34 | - * Describes a position in the @c TextArea. | |
35 | - * @see kernel#locations#PointProxy | |
36 | - */ | |
37 | - typedef std::pair<const TextArea&, TextHit> PointProxy; | |
33 | + struct PointProxy; | |
38 | 34 | |
39 | 35 | /// @defgroup special_locations_in_text_area Special Locations in Text Area |
40 | 36 | /// Free functions related to special locations in @c TextArea. |
@@ -58,10 +54,10 @@ | ||
58 | 54 | TextHit lastPrintableCharacterOfVisualLine(const PointProxy& p); |
59 | 55 | /// @} |
60 | 56 | |
61 | -#ifdef ASCENSION_ABANDONED_AT_VERSION_08 | |
62 | 57 | /// @defgroup motions_in_text_area Motions in Text Area |
63 | 58 | /// @note All functions are *affected* by accessible region of the document. |
64 | 59 | /// @{ |
60 | +#ifdef ASCENSION_ABANDONED_AT_VERSION_08 | |
65 | 61 | viewer::VisualDestinationProxy backwardPage(const PointProxy& p, Index pages = 1); |
66 | 62 | viewer::VisualDestinationProxy backwardVisualLine(const PointProxy& p, Index lines = 1); |
67 | 63 | viewer::VisualDestinationProxy forwardPage(const PointProxy& p, Index pages = 1); |
@@ -74,12 +70,12 @@ | ||
74 | 70 | const VisualPoint& p, CharacterUnit unit, Index characters = 1); |
75 | 71 | boost::optional<Position> rightWord(const PointProxy& p, Index words = 1); |
76 | 72 | boost::optional<Position> rightWordEnd(const PointProxy& p, Index words = 1); |
73 | +#endif // ASCENSION_ABANDONED_AT_VERSION_08 | |
77 | 74 | /// @} |
78 | -#endif // ASCENSION_ABANDONED_AT_VERSION_08 | |
79 | 75 | |
80 | 76 | /// @defgroup miscellaneous_visual_locational_functions Miscellaneous Visual Locational Functions |
81 | 77 | /// @{ |
82 | - TextHit updateTextHit(const TextHit& position, const kernel::DocumentChange& change, Direction gravity) BOOST_NOEXCEPT; | |
78 | + TextHit updateTextHit(const TextHit& hit, const kernel::Document& document, const kernel::DocumentChange& change, Direction gravity); | |
83 | 79 | /// @} |
84 | 80 | } |
85 | 81 | } |
@@ -12,10 +12,12 @@ | ||
12 | 12 | #ifndef ASCENSION_VISUAL_POINT_HPP |
13 | 13 | #define ASCENSION_VISUAL_POINT_HPP |
14 | 14 | #include <ascension/kernel/point.hpp> |
15 | +#include <ascension/kernel/point-proxy.hpp> | |
15 | 16 | #include <ascension/graphics/font/visual-line.hpp> |
16 | 17 | #include <ascension/graphics/font/visual-lines-listener.hpp> |
17 | 18 | #include <ascension/graphics/geometry/point.hpp> |
18 | 19 | #include <ascension/viewer/detail/weak-reference-for-points.hpp> |
20 | +#include <ascension/viewer/point-proxy.hpp> | |
19 | 21 | #include <ascension/viewer/visual-destination-proxy.hpp> |
20 | 22 | |
21 | 23 | namespace ascension { |
@@ -67,8 +69,8 @@ | ||
67 | 69 | explicit VisualPoint(const graphics::font::TextHit<kernel::Point>& other); |
68 | 70 | VisualPoint(const VisualPoint& other); |
69 | 71 | virtual ~VisualPoint() BOOST_NOEXCEPT; |
70 | - operator std::pair<const kernel::Document&, kernel::Position>() const; | |
71 | - operator std::pair<const TextArea&, TextHit>() const; | |
72 | + operator kernel::locations::PointProxy() const; | |
73 | + operator locations::PointProxy() const; | |
72 | 74 | |
73 | 75 | /// @name Installation |
74 | 76 | /// @{ |
@@ -155,13 +157,13 @@ | ||
155 | 157 | } |
156 | 158 | |
157 | 159 | /// Conversion operator into @c kernel#locations#PointProyx. |
158 | - inline VisualPoint::operator std::pair<const kernel::Document&, kernel::Position>() const { | |
159 | - return std::make_pair(std::ref(document()), insertionPosition(*this)); | |
160 | + inline VisualPoint::operator kernel::locations::PointProxy() const { | |
161 | + return kernel::locations::PointProxy(document(), insertionPosition(*this)); | |
160 | 162 | } |
161 | 163 | |
162 | 164 | /// Conversion operator into @c viewer#locations#PointProxy. |
163 | - inline VisualPoint::operator std::pair<const TextArea&, TextHit>() const { | |
164 | - return std::make_pair(std::ref(textArea()), hit()); | |
165 | + inline VisualPoint::operator locations::PointProxy() const { | |
166 | + return locations::PointProxy(textArea(), hit()); | |
165 | 167 | } |
166 | 168 | |
167 | 169 | /** |
@@ -256,6 +258,34 @@ | ||
256 | 258 | } // namespace viewer |
257 | 259 | |
258 | 260 | namespace kernel { |
261 | + template<> | |
262 | + struct DocumentAccess<viewer::VisualPoint> { | |
263 | + static Document& get(viewer::VisualPoint& p) BOOST_NOEXCEPT { | |
264 | + return p.document(); | |
265 | + } | |
266 | + }; | |
267 | + | |
268 | + template<> | |
269 | + struct DocumentAccess<const viewer::VisualPoint> { | |
270 | + static const Document& get(const viewer::VisualPoint& p) BOOST_NOEXCEPT { | |
271 | + return p.document(); | |
272 | + } | |
273 | + }; | |
274 | + | |
275 | + template<> | |
276 | + struct PositionAccess<viewer::VisualPoint> { | |
277 | + static Position get(viewer::VisualPoint& p) BOOST_NOEXCEPT { | |
278 | + return viewer::insertionPosition(p); | |
279 | + } | |
280 | + }; | |
281 | + | |
282 | + template<> | |
283 | + struct PositionAccess<const viewer::VisualPoint> { | |
284 | + static Position get(const viewer::VisualPoint& p) BOOST_NOEXCEPT { | |
285 | + return viewer::insertionPosition(p); | |
286 | + } | |
287 | + }; | |
288 | + | |
259 | 289 | /** |
260 | 290 | * @overload |
261 | 291 | * @note There is no @c offsetInLine for @c viewer#VisualPoint. |
@@ -15,6 +15,7 @@ | ||
15 | 15 | #include <ascension/kernel/document.hpp> |
16 | 16 | #include <ascension/kernel/document-character-iterator.hpp> |
17 | 17 | #include <ascension/kernel/locations.hpp> |
18 | +#include <ascension/kernel/point-proxy.hpp> | |
18 | 19 | #include <boost/core/ignore_unused.hpp> |
19 | 20 | |
20 | 21 |
@@ -23,20 +24,6 @@ | ||
23 | 24 | namespace locations { |
24 | 25 | namespace { |
25 | 26 | template<typename T> |
26 | - inline const Document& document(const T& p) BOOST_NOEXCEPT { | |
27 | - return std::get<0>(p); | |
28 | - } | |
29 | - template<typename T> | |
30 | - inline const Position& position(const T& p) BOOST_NOEXCEPT { | |
31 | - return std::get<1>(p); | |
32 | - } | |
33 | - inline Index line(const PointProxy& p) BOOST_NOEXCEPT { | |
34 | - return kernel::line(position(p)); | |
35 | - } | |
36 | - inline Index offsetInLine(const PointProxy& p) BOOST_NOEXCEPT { | |
37 | - return kernel::offsetInLine(position(p)); | |
38 | - } | |
39 | - template<typename T> | |
40 | 27 | inline void throwIfOutsideOfDocument(const T& p) { |
41 | 28 | if(isOutsideOfDocumentRegion(p)) |
42 | 29 | throw BadPositionException(position(p)); |
@@ -89,7 +76,7 @@ | ||
89 | 76 | */ |
90 | 77 | Position beginningOfLine(const PointProxy& p) { |
91 | 78 | throwIfOutsideOfDocument(p); |
92 | - return shrinkToAccessibleRegion(makePointProxy(document(p), Position::bol(position(p)))); | |
79 | + return shrinkToAccessibleRegion(PointProxy(document(p), Position::bol(position(p)))); | |
93 | 80 | } |
94 | 81 | |
95 | 82 | /** |
@@ -124,7 +111,7 @@ | ||
124 | 111 | Position endOfLine(const PointProxy& p) { |
125 | 112 | throwIfOutsideOfDocument(p); |
126 | 113 | const auto ln = line(p); |
127 | - return shrinkToAccessibleRegion(makePointProxy(document(p), Position(ln, document(p).lineLength(ln)))); | |
114 | + return shrinkToAccessibleRegion(PointProxy(document(p), Position(ln, document(p).lineLength(ln)))); | |
128 | 115 | } |
129 | 116 | |
130 | 117 | /** |
@@ -343,8 +330,8 @@ | ||
343 | 330 | */ |
344 | 331 | Region shrinkToAccessibleRegion(const Document& document, const Region& region) BOOST_NOEXCEPT { |
345 | 332 | return Region( |
346 | - shrinkToAccessibleRegion(makePointProxy(document, *boost::const_begin(region))), | |
347 | - shrinkToAccessibleRegion(makePointProxy(document, *boost::const_end(region)))); | |
333 | + shrinkToAccessibleRegion(PointProxy(document, *boost::const_begin(region))), | |
334 | + shrinkToAccessibleRegion(PointProxy(document, *boost::const_end(region)))); | |
348 | 335 | } |
349 | 336 | |
350 | 337 | /** |
@@ -364,8 +351,8 @@ | ||
364 | 351 | */ |
365 | 352 | Region shrinkToDocumentRegion(const Document& document, const Region& region) BOOST_NOEXCEPT { |
366 | 353 | return Region( |
367 | - shrinkToDocumentRegion(makePointProxy(document, *boost::const_begin(region))), | |
368 | - shrinkToDocumentRegion(makePointProxy(document, *boost::const_end(region)))); | |
354 | + shrinkToDocumentRegion(PointProxy(document, *boost::const_begin(region))), | |
355 | + shrinkToDocumentRegion(PointProxy(document, *boost::const_end(region)))); | |
369 | 356 | } |
370 | 357 | |
371 | 358 | /** |
@@ -11,6 +11,7 @@ | ||
11 | 11 | #include <ascension/kernel/document-character-iterator.hpp> |
12 | 12 | #include <ascension/kernel/locations.hpp> |
13 | 13 | #include <ascension/kernel/point.hpp> |
14 | +#include <ascension/kernel/point-proxy.hpp> | |
14 | 15 | #include <boost/core/ignore_unused.hpp> |
15 | 16 | |
16 | 17 |
@@ -157,11 +158,11 @@ | ||
157 | 158 | Point& Point::moveTo(const Position& to) { |
158 | 159 | if(isDocumentDisposed()) |
159 | 160 | throw DocumentDisposedException(); |
160 | - else if(locations::isOutsideOfDocumentRegion(locations::makePointProxy(document(), to))) | |
161 | + else if(locations::isOutsideOfDocumentRegion(locations::PointProxy(document(), to))) | |
161 | 162 | throw BadPositionException(to); |
162 | 163 | Position destination(to); |
163 | 164 | aboutToMove(destination); |
164 | - destination = locations::shrinkToDocumentRegion(locations::makePointProxy(document(), destination)); | |
165 | + destination = locations::shrinkToDocumentRegion(locations::PointProxy(document(), destination)); | |
165 | 166 | const Position from(position()); |
166 | 167 | position_ = destination; |
167 | 168 | moved(from); |
@@ -40,9 +40,9 @@ | ||
40 | 40 | viewer::TextViewer& viewer = target(); |
41 | 41 | abortModes(); |
42 | 42 | const auto document(viewer::document(viewer)); |
43 | - const auto& peos = viewer.textArea()->caret()->end(); | |
43 | + const auto peos(viewer.textArea()->caret()->end()); | |
44 | 44 | const auto eos(*boost::const_end(viewer.textArea()->caret()->selectedRegion())); |
45 | - if(kernel::locations::isBeginningOfLine(peos) || (document->isNarrowed() && eos == *boost::const_begin(document->accessibleRegion()))) | |
45 | + if(kernel::locations::isBeginningOfLine(viewer::insertionPosition(peos)) || (document->isNarrowed() && eos == *boost::const_begin(document->accessibleRegion()))) | |
46 | 46 | return false; |
47 | 47 | |
48 | 48 | const auto caret(viewer.textArea()->caret()); |
@@ -55,7 +55,7 @@ | ||
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | viewer::AutoFreeze af(&viewer); |
58 | - caret->select(viewer::_anchor = kernel::Position(kernel::line(eos), kernel::offsetInLine(eos) - ((c > 0xffffu) ? 2 : 1)), viewer::_caret = peos.hit()); | |
58 | + caret->select(viewer::_anchor = kernel::Position(kernel::line(eos), kernel::offsetInLine(eos) - ((c > 0xffffu) ? 2 : 1)), viewer::_caret = peos); | |
59 | 59 | try { |
60 | 60 | caret->replaceSelection(hex, false); |
61 | 61 | } catch(const kernel::DocumentInput::ChangeRejectedException&) { |
@@ -83,9 +83,9 @@ | ||
83 | 83 | const auto document(viewer::document(target())); |
84 | 84 | const auto textArea(target().textArea()); |
85 | 85 | const auto caret(textArea->caret()); |
86 | - const auto& peos = caret->end(); | |
86 | + const auto peos(caret->end()); | |
87 | 87 | const auto eos(*boost::const_end(caret->selectedRegion())); |
88 | - if(kernel::locations::isBeginningOfLine(peos) || (document->isNarrowed() && eos == *boost::const_begin(document->accessibleRegion()))) | |
88 | + if(kernel::locations::isBeginningOfLine(viewer::insertionPosition(peos)) || (document->isNarrowed() && eos == *boost::const_begin(document->accessibleRegion()))) | |
89 | 89 | return false; |
90 | 90 | |
91 | 91 | const String& lineString = document->lineString(kernel::line(eos)); |
@@ -115,7 +115,7 @@ | ||
115 | 115 | if(i >= 2 && lineString[i - 1] == L'+' && (lineString[i - 2] == L'U' || lineString[i - 2] == L'u')) |
116 | 116 | i -= 2; |
117 | 117 | viewer::AutoFreeze af(&target()); |
118 | - caret->select(viewer::_anchor = kernel::Position(kernel::line(eos), i), viewer::_caret = peos.hit()); | |
118 | + caret->select(viewer::_anchor = kernel::Position(kernel::line(eos), i), viewer::_caret = peos); | |
119 | 119 | try { |
120 | 120 | caret->replaceSelection(s, false); |
121 | 121 | } |
@@ -76,11 +76,11 @@ | ||
76 | 76 | if(direction_ == Direction::forward()) |
77 | 77 | region = kernel::Region( |
78 | 78 | *boost::const_begin(region), |
79 | - kernel::locations::nextCharacter(caret->end(), | |
79 | + kernel::locations::nextCharacter(viewer::insertionPosition(caret->end()), | |
80 | 80 | Direction::forward(), kernel::locations::GRAPHEME_CLUSTER, viewer::isSelectionEmpty(*caret) ? n : (n - 1))); |
81 | 81 | else |
82 | 82 | region = kernel::Region( |
83 | - kernel::locations::nextCharacter(caret->beginning(), | |
83 | + kernel::locations::nextCharacter(viewer::insertionPosition(caret->beginning()), | |
84 | 84 | Direction::backward(), kernel::locations::UTF32_CODE_UNIT, viewer::isSelectionEmpty(*caret) ? n : (n - 1)), |
85 | 85 | *boost::const_end(region)); |
86 | 86 | try { |
@@ -166,7 +166,7 @@ | ||
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | document->insertUndoBoundary(); |
169 | - caret->moveTo(caret->anchor().hit()); | |
169 | + caret->moveTo(caret->anchor()); | |
170 | 170 | return true; |
171 | 171 | } |
172 | 172 |
@@ -182,7 +182,7 @@ | ||
182 | 182 | /// @see VisualPoint#aboutToMove |
183 | 183 | void Caret::aboutToMove(TextHit& to) { |
184 | 184 | const auto ip(insertionPosition(document(), to)); |
185 | - if(kernel::locations::isOutsideOfDocumentRegion(kernel::locations::makePointProxy(document(), ip))) | |
185 | + if(kernel::locations::isOutsideOfDocumentRegion(kernel::locations::PointProxy(document(), ip))) | |
186 | 186 | throw kernel::BadPositionException(ip, "Caret tried to move outside of document."); |
187 | 187 | VisualPoint::aboutToMove(to); |
188 | 188 | } |
@@ -499,7 +499,7 @@ | ||
499 | 499 | if(validateSequence) { |
500 | 500 | if(const texteditor::Session* const session = doc.session()) { |
501 | 501 | if(const std::shared_ptr<const texteditor::InputSequenceCheckers> checker = session->inputSequenceCheckers()) { |
502 | - const auto ip(insertionPosition(document(), beginning().hit())); | |
502 | + const auto ip(insertionPosition(document(), beginning())); | |
503 | 503 | const Char* const lineString = doc.lineString(kernel::line(ip)).data(); |
504 | 504 | if(!checker->check(StringPiece(lineString, kernel::offsetInLine(ip)), character)) { |
505 | 505 | eraseSelection(*this); |
@@ -524,8 +524,7 @@ | ||
524 | 524 | destructiveInsert(*this, StringPiece(buffer, (character < 0x10000u) ? 1 : 2)); |
525 | 525 | doc.insertUndoBoundary(); |
526 | 526 | } else { |
527 | - const bool alpha = kernel::detail::identifierSyntax( | |
528 | - static_cast<std::pair<const kernel::Document&, kernel::Position>>(*this)).isIdentifierContinueCharacter(character); | |
527 | + const bool alpha = kernel::detail::identifierSyntax(*this).isIdentifierContinueCharacter(character); | |
529 | 528 | if(context_.lastTypedPosition != boost::none && (!alpha || boost::get(context_.lastTypedPosition) != insertionPosition(*this))) { |
530 | 529 | // end sequential typing |
531 | 530 | doc.insertUndoBoundary(); |
@@ -621,7 +620,7 @@ | ||
621 | 620 | const StringPiece lineString(document().lineString(kernel::line(hit().characterIndex()))); |
622 | 621 | StringPiece::const_iterator position(lineString.cbegin()); |
623 | 622 | if(boost::size(selectedRegion().lines()) == 1) |
624 | - position += kernel::offsetInLine(insertionPosition(document(), beginning().hit())); | |
623 | + position += kernel::offsetInLine(insertionPosition(document(), beginning())); | |
625 | 624 | return std::make_pair(lineString, position); |
626 | 625 | } |
627 | 626 |
@@ -946,5 +946,25 @@ | ||
946 | 946 | } |
947 | 947 | } |
948 | 948 | } |
949 | + | |
950 | + kernel::locations::PointProxy insertionPosition(const locations::PointProxy& p) { | |
951 | + return kernel::locations::PointProxy(*kernel::document(p), insertionPosition(*kernel::document(p), p.hit)); | |
952 | + } | |
953 | + } | |
954 | + | |
955 | + std::shared_ptr<kernel::Document> kernel::DocumentAccess<viewer::TextArea>::get(viewer::TextArea& textArea) BOOST_NOEXCEPT { | |
956 | + return kernel::document(textArea.textViewer()); | |
957 | + } | |
958 | + | |
959 | + std::shared_ptr<const kernel::Document> kernel::DocumentAccess<const viewer::TextArea>::get(const viewer::TextArea& textArea) BOOST_NOEXCEPT { | |
960 | + return kernel::document(textArea.textViewer()); | |
961 | + } | |
962 | + | |
963 | + std::shared_ptr<const kernel::Document> kernel::DocumentAccess<const viewer::locations::PointProxy>::get(const viewer::locations::PointProxy& p) BOOST_NOEXCEPT { | |
964 | + return kernel::document(p.textArea); | |
965 | + } | |
966 | + | |
967 | + kernel::Position kernel::PositionAccess<const viewer::locations::PointProxy>::get(const viewer::locations::PointProxy& p) BOOST_NOEXCEPT { | |
968 | + return viewer::insertionPosition(p); | |
949 | 969 | } |
950 | 970 | } |
@@ -14,6 +14,7 @@ | ||
14 | 14 | #include <ascension/graphics/font/text-layout.hpp> |
15 | 15 | #include <ascension/graphics/font/text-viewport.hpp> |
16 | 16 | #include <ascension/kernel/document.hpp> |
17 | +#include <ascension/kernel/document-character-iterator.hpp> | |
17 | 18 | #include <ascension/kernel/locations.hpp> |
18 | 19 | #include <ascension/viewer/caret.hpp> |
19 | 20 | #include <ascension/viewer/text-area.hpp> |
@@ -23,29 +24,23 @@ | ||
23 | 24 | namespace viewer { |
24 | 25 | namespace locations { |
25 | 26 | namespace { |
26 | - inline const TextArea& textArea(const PointProxy& p) BOOST_NOEXCEPT { | |
27 | - return std::get<0>(p); | |
28 | - } | |
29 | 27 | inline const kernel::Document& document(const PointProxy& p) BOOST_NOEXCEPT { |
30 | - return textArea(p).caret()->document(); | |
31 | - } | |
32 | - inline const TextHit& hit(const PointProxy& p) BOOST_NOEXCEPT { | |
33 | - return std::get<1>(p); | |
28 | + return p.textArea.caret()->document(); | |
34 | 29 | } |
35 | 30 | inline kernel::Position position(const PointProxy& p) BOOST_NOEXCEPT { |
36 | - return insertionPosition(document(p), hit(p)); | |
31 | + return insertionPosition(document(p), p.hit); | |
37 | 32 | } |
38 | 33 | inline kernel::Position normalPosition(const PointProxy& p) BOOST_NOEXCEPT { |
39 | - return kernel::locations::shrinkToAccessibleRegion(kernel::locations::makePointProxy(document(p), position(p))); | |
34 | + return kernel::locations::shrinkToAccessibleRegion(kernel::locations::PointProxy(document(p), position(p))); | |
40 | 35 | } |
41 | 36 | inline TextHit normalHit(const PointProxy& p) BOOST_NOEXCEPT { |
42 | - const auto np(kernel::locations::shrinkToAccessibleRegion(kernel::locations::makePointProxy(document(p), hit(p).characterIndex()))); | |
43 | - if(np != hit(p).characterIndex() || kernel::locations::isEndOfLine(kernel::locations::makePointProxy(document(p), np))) | |
37 | + const auto np(kernel::locations::shrinkToAccessibleRegion(kernel::locations::PointProxy(document(p), p.hit.characterIndex()))); | |
38 | + if(np != p.hit.characterIndex() || kernel::locations::isEndOfLine(kernel::locations::PointProxy(document(p), np))) | |
44 | 39 | return TextHit::leading(np); |
45 | - return hit(p); | |
40 | + return p.hit; | |
46 | 41 | } |
47 | - inline std::pair<const kernel::Document&, kernel::Position> kernelProxy(const PointProxy& p) { | |
48 | - return kernel::locations::makePointProxy(document(p), position(p)); | |
42 | + inline kernel::locations::PointProxy kernelProxy(const PointProxy& p) { | |
43 | + return kernel::locations::PointProxy(document(p), position(p)); | |
49 | 44 | } |
50 | 45 | inline graphics::font::TextHit<> inlineHit(const TextHit& hit) BOOST_NOEXCEPT { |
51 | 46 | return graphics::font::transformTextHit(hit, [](const kernel::Position& p) { |
@@ -107,7 +102,7 @@ | ||
107 | 102 | */ |
108 | 103 | TextHit beginningOfVisualLine(const PointProxy& p) { |
109 | 104 | const auto h(normalHit(p)); |
110 | - if(const graphics::font::TextLayout* const layout = textArea(p).textRenderer()->layouts().at(kernel::line(h.characterIndex()))) | |
105 | + if(const graphics::font::TextLayout* const layout = p.textArea.textRenderer()->layouts().at(kernel::line(h.characterIndex()))) | |
111 | 106 | return TextHit::leading(kernel::Position(kernel::line(h.characterIndex()), layout->lineOffset(layout->lineAt(inlineHit(h))))); |
112 | 107 | return TextHit::leading(kernel::locations::beginningOfLine(kernelProxy(p))); |
113 | 108 | } |
@@ -160,7 +155,7 @@ | ||
160 | 155 | TextHit endOfVisualLine(const PointProxy& p) { |
161 | 156 | auto h(normalHit(p)); |
162 | 157 | const auto line = kernel::line(h.characterIndex()); |
163 | - if(const graphics::font::TextLayout* const layout = textArea(p).textRenderer()->layouts().at(line)) { | |
158 | + if(const graphics::font::TextLayout* const layout = p.textArea.textRenderer()->layouts().at(line)) { | |
164 | 159 | const Index subline = layout->lineAt(inlineHit(h)); |
165 | 160 | if(subline < layout->numberOfLines() - 1) |
166 | 161 | return otherHit(document(p), TextHit::leading(kernel::Position(line, layout->lineOffset(subline + 1)))); |
@@ -191,7 +186,7 @@ | ||
191 | 186 | TextHit firstPrintableCharacterOfVisualLine(const PointProxy& p) { |
192 | 187 | kernel::Position np(normalPosition(p)); |
193 | 188 | const String& s = document(p).lineString(kernel::line(np)); |
194 | - if(const graphics::font::TextLayout* const layout = textArea(p).textRenderer()->layouts().at(kernel::line(np))) { | |
189 | + if(const graphics::font::TextLayout* const layout = p.textArea.textRenderer()->layouts().at(kernel::line(np))) { | |
195 | 190 | const Index subline = layout->lineAt(graphics::font::makeLeadingTextHit(kernel::offsetInLine(np))); |
196 | 191 | np.offsetInLine = kernel::detail::identifierSyntax(kernelProxy(p)).eatWhiteSpaces( |
197 | 192 | s.begin() + layout->lineOffset(subline), |
@@ -258,7 +253,7 @@ | ||
258 | 253 | if(kernel::locations::isBeginningOfLine(kernelProxy(p))) // this considers narrowing |
259 | 254 | return true; |
260 | 255 | const kernel::Position np(normalPosition(p)); |
261 | - if(const graphics::font::TextLayout* const layout = textArea(p).textRenderer()->layouts().at(kernel::line(np))) | |
256 | + if(const graphics::font::TextLayout* const layout = p.textArea.textRenderer()->layouts().at(kernel::line(np))) | |
262 | 257 | return kernel::offsetInLine(np) == layout->lineOffset(layout->lineAt(graphics::font::makeLeadingTextHit(kernel::offsetInLine(np)))); |
263 | 258 | return kernel::locations::isBeginningOfLine(kernelProxy(p)); |
264 | 259 | } |
@@ -273,7 +268,7 @@ | ||
273 | 268 | if(kernel::locations::isEndOfLine(kernelProxy(p))) // this considers narrowing |
274 | 269 | return true; |
275 | 270 | const kernel::Position np(normalPosition(p)); |
276 | - if(const graphics::font::TextLayout* const layout = textArea(p).textRenderer()->layouts().at(kernel::line(np))) { | |
271 | + if(const graphics::font::TextLayout* const layout = p.textArea.textRenderer()->layouts().at(kernel::line(np))) { | |
277 | 272 | const Index subline = layout->lineAt(graphics::font::makeLeadingTextHit(kernel::offsetInLine(np))); |
278 | 273 | return kernel::offsetInLine(np) == layout->lineOffset(subline) + layout->lineLength(subline); |
279 | 274 | } |
@@ -19,6 +19,7 @@ | ||
19 | 19 | #include <ascension/viewer/text-area.hpp> |
20 | 20 | #include <ascension/viewer/text-viewer.hpp> |
21 | 21 | #include <ascension/viewer/text-viewer-model-conversion.hpp> |
22 | +#include <ascension/viewer/visual-locations.hpp> | |
22 | 23 | #include <ascension/viewer/visual-point.hpp> |
23 | 24 | #ifndef ASCENSION_PIXELFUL_SCROLL_IN_BPD |
24 | 25 | # include <boost/math/special_functions/trunc.hpp> |
@@ -398,16 +399,16 @@ | ||
398 | 399 | #endif |
399 | 400 | namespace { |
400 | 401 | inline bool isOutsideOfDocumentRegion(const kernel::Document& document, const TextHit& hit) BOOST_NOEXCEPT { |
401 | - return kernel::locations::isOutsideOfDocumentRegion(kernel::locations::makePointProxy(document, insertionPosition(document, hit))); | |
402 | + return kernel::locations::isOutsideOfDocumentRegion(kernel::locations::PointProxy(document, insertionPosition(document, hit))); | |
402 | 403 | } |
403 | 404 | inline TextHit shrinkToDocumentRegion(const kernel::Document& document, const TextHit& hit) BOOST_NOEXCEPT { |
404 | 405 | if(kernel::line(hit.characterIndex()) >= document.numberOfLines()) |
405 | - return TextHit::leading(kernel::locations::endOfDocument(kernel::locations::makePointProxy(document, hit.characterIndex()))); | |
406 | + return TextHit::leading(kernel::locations::endOfDocument(kernel::locations::PointProxy(document, hit.characterIndex()))); | |
406 | 407 | const Index line = kernel::line(hit.characterIndex()); |
407 | 408 | if(kernel::offsetInLine(hit.characterIndex()) < document.lineLength(line)) |
408 | 409 | return hit; |
409 | 410 | else |
410 | - return TextHit::leading(kernel::locations::endOfLine(kernel::locations::makePointProxy(document, hit.characterIndex()))); | |
411 | + return TextHit::leading(kernel::locations::endOfLine(kernel::locations::PointProxy(document, hit.characterIndex()))); | |
411 | 412 | } |
412 | 413 | } |
413 | 414 |