Remove IndentString
This commit is contained in:
@@ -169,7 +169,6 @@ RegisterVariable(Int, WaitForEvents, 1);
|
||||
RegisterVariable(Int, DrawLineNumbers, 1);
|
||||
RegisterVariable(Int, DrawScrollbar, 1);
|
||||
RegisterVariable(Int, IndentSize, 4);
|
||||
RegisterVariable(String, IndentKindWhichIsTabsOrSpaces, "spaces");
|
||||
RegisterVariable(Int, FontSize, 15);
|
||||
RegisterVariable(String, PathToFont, "");
|
||||
RegisterVariable(Float, UndoMergeTime, 0.3);
|
||||
|
||||
@@ -136,42 +136,6 @@ String16 FetchLoadWord(View *view) {
|
||||
return string;
|
||||
}
|
||||
|
||||
char16_t GetIndentChar() {
|
||||
char16_t c = u' ';
|
||||
if (IndentKindWhichIsTabsOrSpaces == "spaces") {
|
||||
c = u' ';
|
||||
} else if (IndentKindWhichIsTabsOrSpaces == "tabs") {
|
||||
c = u'\t';
|
||||
} else {
|
||||
ReportErrorf("Invalid IndentKindWhichIsTabsOrSpaces value: %S", IndentKindWhichIsTabsOrSpaces);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
String16 GetIndentString(Allocator allocator, Int indent_size) {
|
||||
char16_t *result = AllocArray(allocator, char16_t, indent_size + 1);
|
||||
char16_t c = GetIndentChar();
|
||||
|
||||
for (int i = 0; i < indent_size; i += 1) {
|
||||
result[i] = c;
|
||||
}
|
||||
result[indent_size] = 0;
|
||||
String16 res = {result, indent_size};
|
||||
return res;
|
||||
}
|
||||
|
||||
String GetIndentString8(Allocator allocator, Int indent_size) {
|
||||
char *result = AllocArray(allocator, char, indent_size + 1);
|
||||
char c = (char)GetIndentChar();
|
||||
|
||||
for (int i = 0; i < indent_size; i += 1) {
|
||||
result[i] = c;
|
||||
}
|
||||
result[indent_size] = 0;
|
||||
String res = {result, indent_size};
|
||||
return res;
|
||||
}
|
||||
|
||||
Array<Range> GetSelectedLinesSortedExclusive(Allocator allocator, View *view) {
|
||||
Scratch scratch(allocator);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
@@ -208,8 +172,7 @@ void IndentedNewLine(View *view) {
|
||||
For(view->carets) {
|
||||
Int front = GetFront(it);
|
||||
Int indent = GetLineIndent(buffer, PosToLine(buffer, front));
|
||||
String indent_string = GetIndentString8(scratch, indent);
|
||||
String string = Format(scratch, "\n%S", indent_string);
|
||||
String string = Format(scratch, "\n%.*s", IndentSize, " ");
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
AddEdit(&edits, it.range, string16);
|
||||
}
|
||||
@@ -563,7 +526,7 @@ void Delete(View *view, int direction, bool ctrl = false) {
|
||||
// Delete indent in multiple of IndentSize
|
||||
Range indent_range = GetIndentRangeAtPos(buffer, it.range.min);
|
||||
if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) {
|
||||
Int offset = it.range.min - indent_range.min;
|
||||
Int offset = it.range.min - indent_range.min;
|
||||
Int to_delete = (offset % (IndentSize));
|
||||
if (to_delete == 0) to_delete = IndentSize;
|
||||
to_delete = Clamp(to_delete, (Int)1, IndentSize);
|
||||
@@ -599,19 +562,19 @@ void IndentSelectedLines(View *view, bool shift = false) {
|
||||
Array<Edit> edits = BeginEdit(scratch, buffer, view->carets);
|
||||
MergeCarets(buffer, &view->carets);
|
||||
|
||||
char16_t indent_char = GetIndentChar();
|
||||
String16 indent_string = GetIndentString(scratch, IndentSize);
|
||||
Array<Range> line_ranges_to_indent = GetSelectedLinesSortedExclusive(scratch, view);
|
||||
For(line_ranges_to_indent) {
|
||||
For (line_ranges_to_indent) {
|
||||
for (Int i = it.min; i < it.max; i += 1) {
|
||||
Range pos_range_of_line = GetLineRange(buffer, i);
|
||||
|
||||
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] == indent_char; i += 1) {
|
||||
for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == u' '; i += 1) {
|
||||
whitespace_len += 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user