Add Trim trailing whitespace
This commit is contained in:
@@ -85,6 +85,32 @@ void Command_IndentSelectedLines(View *view, bool shift = false) {
|
|||||||
view->update_scroll = false;
|
view->update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Command_TrimTrailingWhitespace(View *view) {
|
||||||
|
Scratch scratch;
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
|
BeforeEdit(buffer, view->carets);
|
||||||
|
MergeCarets(view);
|
||||||
|
|
||||||
|
Array<Edit> edits = {scratch};
|
||||||
|
for (Int i = 0; i < buffer->line_starts.len; i += 1) {
|
||||||
|
Range range = GetLineRangeWithoutNL(*buffer, i);
|
||||||
|
Int whitespace_end = range.max;
|
||||||
|
for (; whitespace_end > range.min; whitespace_end -= 1) {
|
||||||
|
U16 w = buffer->data[whitespace_end - 1];
|
||||||
|
bool is_whitespace = w == ' ' || w == '\t' || w == '\v' || w == '\r';
|
||||||
|
if (!is_whitespace) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Range whitespace_range = {whitespace_end, range.max};
|
||||||
|
AddEdit(&edits, whitespace_range, L"");
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyEdits(buffer, edits);
|
||||||
|
AfterEdit(buffer, &edits, &view->carets, !KILL_SELECTION);
|
||||||
|
view->update_scroll = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool SHIFT_PRESSED = true;
|
bool SHIFT_PRESSED = true;
|
||||||
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
||||||
Assert(direction == DIR_UP || direction == DIR_DOWN);
|
Assert(direction == DIR_UP || direction == DIR_DOWN);
|
||||||
@@ -420,6 +446,10 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
search = true;
|
search = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Ctrl(SDLK_W)) {
|
||||||
|
Command_TrimTrailingWhitespace(view);
|
||||||
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_BACKSPACE)) {
|
if (Ctrl(SDLK_BACKSPACE)) {
|
||||||
Command_Delete(view, DIR_LEFT, CTRL_PRESSED);
|
Command_Delete(view, DIR_LEFT, CTRL_PRESSED);
|
||||||
search = true;
|
search = true;
|
||||||
@@ -572,7 +602,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
*c = ChangeFront(*c, p);
|
*c = ChangeFront(*c, p);
|
||||||
} else if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
|
} else if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
|
||||||
Caret *c = &view->carets[0];
|
Caret *c = &view->carets[0];
|
||||||
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
|
if (InBounds({c->range.min, c->range.max + 1}, p)) {
|
||||||
c->range = EncloseWord(*buffer, p);
|
c->range = EncloseWord(*buffer, p);
|
||||||
view->selection_anchor = c->range;
|
view->selection_anchor = c->range;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
- scrolling in fullscreen is busted because no space outside of window
|
- scrolling in fullscreen is busted because no space outside of window
|
||||||
- scrolling when clicking on scroller is busted
|
- scrolling when clicking on scroller is busted
|
||||||
- page up and down should also scroll and leave you in exactly same scroll
|
- page up and down should also scroll and leave you in exactly same scroll
|
||||||
- Shift + click is not selecting!!!
|
- something about mouse stuff is busted and it randomly does big selections and stuff like that
|
||||||
|
|
||||||
- underline the word which can be loaded / executed
|
- underline the word which can be loaded / executed
|
||||||
- search as a command to execute which is going to be in the title bar
|
- search as a command to execute which is going to be in the title bar
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
- Ctrl + G should select the line number in bar
|
- Ctrl + G should select the line number in bar
|
||||||
- How to make search into bar?
|
- How to make search into bar?
|
||||||
- command window should close on esacpe but make it more coherent
|
- command window should close on esacpe but make it more coherent
|
||||||
|
- auto register commands
|
||||||
|
|
||||||
- simulation:
|
- simulation:
|
||||||
- make the editor replayable, store events and then replay
|
- make the editor replayable, store events and then replay
|
||||||
|
|||||||
Reference in New Issue
Block a user