Skip to content

Commit 230c2ee

Browse files
committed
[deprecated] stupid brain
1 parent d27eb12 commit 230c2ee

File tree

5 files changed

+180
-58
lines changed

5 files changed

+180
-58
lines changed

include/ekg/io/utf.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ namespace ekg {
151151
protected:
152152
std::vector<ekg::io::chunk_t> loaded_chunks {};
153153
size_t lines_per_chunk_limit {10};
154-
size_t total_lines {};
154+
size_t total_chars {};
155+
size_t prev_total_chars {};
155156
bool was_audited {};
157+
bool should_count {};
156158
public:
157159
static std::string line_not_found;
158160
public:
@@ -179,8 +181,11 @@ namespace ekg {
179181

180182
std::vector<ekg::io::chunk_t> &data();
181183

184+
size_t size();
182185
size_t lines();
183186
size_t chunks();
187+
188+
void unset_audited();
184189
bool audited();
185190
};
186191
}

include/ekg/ui/textbox/textbox.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,43 @@ namespace ekg {
5656
ekg::rect_t<float> rect {};
5757
public:
5858
bool operator == (size_t index) {
59-
return this->index_a == index && this->index_b == index;
59+
return index == this->index_a && index == this->index_b;
6060
}
6161

6262
bool operator > (size_t index) {
63-
return this->index_a > index;
63+
return index > this->index_a;
6464
}
6565

6666
bool operator >= (size_t index) {
67-
return this->index_a >= index;
67+
return index >= this->index_a;
6868
}
6969

7070
bool operator < (size_t index) {
71-
return this->index_b < index;
71+
return index < this->index_b;
7272
}
7373

7474
bool operator <= (size_t index) {
75-
return this->index_b <= index;
75+
return index <= this->index_b;
7676
}
7777

7878
bool operator == (const ekg::textbox_t::cursor_t &cursor) {
7979
return this->index_a == cursor.index_a && this->index_b == cursor.index_b;
8080
}
8181
};
8282

83+
struct untracked_line_ending_t {
84+
public:
85+
ekg::vec2_t<size_t> indices {};
86+
std::string text {};
87+
};
88+
8389
struct widget_t {
8490
public:
8591
ekg::rect_t<float> rect_text_size {};
8692
ekg::scrollbar_t scrollbar {};
8793
std::vector<ekg::textbox_t::cursor_t> cursors {};
8894
std::vector<ekg::textbox_t::select_draw_layer_t> layers_select {};
95+
std::vector<ekg::textbox_t::untracked_line_ending_t> line_ending_untracked {};
8996
size_t last_layers_select_size {};
9097
};
9198

