Compare commits
3 Commits
1a6159e0ec
...
ecbc800fdd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecbc800fdd | ||
|
|
753c9199b6 | ||
|
|
eb19ba6037 |
@@ -9,7 +9,6 @@
|
||||
- Window position: vscode opens in fullscreen and then remembers what position it was close in (could be a config option)
|
||||
- On Linux: Try to implement is_debugger_present()
|
||||
- Probably shouldn't emit (Key pressed when ctrl etc. is not clicked!!)
|
||||
- Brace, bracket, paren indenting?
|
||||
|
||||
- OnUpdate view hooks!
|
||||
- OnSave buffer hooks which will execute the config on save
|
||||
|
||||
@@ -519,47 +519,20 @@ API Int SkipSpaces(Buffer *buffer, Int seek) {
|
||||
return seek;
|
||||
}
|
||||
|
||||
API Int FindScopeEnd(Buffer *buffer, Int seek, Int max_seek, char16_t open, char16_t close) {
|
||||
char16_t right = GetChar(buffer, seek);
|
||||
if (right == open) {
|
||||
int scope = 1;
|
||||
Int i = seek + 1;
|
||||
for (; i < seek + max_seek && i < buffer->len; i += 1) {
|
||||
char16_t c = GetChar(buffer, i);
|
||||
|
||||
if (open == close && c == '\\') {
|
||||
i += 1;
|
||||
} else if (open == close && c == open) {
|
||||
scope -= 1;
|
||||
} else if (c == open) {
|
||||
scope += 1;
|
||||
} else if (c == close) {
|
||||
scope -= 1;
|
||||
API Int FindAnyScopeBegin(Buffer *buffer, Int pos) {
|
||||
int inner_scope = 0;
|
||||
for (Int i = pos - 1; i >= 0; i -= 1) {
|
||||
if (buffer->str[i] == '{' || buffer->str[i] == '[' || buffer->str[i] == '(') {
|
||||
if (inner_scope == 0) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if (c == u'\n' || scope == 0) break;
|
||||
inner_scope -= 1;
|
||||
}
|
||||
|
||||
if (scope == 0) seek = i;
|
||||
}
|
||||
return seek;
|
||||
}
|
||||
|
||||
API Range EncloseScope(Buffer *buffer, Int pos_min, Int pos_max, char16_t open, char16_t close) {
|
||||
Range result = {pos_min, pos_max};
|
||||
for (Int i = pos_min - 1; i >= 0; i -= 1) {
|
||||
if (buffer->str[i] == open) {
|
||||
result.min = i;
|
||||
break;
|
||||
if (buffer->str[i] == '}' || buffer->str[i] == ']' || buffer->str[i] == ')') {
|
||||
inner_scope += 1;
|
||||
}
|
||||
}
|
||||
for (Int i = pos_max; i < buffer->len; i += 1) {
|
||||
if (buffer->str[i] == close) {
|
||||
result.max = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
API Range EncloseLine(Buffer *buffer, Int pos) {
|
||||
|
||||
@@ -120,7 +120,6 @@ API Int GetPrevEmptyLineStart(Buffer *buffer, Int pos);
|
||||
API Range EncloseWord(Buffer *buffer, Int pos);
|
||||
API Int SkipSpaces(Buffer *buffer, Int seek);
|
||||
API Int FindScopeEnd(Buffer *buffer, Int seek, Int max_seek, char16_t open, char16_t close);
|
||||
API Range EncloseScope(Buffer *buffer, Int pos_min, Int pos_max, char16_t open, char16_t close);
|
||||
API Range EncloseLine(Buffer *buffer, Int pos);
|
||||
API Range EncloseFullLine(Buffer *buffer, Int pos);
|
||||
API Int OffsetByLine(Buffer *buffer, Int pos, Int line_offset);
|
||||
|
||||
@@ -1365,20 +1365,22 @@ void CMD_DeleteForwardBoundary() {
|
||||
|
||||
void CMD_InsertNewLineUp() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
MoveCursorToSide(active.view, DIR_LEFT);
|
||||
IdentedNewLine(active.view);
|
||||
IndentedNewLine(active.view);
|
||||
MoveCarets(active.view, DIR_UP);
|
||||
} RegisterCommand(CMD_InsertNewLineUp, "ctrl-shift-enter");
|
||||
|
||||
void CMD_InsertNewLineDown() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
SaveCaretHistoryBeforeBeginEdit(active.buffer, active.view->carets);
|
||||
MoveCursorToSide(active.view, DIR_RIGHT);
|
||||
IdentedNewLine(active.view);
|
||||
IndentedNewLine(active.view);
|
||||
} RegisterCommand(CMD_InsertNewLineDown, "ctrl-enter");
|
||||
|
||||
void CMD_NewLine() {
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
IdentedNewLine(active.view);
|
||||
IndentedNewLine(active.view);
|
||||
} RegisterCommand(CMD_NewLine, "enter | shift-enter");
|
||||
|
||||
void CMD_CreateCaretOnNextFind() {
|
||||
|
||||
@@ -134,16 +134,17 @@ String16 FetchFuzzyViewLoadLine(View *view) {
|
||||
return string;
|
||||
}
|
||||
|
||||
void IdentedNewLine(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Scratch scratch;
|
||||
void IndentedNewLine(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Scratch scratch;
|
||||
Array<Edit> edits = BeginEdit(scratch, buffer, view->carets);
|
||||
MergeCarets(buffer, &view->carets);
|
||||
For(view->carets) {
|
||||
Int front = GetFront(it);
|
||||
Int line = PosToLine(buffer, front);
|
||||
Int indent = GetLineIndent(buffer, line);
|
||||
String string = Format(scratch, "\n%.*s", (int)indent, " ");
|
||||
Int front = GetFront(it);
|
||||
Int scope_begin = FindAnyScopeBegin(buffer, front); // @todo: this could be problematic in large source files!
|
||||
Int line = PosToLine(buffer, scope_begin);
|
||||
Int indent = GetLineIndent(buffer, line) + IndentSize;
|
||||
String string = Format(scratch, "\n%.*s", (int)indent, " ");
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
AddEdit(&edits, it.range, string16);
|
||||
}
|
||||
@@ -662,15 +663,6 @@ void EncloseLine(View *view) {
|
||||
}
|
||||
}
|
||||
|
||||
void EncloseScope(View *view) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
For (view->carets) {
|
||||
it.range = EncloseScope(buffer, it.range.min - 1, it.range.max + 1, u'(', u')');
|
||||
it.range.min = Clamp(buffer, it.range.min + 1);
|
||||
it.range.max = Clamp(buffer, it.range.max - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectAllOccurences(View *view, String16 needle) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Scratch scratch;
|
||||
|
||||
@@ -274,7 +274,7 @@ void JumpBack(Window *window) {
|
||||
window->active_view = c.view_id;
|
||||
View *view = GetView(c.view_id);
|
||||
view->carets[0] = c.caret;
|
||||
UpdateScroll(window, true);
|
||||
CenterView(window->id);
|
||||
|
||||
if (window->goto_history.len) {
|
||||
GotoCrumb *next = GetLast(window->goto_history);
|
||||
@@ -294,7 +294,7 @@ void JumpForward(Window *window) {
|
||||
window->active_view = c.view_id;
|
||||
View *view = GetView(c.view_id);
|
||||
view->carets[0] = c.caret;
|
||||
UpdateScroll(window, true);
|
||||
CenterView(window->id);
|
||||
|
||||
if (window->goto_redo.len) {
|
||||
GotoCrumb *next = GetLast(window->goto_redo);
|
||||
|
||||
@@ -43,7 +43,7 @@ void CMD_ShowDebugBufferList() {
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "ctrl-shift-alt-p", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
|
||||
void CMD_ShowBufferList() {
|
||||
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == CMD_ShowBufferList) {
|
||||
|
||||
Reference in New Issue
Block a user