Delete indent in multiples of indent size
This commit is contained in:
@@ -402,6 +402,11 @@ Int GetPrevChar(Buffer *buffer, Int pos) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wchar_t GetChar(Buffer *buffer, Int pos) {
|
||||||
|
if (pos >= 0 && pos < buffer->len) return buffer->str[pos];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Int GetLineIndent(Buffer *buffer, Int line) {
|
Int GetLineIndent(Buffer *buffer, Int line) {
|
||||||
String16 string = GetLineStringWithoutNL(*buffer, line);
|
String16 string = GetLineStringWithoutNL(*buffer, line);
|
||||||
Int indent = 0;
|
Int indent = 0;
|
||||||
@@ -421,6 +426,13 @@ Int GetIndentAtPos(Buffer *buffer, Int pos) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Range GetIndentRangeAtPos(Buffer *buffer, Int pos) {
|
||||||
|
Int line = PosToLine(*buffer, pos);
|
||||||
|
Int indent = GetLineIndent(buffer, line);
|
||||||
|
Range range = GetLineRangeWithoutNL(*buffer, line);
|
||||||
|
return {range.min, range.min + indent};
|
||||||
|
}
|
||||||
|
|
||||||
Range EncloseScope(Buffer *buffer, Int pos, wchar_t open, wchar_t close) {
|
Range EncloseScope(Buffer *buffer, Int pos, wchar_t open, wchar_t close) {
|
||||||
Range result = {pos, pos};
|
Range result = {pos, pos};
|
||||||
for (Int i = pos; i >= 0; i -= 1) {
|
for (Int i = pos; i >= 0; i -= 1) {
|
||||||
|
|||||||
@@ -342,7 +342,25 @@ void Command_Delete(View *view, int direction, bool ctrl = false) {
|
|||||||
// Select things to delete
|
// Select things to delete
|
||||||
For(view->carets) {
|
For(view->carets) {
|
||||||
if (GetSize(it.range)) continue;
|
if (GetSize(it.range)) continue;
|
||||||
it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED);
|
if (direction == DIR_LEFT) {
|
||||||
|
|
||||||
|
// Delete indent in multiple of IndentSize
|
||||||
|
Range indent_range = GetIndentRangeAtPos(buffer, it.range.min);
|
||||||
|
if (it.range.min > indent_range.min && it.range.max <= indent_range.max) {
|
||||||
|
Int offset = it.range.min - indent_range.min;
|
||||||
|
Int to_delete = (offset % (StyleIndentSize));
|
||||||
|
if (to_delete == 0) to_delete = StyleIndentSize;
|
||||||
|
to_delete = Clamp(to_delete, (Int)1, StyleIndentSize);
|
||||||
|
for (Int i = 0; i < to_delete; i += 1) {
|
||||||
|
it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it = MoveCaret(buffer, it, direction, ctrl, SHIFT_PRESSED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MergeCarets(view);
|
MergeCarets(view);
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
- fix the bug where when we create a new view the anchor value on new view is compromised because and incongruent with position so we select from start of buffer
|
- fix the bug where when we create a new view the anchor value on new view is compromised because and incongruent with position so we select from start of buffer
|
||||||
- hand cursor on hover over underlined word
|
- hand cursor on hover over underlined word
|
||||||
|
|
||||||
- ctrl + q to open, alt + q to go back
|
- delete multiple spaces (based on indent size) on delete instead one by one. It should only work at beginning of line, in indent area
|
||||||
- delete multiple spaces (based on indent size) on delete instead one by one
|
|
||||||
- switch to previous view (ctrl + tab)
|
- switch to previous view (ctrl + tab)
|
||||||
- save location on open and allow for revert (buffer id? or buffer name? - buffer name can change, buffer id is harder to serialize, I guess if internal only then buffer id)
|
- save location on open and allow for revert (buffer id? or buffer name? - buffer name can change, buffer id is harder to serialize, I guess if internal only then buffer id)
|
||||||
- we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace
|
- we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace
|
||||||
|
|||||||
Reference in New Issue
Block a user