src/ekg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void ekg::render() {
167167
*
168168
* I do not know why this is hapenning, likely wtf, if I remove this
169169
* scrolling is horrible, I am not sure why this is hapning, I tried make the make redraw always,
170-
* rendering everything, no allocators asserts. Nothing. I tried do a stupid `meow<t>` where t receives a descriptor,
170+
* rendering everything, no allocators asscerts. Nothing. I tried do a stupid `meow<t>` where t receives a descriptor,
171171
* but nothing too. I do not know why this happens but it is very insanely weird. Post does not affect the performance
172172
* a lot, may we consider to let for some long time. While no solution was found.
173173
*

src/io/utf.cpp

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,20 @@ std::string ekg::text::line_not_found {'\x1B'};
270270

271271
std::string &ekg::text::write(size_t index) {
272272
size_t chunks_size {this->loaded_chunks.size()};
273-
size_t total_lines {};
274-
size_t previous_total_lines {};
273+
size_t total_chars {};
274+
size_t previous_total_chars {};
275275
size_t chunk_size {};
276276

277277
this->was_audited = true;
278278

279279
for (size_t it {}; it < chunks_size; it++) {
280280
ekg::io::chunk_t &chunk {this->loaded_chunks.at(it)};
281281

282-
previous_total_lines = total_lines;
283-
total_lines += (chunk_size = chunk.size());
282+
previous_total_chars = total_chars;
283+
total_chars += (chunk_size = chunk.size());
284284

285-
if (index < total_lines && (index - previous_total_lines) < chunk_size) {
286-
return chunk.at(index - previous_total_lines);
285+
if (index < total_chars && (index - previous_total_chars) < chunk_size) {
286+
return chunk.at(index - previous_total_chars);
287287
}
288288
}
289289

@@ -308,31 +308,31 @@ void ekg::text::insert(
308308
}
309309
return;
310310
}
311+
this->was_audited = true;
311312

312313
bool ok {};
313314

314-
size_t previous_total_lines {};
315+
size_t previous_total_chars {};
315316
size_t chunk_size {};
316-
size_t current_total_lines {};
317+
size_t current_total_chars {};
317318

318319
ekg::io::chunk_t to_swizzle_chunk {};
319320

320-
this->total_lines = 0;
321321
for (size_t it {}; it < this->loaded_chunks.size(); it++) {
322322
ekg::io::chunk_t &chunk {this->loaded_chunks.at(it)};
323323

324-
previous_total_lines = this->total_lines;
325-
current_total_lines += (chunk_size = chunk.size());
324+
previous_total_chars = this->total_chars;
325+
current_total_chars += (chunk_size = chunk.size());
326326

327327
if (
328328
!ok
329329
&&
330-
index < current_total_lines
330+
index < current_total_chars
331331
&&
332-
(index - previous_total_lines) < chunk_size
332+
(index - previous_total_chars) < chunk_size
333333
) {
334334
chunk.insert(
335-
chunk.begin() + (index - previous_total_lines),
335+
chunk.begin() + (index - previous_total_chars),
336336
to_insert_chunk.begin(),
337337
to_insert_chunk.end()
338338
);
@@ -381,8 +381,6 @@ void ekg::text::insert(
381381

382382
ok = true;
383383
}
384-
385-
this->total_lines += this->loaded_chunks.at(it).size();
386384
}
387385
}
388386

@@ -404,16 +402,22 @@ void ekg::text::erase(
404402
return;
405403
}
406404

407-
if (begin >= this->total_lines || end >= this->total_lines || end <= begin) {
408-
throw std::out_of_range("ekg::text::erase -> begin or end out of index");
405+
if (begin > this->total_chars) {
406+
throw std::out_of_range("ekg::text::erase: " + std::to_string(begin) + ", " + std::to_string(this->total_chars));
409407
return;
410408
}
411409

412-
this->total_lines -= end - begin;
410+
end = ekg::min(begin + end, this->total_chars);
411+
412+
this->should_count = true;
413+
this->size();
414+
415+
this->total_chars -= end - begin;
416+
this->was_audited = true;
413417

414-
size_t previous_total_lines {};
418+
size_t previous_total_chars {};
415419
size_t chunk_size {};
416-
size_t total_lines {};
420+
size_t total_chars {};
417421
size_t remains_lines {};
418422

419423
bool empty_chunk {};
@@ -422,12 +426,12 @@ void ekg::text::erase(
422426
for (size_t it {}; it < this->loaded_chunks.size(); it++) {
423427
ekg::io::chunk_t &chunk {this->loaded_chunks.at(it)};
424428

425-
previous_total_lines = total_lines;
426-
total_lines += (chunk_size = chunk.size());
429+
previous_total_chars = total_chars;
430+
total_chars += (chunk_size = chunk.size());
427431

428-
if (begin < total_lines) {
432+
if (begin < total_chars) {
429433
remains_lines = end - begin;
430-
begin = begin - previous_total_lines;
434+
begin = begin - previous_total_chars;
431435
while (remains_lines != 0) {
432436
ekg::io::chunk_t &chunk {this->loaded_chunks.at(it)};
433437

@@ -459,15 +463,19 @@ void ekg::text::erase(
459463
break;
460464
}
461465
}
466+
467+
this->should_count = true;
468+
this->size();
462469
}
463470

464471
void ekg::text::push_back(const std::string &line) {
465472
if (this->loaded_chunks.empty()) {
466473
this->loaded_chunks.emplace_back().push_back(line);
467474
return;
468475
}
469-
470-
this->total_lines++;
476+
477+
this->should_count = true;
478+
this->size();
471479

472480
size_t chunks_size {this->loaded_chunks.size()};
473481
ekg::io::chunk_t &chunk {this->loaded_chunks.at(chunks_size - (chunks_size != 0))};
@@ -484,7 +492,8 @@ std::string &ekg::text::emplace_back() {
484492
return this->loaded_chunks.emplace_back().emplace_back();
485493
}
486494

487-
this->total_lines++;
495+
this->should_count = true;
496+
this->size();
488497

489498
size_t chunks_size {this->loaded_chunks.size()};
490499
ekg::io::chunk_t &chunk {this->loaded_chunks.at(chunks_size - (chunks_size != 0))};
@@ -496,17 +505,36 @@ std::string &ekg::text::emplace_back() {
496505
}
497506

498507
size_t ekg::text::lines() {
499-
return this->total_lines;
508+
return 0;
509+
}
510+
511+
size_t ekg::text::size() {
512+
if (this->should_count) {
513+
this->total_chars = 0;
514+
for (ekg::io::chunk_t &chunk : this->loaded_chunks) {
515+
for (std::string &lines : chunk) {
516+
this->total_chars += lines.size();
517+
}
518+
}
519+
520+
this->should_count = false;
521+
}
522+
523+
return this->total_chars;
500524
}
501525

502526
size_t ekg::text::chunks() {
503527
return this->loaded_chunks.size();
504528
}
505529

506-
bool ekg::text::audited() {
507-
bool should {this->was_audited};
530+
void ekg::text::unset_audited() {
508531
this->was_audited = false;
509-
return should;
532+
}
533+
534+
bool ekg::text::audited() {
535+
this->was_audited = this->was_audited || (this->prev_total_chars != this->total_chars);
536+
this->prev_total_chars = this->total_chars;
537+
return this->was_audited;
510538
}
511539

512540
std::vector<ekg::io::chunk_t> &ekg::text::data() {

0 commit comments

Comments
 (0)