1 | // Scintilla source code edit control |
---|---|
2 | /** @file EditModel.cxx |
3 | ** Defines the editor state that must be visible to EditorView. |
4 | **/ |
5 | // Copyright 1998-2014 by Neil Hodgson <neilh@scintilla.org> |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | |
8 | #include <cstddef> |
9 | #include <cstdlib> |
10 | #include <cstdint> |
11 | #include <cassert> |
12 | #include <cstring> |
13 | #include <cmath> |
14 | |
15 | #include <stdexcept> |
16 | #include <string> |
17 | #include <string_view> |
18 | #include <vector> |
19 | #include <map> |
20 | #include <set> |
21 | #include <optional> |
22 | #include <algorithm> |
23 | #include <memory> |
24 | |
25 | #include "ScintillaTypes.h" |
26 | #include "ILoader.h" |
27 | #include "ILexer.h" |
28 | |
29 | #include "Debugging.h" |
30 | #include "Geometry.h" |
31 | #include "Platform.h" |
32 | |
33 | #include "CharacterCategoryMap.h" |
34 | |
35 | #include "Position.h" |
36 | #include "UniqueString.h" |
37 | #include "SplitVector.h" |
38 | #include "Partitioning.h" |
39 | #include "RunStyles.h" |
40 | #include "ContractionState.h" |
41 | #include "CellBuffer.h" |
42 | #include "Indicator.h" |
43 | #include "LineMarker.h" |
44 | #include "Style.h" |
45 | #include "ViewStyle.h" |
46 | #include "CharClassify.h" |
47 | #include "Decoration.h" |
48 | #include "CaseFolder.h" |
49 | #include "Document.h" |
50 | #include "UniConversion.h" |
51 | #include "Selection.h" |
52 | #include "PositionCache.h" |
53 | #include "EditModel.h" |
54 | |
55 | using namespace Scintilla; |
56 | using namespace Scintilla::Internal; |
57 | |
58 | Caret::Caret() noexcept : |
59 | active(false), on(false), period(500) {} |
60 | |
61 | EditModel::EditModel() : braces{} { |
62 | inOverstrike = false; |
63 | xOffset = 0; |
64 | trackLineWidth = false; |
65 | posDrag = SelectionPosition(Sci::invalidPosition); |
66 | braces[0] = Sci::invalidPosition; |
67 | braces[1] = Sci::invalidPosition; |
68 | bracesMatchStyle = StyleBraceBad; |
69 | highlightGuideColumn = 0; |
70 | hasFocus = false; |
71 | primarySelection = true; |
72 | imeInteraction = IMEInteraction::Windowed; |
73 | bidirectional = Bidirectional::Disabled; |
74 | foldFlags = FoldFlag::None; |
75 | foldDisplayTextStyle = FoldDisplayTextStyle::Hidden; |
76 | hotspot = Range(Sci::invalidPosition); |
77 | hotspotSingleLine = true; |
78 | hoverIndicatorPos = Sci::invalidPosition; |
79 | wrapWidth = LineLayout::wrapWidthInfinite; |
80 | pdoc = new Document(DocumentOption::Default); |
81 | pdoc->AddRef(); |
82 | pcs = ContractionStateCreate(pdoc->IsLarge()); |
83 | } |
84 | |
85 | EditModel::~EditModel() { |
86 | try { |
87 | // This never throws but isn't marked noexcept for compatibility |
88 | pdoc->Release(); |
89 | } catch (...) { |
90 | // Ignore any exception |
91 | } |
92 | pdoc = nullptr; |
93 | } |
94 | |
95 | bool EditModel::BidirectionalEnabled() const noexcept { |
96 | return (bidirectional != Bidirectional::Disabled) && |
97 | (CpUtf8 == pdoc->dbcsCodePage); |
98 | } |
99 | |
100 | bool EditModel::BidirectionalR2L() const noexcept { |
101 | return bidirectional == Bidirectional::R2L; |
102 | } |
103 | |
104 | void EditModel::SetDefaultFoldDisplayText(const char *text) { |
105 | defaultFoldDisplayText = IsNullOrEmpty(text) ? UniqueString() : UniqueStringCopy(text); |
106 | } |
107 | |
108 | const char *EditModel::GetDefaultFoldDisplayText() const noexcept { |
109 | return defaultFoldDisplayText.get(); |
110 | } |
111 | |
112 | const char *EditModel::GetFoldDisplayText(Sci::Line lineDoc) const noexcept { |
113 | if (foldDisplayTextStyle == FoldDisplayTextStyle::Hidden || pcs->GetExpanded(lineDoc)) { |
114 | return nullptr; |
115 | } |
116 | |
117 | const char *text = pcs->GetFoldDisplayText(lineDoc); |
118 | return text ? text : defaultFoldDisplayText.get(); |
119 | } |
120 | |
121 | InSelection EditModel::LineEndInSelection(Sci::Line lineDoc) const { |
122 | const Sci::Position posAfterLineEnd = pdoc->LineStart(lineDoc + 1); |
123 | return sel.InSelectionForEOL(posAfterLineEnd); |
124 | } |
125 |