diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 25a5938..1b0f038 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -35,7 +35,6 @@ New UI Session FEATURE Some decl/function indexing in fuzzy format FEATURE dump text editor state to file, restore state -- Search and replace - word complete - escapeing multiple cursor after ctrl + d should put the cursor where it was (probably will need to swap secondary and primary cursor for new cursor - draw indentation levels like in sublime (those lines) - we render chars one by one so seems relatively easy to figure out if whitespace belongs to beginning of line (make sure to add max value like 40 because of big files) @@ -54,3 +53,21 @@ FEATURE dump text editor state to file, restore state - gap buffer - optimize rendering - command buffer, and vertice buffer instead of vertice buffer with scissor + + + + + + + + + +WORD COMPLETE +1. Tokenize the file (or maybe couple last viewed files) +2. Match the tokens (identifiers) with prefix string and produce a list +3. Remove duplicates +4. Sort by proximity to cursor + +We save the iterator, it's enough for it to be global with unique for it arena +If prefix ask is the same - reuse the iterator go to next word, if there are none go to next buffer ... + else - dump old, create new diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 74b217d..4797c0f 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -10,6 +10,9 @@ union XY { struct {Int col; Int line;}; struct {Int x; Int y; }; }; +struct XYPair { XY front; XY back; }; + + typedef void Function(); struct FunctionData { diff --git a/src/text_editor/view.cpp b/src/text_editor/view.cpp index 584201f..ef846b4 100644 --- a/src/text_editor/view.cpp +++ b/src/text_editor/view.cpp @@ -172,7 +172,7 @@ void IndentedNewLine(View *view) { For(view->carets) { Int front = GetFront(it); Int indent = GetLineIndent(buffer, PosToLine(buffer, front)); - String string = Format(scratch, "\n%.*s", IndentSize, " "); + String string = Format(scratch, "\n%.*s", indent, " "); String16 string16 = ToString16(scratch, string); AddEdit(&edits, it.range, string16); } @@ -400,7 +400,7 @@ void MoveCaretsLine(View *view, int direction) { // Save caret positions to fix them at end to the expected incremented by one positions - struct XYPair { XY front; XY back; }; + // :PreserveXYCarets (kind of) Array saved_xy = {scratch}; For (view->carets) { Add(&saved_xy, {PosToXY(buffer, GetFront(it)), PosToXY(buffer, GetBack(it))}); @@ -562,17 +562,25 @@ void IndentSelectedLines(View *view, bool shift = false) { Array edits = BeginEdit(scratch, buffer, view->carets); MergeCarets(buffer, &view->carets); + // :PreserveXYCarets - maybe make it as one of the strategies of adjusting carets? + Array saved_xy = {scratch}; + For (view->carets) Add(&saved_xy, {PosToXY(buffer, GetFront(it)), PosToXY(buffer, GetBack(it))}); + Array line_ranges_to_indent = GetSelectedLinesSortedExclusive(scratch, view); For (line_ranges_to_indent) { for (Int i = it.min; i < it.max; i += 1) { Range pos_range_of_line = GetLineRange(buffer, i); + String16 string = GetString(buffer, pos_range_of_line); + String16 without_whitespace = Trim(string); + if (without_whitespace.len == 0) { + continue; + } String16 indent_string = u" "; indent_string.len = IndentSize; if (!shift) { AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, indent_string); } else { - String16 string = GetString(buffer, pos_range_of_line); Int whitespace_len = 0; for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == u' '; i += 1) { whitespace_len += 1; @@ -583,6 +591,14 @@ void IndentSelectedLines(View *view, bool shift = false) { } } EndEdit(buffer, &edits, &view->carets, !EndEdit_KillSelection); + + for (Int i = 0; i < saved_xy.len; i += 1) { + Caret &caret = view->carets[i]; + XYPair &xypair = saved_xy[i]; + Int front = XYToPos(buffer, xypair.front); + Int back = XYToPos(buffer, xypair.back); + caret = MakeCaret(front, back); + } view->update_scroll = false; }