Fix offseting carets after edit without killing selection, add dedent
This commit is contained in:
@@ -132,11 +132,16 @@ void AfterEdit(Buffer *buffer, Array<Edit> *edits, Array<Caret> *carets, bool ki
|
||||
for (Int i = 0; i < carets->len; i += 1) {
|
||||
Caret &old_cursor = carets->data[i];
|
||||
Caret &new_cursor = new_carets.data[i];
|
||||
|
||||
if (old_cursor.range.min == edit.range.min) {
|
||||
new_cursor.range.min += insert_size;
|
||||
new_cursor.range.max += insert_size;
|
||||
} else if (old_cursor.range.min > edit.range.min) {
|
||||
new_cursor.range.min += offset;
|
||||
}
|
||||
|
||||
if (old_cursor.range.max == edit.range.max) {
|
||||
new_cursor.range.max += insert_size;
|
||||
} else if (old_cursor.range.max > edit.range.max) {
|
||||
new_cursor.range.max += offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ void Command_DuplicateLine(View *view, int direction) {
|
||||
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.min, direction, false));
|
||||
}
|
||||
|
||||
void Command_IndentSelectedLines(View *view) {
|
||||
void Command_IndentSelectedLines(View *view, bool shift = false) {
|
||||
Scratch scratch;
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
|
||||
@@ -65,7 +65,18 @@ void Command_IndentSelectedLines(View *view) {
|
||||
For(line_ranges_to_indent) {
|
||||
for (Int i = it.min; i <= it.max; i += 1) {
|
||||
Range pos_range_of_line = GetLineRange(*buffer, i);
|
||||
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, L" ");
|
||||
|
||||
if (!shift) {
|
||||
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, L" ");
|
||||
} else {
|
||||
String16 string = GetString(*buffer, pos_range_of_line);
|
||||
Int whitespace_len = 0;
|
||||
for (Int i = 0; i < 4 && i < string.len && string.data[i] == ' '; i += 1) {
|
||||
whitespace_len += 1;
|
||||
}
|
||||
|
||||
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min + whitespace_len}, L"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,8 +412,10 @@ void WindowCommand(Event event, Window *window, View *view) {
|
||||
}
|
||||
|
||||
bool search = false;
|
||||
if (Press(SDLK_TAB)) {
|
||||
// Command_Replace(view, L" ");
|
||||
if (Shift(SDLK_TAB)) {
|
||||
Command_IndentSelectedLines(view, SHIFT_PRESSED);
|
||||
search = true;
|
||||
} else if (Press(SDLK_TAB)) {
|
||||
Command_IndentSelectedLines(view);
|
||||
search = true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
- underline the word which can be loaded / executed
|
||||
- search as a command to execute which is going to be in the title bar
|
||||
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
|
||||
|
||||
- commands:
|
||||
- indent selected lines
|
||||
|
||||
Reference in New Issue
Block a user