aboutsummaryrefslogtreecommitdiff
path: root/src/scintilla_backports/6445_89d992f380a1.patch
blob: b0b9acae8e730c38e2576505177de2cba53b06b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# HG changeset patch
# User Neil <nyamatongwe@gmail.com>
# Date 1517437334 -39600
# Node ID 89d992f380a1ce28a3ba6934230388ffaf1ea611
# Parent  1bd57324aa36e3fce1ed8a2371001b062322884b
Templatize RunStyles so it can be over ranges of different types and contain
different style types.
Currently only instantiated over <int, int>.

diff -r 1bd57324aa36 -r 89d992f380a1 src/ContractionState.cxx
--- a/src/ContractionState.cxx	Thu Feb 01 09:07:21 2018 +1100
+++ b/src/ContractionState.cxx	Thu Feb 01 09:22:14 2018 +1100
@@ -35,9 +35,9 @@

 void ContractionState::EnsureData() {
 	if (OneToOne()) {
-		visible = new RunStyles();
-		expanded = new RunStyles();
-		heights = new RunStyles();
+		visible = new RunStyles<int, int>();
+		expanded = new RunStyles<int, int>();
+		heights = new RunStyles<int, int>();
 		foldDisplayTexts = new SparseVector<const char *>();
 		displayLines = new Partitioning<int>(4);
 		InsertLines(0, linesInDocument);
diff -r 1bd57324aa36 -r 89d992f380a1 src/ContractionState.h
--- a/src/ContractionState.h	Thu Feb 01 09:07:21 2018 +1100
+++ b/src/ContractionState.h	Thu Feb 01 09:22:14 2018 +1100
@@ -17,9 +17,9 @@
  */
 class ContractionState {
 	// These contain 1 element for every document line.
-	RunStyles *visible;
-	RunStyles *expanded;
-	RunStyles *heights;
+	RunStyles<int, int> *visible;
+	RunStyles<int, int> *expanded;
+	RunStyles<int, int> *heights;
 	SparseVector<const char *> *foldDisplayTexts;
 	Partitioning<int> *displayLines;
 	Sci::Line linesInDocument;
diff -r 1bd57324aa36 -r 89d992f380a1 src/Decoration.h
--- a/src/Decoration.h	Thu Feb 01 09:07:21 2018 +1100
+++ b/src/Decoration.h	Thu Feb 01 09:22:14 2018 +1100
@@ -12,7 +12,7 @@
 class Decoration {
 	int indicator;
 public:
 	Decoration *next;
-	RunStyles rs;
+	RunStyles<int, int> rs;

 	explicit Decoration(int indicator_);
diff -r 1bd57324aa36 -r 89d992f380a1 src/RunStyles.cxx
--- a/src/RunStyles.cxx	Thu Feb 01 09:07:21 2018 +1100
+++ b/src/RunStyles.cxx	Thu Feb 01 09:22:14 2018 +1100
@@ -26,8 +26,9 @@
 using namespace Scintilla;

 // Find the first run at a position
-int RunStyles::RunFromPosition(int position) const {
-	int run = starts->PartitionFromPosition(position);
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::RunFromPosition(DISTANCE position) const {
+	DISTANCE run = starts->PartitionFromPosition(position);
 	// Go to first element with this position
 	while ((run > 0) && (position == starts->PositionFromPartition(run-1))) {
 		run--;
@@ -36,11 +37,12 @@
 }

 // If there is no run boundary at position, insert one continuing style.
-int RunStyles::SplitRun(int position) {
-	int run = RunFromPosition(position);
-	const int posRun = starts->PositionFromPartition(run);
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::SplitRun(DISTANCE position) {
+	DISTANCE run = RunFromPosition(position);
+	const DISTANCE posRun = starts->PositionFromPartition(run);
 	if (posRun < position) {
-		int runStyle = ValueAt(position);
+		STYLE runStyle = ValueAt(position);
 		run++;
 		starts->InsertPartition(run, position);
 		styles->InsertValue(run, 1, runStyle);
@@ -48,12 +50,14 @@
 	return run;
 }

-void RunStyles::RemoveRun(int run) {
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::RemoveRun(DISTANCE run) {
 	starts->RemovePartition(run);
 	styles->DeleteRange(run, 1);
 }

-void RunStyles::RemoveRunIfEmpty(int run) {
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::RemoveRunIfEmpty(DISTANCE run) {
 	if ((run < starts->Partitions()) && (starts->Partitions() > 1)) {
 		if (starts->PositionFromPartition(run) == starts->PositionFromPartition(run+1)) {
 			RemoveRun(run);
@@ -61,7 +65,8 @@
 	}
 }

-void RunStyles::RemoveRunIfSameAsPrevious(int run) {
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::RemoveRunIfSameAsPrevious(DISTANCE run) {
 	if ((run > 0) && (run < starts->Partitions())) {
 		if (styles->ValueAt(run-1) == styles->ValueAt(run)) {
 			RemoveRun(run);
@@ -69,34 +74,39 @@
 	}
 }

-RunStyles::RunStyles() {
-	starts = new Partitioning<int>(8);
-	styles = new SplitVector<int>();
+template <typename DISTANCE, typename STYLE>
+RunStyles<DISTANCE, STYLE>::RunStyles() {
+	starts = new Partitioning<DISTANCE>(8);
+	styles = new SplitVector<STYLE>();
 	styles->InsertValue(0, 2, 0);
 }

-RunStyles::~RunStyles() {
+template <typename DISTANCE, typename STYLE>
+RunStyles<DISTANCE, STYLE>::~RunStyles() {
 	delete starts;
 	starts = NULL;
 	delete styles;
 	styles = NULL;
 }

-int RunStyles::Length() const {
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::Length() const {
 	return starts->PositionFromPartition(starts->Partitions());
 }

-int RunStyles::ValueAt(int position) const {
+template <typename DISTANCE, typename STYLE>
+STYLE RunStyles<DISTANCE, STYLE>::ValueAt(DISTANCE position) const {
 	return styles->ValueAt(starts->PartitionFromPosition(position));
 }

-int RunStyles::FindNextChange(int position, int end) const {
-	const int run = starts->PartitionFromPosition(position);
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::FindNextChange(DISTANCE position, DISTANCE end) const {
+	const DISTANCE run = starts->PartitionFromPosition(position);
 	if (run < starts->Partitions()) {
-		const int runChange = starts->PositionFromPartition(run);
+		const DISTANCE runChange = starts->PositionFromPartition(run);
 		if (runChange > position)
 			return runChange;
-		const int nextChange = starts->PositionFromPartition(run + 1);
+		const DISTANCE nextChange = starts->PositionFromPartition(run + 1);
 		if (nextChange > position) {
 			return nextChange;
 		} else if (position < end) {
@@ -105,23 +115,26 @@
 	}
 }

-int RunStyles::StartRun(int position) const {
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::StartRun(DISTANCE position) const {
 	return starts->PositionFromPartition(starts->PartitionFromPosition(position));
 }

-int RunStyles::EndRun(int position) const {
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::EndRun(DISTANCE position) const {
 	return starts->PositionFromPartition(starts->PartitionFromPosition(position) + 1);
 }

-bool RunStyles::FillRange(int &position, int value, int &fillLength) {
+template <typename DISTANCE, typename STYLE>
+bool RunStyles<DISTANCE, STYLE>::FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength) {
 	if (fillLength <= 0) {
 		return false;
 	}
-	int end = position + fillLength;
+	DISTANCE end = position + fillLength;
 	if (end > Length()) {
 		return false;
 	}
-	int runEnd = RunFromPosition(end);
+	DISTANCE runEnd = RunFromPosition(end);
 	if (styles->ValueAt(runEnd) == value) {
 		// End already has value so trim range.
 		end = starts->PositionFromPartition(runEnd);
@@ -133,7 +146,7 @@
 	} else {
 		runEnd = SplitRun(end);
 	}
-	int runStart = RunFromPosition(position);
+	DISTANCE runStart = RunFromPosition(position);
 	if (styles->ValueAt(runStart) == value) {
 		// Start is in expected value so trim range.
 		runStart++;
@@ -148,7 +161,7 @@
 	if (runStart < runEnd) {
 		styles->SetValueAt(runStart, value);
 		// Remove each old run over the range
-		for (int run=runStart+1; run<runEnd; run++) {
+		for (DISTANCE run=runStart+1; run<runEnd; run++) {
 			RemoveRun(runStart+1);
 		}
 		runEnd = RunFromPosition(end);
@@ -162,20 +175,22 @@
 	}
 }

-void RunStyles::SetValueAt(int position, int value) {
-	int len = 1;
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::SetValueAt(DISTANCE position, STYLE value) {
+	DISTANCE len = 1;
 	FillRange(position, value, len);
 }

-void RunStyles::InsertSpace(int position, int insertLength) {
-	int runStart = RunFromPosition(position);
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::InsertSpace(DISTANCE position, DISTANCE insertLength) {
+	DISTANCE runStart = RunFromPosition(position);
 	if (starts->PositionFromPartition(runStart) == position) {
-		int runStyle = ValueAt(position);
+		STYLE runStyle = ValueAt(position);
 		// Inserting at start of run so make previous longer
 		if (runStart == 0) {
 			// Inserting at start of document so ensure 0
 			if (runStyle) {
-				styles->SetValueAt(0, 0);
+				styles->SetValueAt(0, STYLE());
 				starts->InsertPartition(1, 0);
 				styles->InsertValue(1, 1, runStyle);
 				starts->InsertText(0, insertLength);
@@ -195,20 +210,22 @@
 	}
 }

-void RunStyles::DeleteAll() {
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::DeleteAll() {
 	delete starts;
 	starts = NULL;
 	delete styles;
 	styles = NULL;
-	starts = new Partitioning<int>(8);
-	styles = new SplitVector<int>();
+	starts = new Partitioning<DISTANCE>(8);
+	styles = new SplitVector<STYLE>();
 	styles->InsertValue(0, 2, 0);
 }

-void RunStyles::DeleteRange(int position, int deleteLength) {
-	int end = position + deleteLength;
-	int runStart = RunFromPosition(position);
-	int runEnd = RunFromPosition(end);
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::DeleteRange(DISTANCE position, DISTANCE deleteLength) {
+	DISTANCE end = position + deleteLength;
+	DISTANCE runStart = RunFromPosition(position);
+	DISTANCE runEnd = RunFromPosition(end);
 	if (runStart == runEnd) {
 		// Deleting from inside one run
 		starts->InsertText(runStart, -deleteLength);
@@ -214,7 +231,7 @@
 		runEnd = SplitRun(end);
 		starts->InsertText(runStart, -deleteLength);
 		// Remove each old run over the range
-		for (int run=runStart; run<runEnd; run++) {
+		for (DISTANCE run=runStart; run<runEnd; run++) {
 			RemoveRun(runStart);
 		}
 		RemoveRunIfEmpty(runStart);
@@ -222,11 +239,13 @@
 	}
 }

-int RunStyles::Runs() const {
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::Runs() const {
 	return starts->Partitions();
 }

-bool RunStyles::AllSame() const {
+template <typename DISTANCE, typename STYLE>
+bool RunStyles<DISTANCE, STYLE>::AllSame() const {
 	for (int run = 1; run < starts->Partitions(); run++) {
 		if (styles->ValueAt(run) != styles->ValueAt(run - 1))
 			return false;
@@ -234,13 +253,15 @@
 	return true;
 }

-bool RunStyles::AllSameAs(int value) const {
+template <typename DISTANCE, typename STYLE>
+bool RunStyles<DISTANCE, STYLE>::AllSameAs(STYLE value) const {
 	return AllSame() && (styles->ValueAt(0) == value);
 }

-int RunStyles::Find(int value, int start) const {
+template <typename DISTANCE, typename STYLE>
+DISTANCE RunStyles<DISTANCE, STYLE>::Find(STYLE value, DISTANCE start) const {
 	if (start < Length()) {
-		int run = start ? RunFromPosition(start) : 0;
+		DISTANCE run = start ? RunFromPosition(start) : 0;
 		if (styles->ValueAt(run) == value)
 			return start;
 		run++;
@@ -253,7 +274,8 @@
 	return -1;
 }

-void RunStyles::Check() const {
+template <typename DISTANCE, typename STYLE>
+void RunStyles<DISTANCE, STYLE>::Check() const {
 	if (Length() < 0) {
 		throw std::runtime_error("RunStyles: Length can not be negative.");
 	}
@@ -263,9 +285,9 @@
 	if (starts->Partitions() != styles->Length()-1) {
 		throw std::runtime_error("RunStyles: Partitions and styles different lengths.");
 	}
-	int start=0;
+	DISTANCE start=0;
 	while (start < Length()) {
-		const int end = EndRun(start);
+		const DISTANCE end = EndRun(start);
 		if (start >= end) {
 			throw std::runtime_error("RunStyles: Partition is 0 length.");
 		}
@@ -280,3 +302,9 @@
 		}
 	}
 }
+
+#ifdef SCI_NAMESPACE
+template class Scintilla::RunStyles<int, int>;
+#else
+template class RunStyles<int, int>;
+#endif
diff -r 1bd57324aa36 -r 89d992f380a1 src/RunStyles.h
--- a/src/RunStyles.h	Thu Feb 01 09:07:21 2018 +1100
+++ b/src/RunStyles.h	Thu Feb 01 09:22:14 2018 +1100
@@ -12,35 +12,36 @@
 namespace Scintilla {
 #endif

+template <typename DISTANCE, typename STYLE>
 class RunStyles {
 private:
-	Partitioning<int> *starts;
-	SplitVector<int> *styles;
-	int RunFromPosition(int position) const;
-	int SplitRun(int position);
-	void RemoveRun(int run);
-	void RemoveRunIfEmpty(int run);
-	void RemoveRunIfSameAsPrevious(int run);
+	Partitioning<DISTANCE> *starts;
+	SplitVector<STYLE> *styles;
+	DISTANCE RunFromPosition(DISTANCE position) const;
+	DISTANCE SplitRun(DISTANCE position);
+	void RemoveRun(DISTANCE run);
+	void RemoveRunIfEmpty(DISTANCE run);
+	void RemoveRunIfSameAsPrevious(DISTANCE run);
 	// Private so RunStyles objects can not be copied
 	RunStyles(const RunStyles &);
 public:
 	RunStyles();
 	~RunStyles();
-	int Length() const;
-	int ValueAt(int position) const;
-	int FindNextChange(int position, int end) const;
-	int StartRun(int position) const;
-	int EndRun(int position) const;
+	DISTANCE Length() const;
+	STYLE ValueAt(DISTANCE position) const;
+	DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const;
+	DISTANCE StartRun(DISTANCE position) const;
+	DISTANCE EndRun(DISTANCE position) const;
 	// Returns true if some values may have changed
-	bool FillRange(int &position, int value, int &fillLength);
-	void SetValueAt(int position, int value);
-	void InsertSpace(int position, int insertLength);
+	bool FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength);
+	void SetValueAt(DISTANCE position, STYLE value);
+	void InsertSpace(DISTANCE position, DISTANCE insertLength);
 	void DeleteAll();
-	void DeleteRange(int position, int deleteLength);
-	int Runs() const;
+	void DeleteRange(DISTANCE position, DISTANCE deleteLength);
+	DISTANCE Runs() const;
 	bool AllSame() const;
-	bool AllSameAs(int value) const;
-	int Find(int value, int start) const;
+	bool AllSameAs(STYLE value) const;
+	DISTANCE Find(STYLE value, DISTANCE start) const;

 	void Check() const;
 };
diff -r 1bd57324aa36 -r 89d992f380a1 test/unit/testRunStyles.cxx
--- a/test/unit/testRunStyles.cxx	Thu Feb 01 09:07:21 2018 +1100
+++ b/test/unit/testRunStyles.cxx	Thu Feb 01 09:22:14 2018 +1100
@@ -22,7 +22,7 @@

 TEST_CASE("RunStyles") {

-	RunStyles rs;
+	RunStyles<int, int> rs;

 	SECTION("IsEmptyInitially") {
 		REQUIRE(0 == rs.Length());