Fix indenting, dedenting

This commit is contained in:
Krzosa Karol
2026-01-25 17:53:29 +01:00
parent 1c25b39df0
commit 0c488bc313
3 changed files with 12 additions and 8 deletions

View File

@@ -62,6 +62,9 @@ void CWSLexIdentifiers(Array<StringAndDistance> *out_idents, Buffer *buffer) {
}
if (StartsWith(token, CWS.prefix_string) && token != CWS.prefix_string) {
Int pos = token.data - buffer->str;
// Here we are computing distance based on position from currently open
// buffer but should be fine. We are sorting then putting into the array
// and it doesn't displace the original ones so it's fine
Int distance = Absolute(CWS.original_caret_pos - pos);
int64_t value_index = FindValueIndex(&idents, token);
if (value_index != -1) {

View File

@@ -250,7 +250,7 @@ void OnCommand(Event event) {
}
}
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
Caret &caret = selected.view->carets[0];
caret = SetFrontWithAnchor(caret, DocumentAnchor, p);
}

View File

@@ -618,11 +618,19 @@ void IndentSelectedLines(View *view, bool shift = false) {
indent_string.len = IndentSize;
if (!shift) {
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, indent_string);
For (saved_xy) {
if (it.front.y == i) it.front.x += indent_string.len;
if (it.back.y == i) it.back.x += indent_string.len;
}
} else {
Int whitespace_len = 0;
for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == u' '; i += 1) {
whitespace_len += 1;
}
For (saved_xy) {
if (it.front.y == i) it.front.x -= whitespace_len;
if (it.back.y == i) it.back.x -= whitespace_len;
}
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min + whitespace_len}, u"");
}
@@ -633,13 +641,6 @@ void IndentSelectedLines(View *view, bool shift = false) {
for (Int i = 0; i < saved_xy.len; i += 1) {
Caret &caret = view->carets[i];
XYPair &xypair = saved_xy[i];
if (!shift) {
xypair.front.x += IndentSize;
xypair.back.x += IndentSize;
} else {
xypair.front.x -= IndentSize;
xypair.back.x -= IndentSize;
}
Int front = XYToPos(buffer, xypair.front);
Int back = XYToPos(buffer, xypair.back);
caret = MakeCaret(front, back);