EncloseFullLine and enclose scopes on multiple click

This commit is contained in:
Krzosa Karol
2024-08-05 15:49:27 +02:00
parent d81c403a5d
commit e514c29de4
3 changed files with 43 additions and 4 deletions

View File

@@ -363,6 +363,20 @@ Int GetLineEnd(Buffer *buffer, Int pos) {
return range.max;
}
Int GetFullLineStart(Buffer *buffer, Int pos) {
pos = Clamp(pos, (Int)0, buffer->len);
Int line = PosToLine(*buffer, pos);
Range range = GetLineRange(*buffer, line);
return range.min;
}
Int GetFullLineEnd(Buffer *buffer, Int pos) {
pos = Clamp(pos, (Int)0, buffer->len);
Int line = PosToLine(*buffer, pos);
Range range = GetLineRange(*buffer, line);
return range.max;
}
Int GetBufferEnd(Buffer *buffer) {
return buffer->len;
}
@@ -429,6 +443,11 @@ Range EncloseLine(Buffer *buffer, Int pos) {
return result;
}
Range EncloseFullLine(Buffer *buffer, Int pos) {
Range result = {GetFullLineStart(buffer, pos), GetFullLineEnd(buffer, pos)};
return result;
}
Int OffsetByLine(Buffer *buffer, Int pos, Int line_offset) {
XY xy = PosToXY(*buffer, pos);
Int result = XYToPosWithoutNL(*buffer, {xy.col, xy.line + line_offset});

View File

@@ -354,10 +354,25 @@ bool GlobalCommand(Event event) {
}
} else if (event.clicks >= 2) {
view->carets.len = 1;
if (InBounds({caret.range.min - 1, caret.range.max + 1}, p)) {
Range range = EncloseWord(buffer, p);
if (event.clicks == 3) range = EncloseLoadWord(buffer, p);
if (event.clicks >= 4) range = EncloseExecWord(buffer, p);
Range range = EncloseWord(buffer, p);
wchar_t scope = GetChar(buffer, p);
if (scope == '{' || scope == '}') {
range = EncloseScope(buffer, p, '{', '}');
} else if (scope == '(' || scope == ')') {
range = EncloseScope(buffer, p, '(', ')');
} else {
if (event.clicks == 3) {
Range load_word_range = EncloseLoadWord(buffer, p);
if (AreEqual(load_word_range, range)) {
load_word_range = EncloseFullLine(buffer, p);
}
range = load_word_range;
}
if (event.clicks >= 4) range = EncloseFullLine(buffer, p);
}
caret = MakeCaret(range.max, range.min);
} else {
caret = MakeCaret(p);

View File

@@ -2,6 +2,7 @@
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
- ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting
BUG: there is a click hang when switching windows sometimes, you click after select and it doesn't switch active window
BUG: when redo and ctrl pressed a bugged enclosure rect is shown
- mouse execute
- experiment with using multiple cursors to select command and it's input
@@ -9,8 +10,13 @@ BUG: there is a click hang when switching windows sometimes, you click after sel
- each buffer needs a directory even the special ones: C:\a\b\c\+errors?
- open directories - resulting in buffer with dir listing and proper buffer name
- clean \r\n into \n on trim and load
- Dump editor state to file
- make the editor replayable, store events and then replay, be careful about globals
- global config and local config
- load all files in a directory
@@ -19,7 +25,6 @@ BUG: there is a click hang when switching windows sometimes, you click after sel
- Search and replace
- select space between parens,braces but make it good
- make the editor replayable, store events and then replay, be careful about globals
- Implement shell interaction (here we also could use the coroutine library)
- word complete