summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-03-02 10:52:08 -0500
committerpommicket <pommicket@gmail.com>2023-03-02 10:52:08 -0500
commit4aebef26deaed5d26fe450193da044f7734051e1 (patch)
tree1bc66ba0db2e41bb78241eda9bf14466e8538f37
parenteddcc7e8c6c02970ac658024b3a8c6b5f416c8a5 (diff)
:previous-position
-rw-r--r--buffer.c10
-rw-r--r--command.c4
-rw-r--r--command.h1
-rw-r--r--main.c1
-rw-r--r--ted.cfg2
-rw-r--r--ted.h4
6 files changed, 21 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index 8371c7c..50bdbe7 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1119,12 +1119,22 @@ void buffer_cursor_move_to_pos(TextBuffer *buffer, BufferPos pos) {
if (buffer_pos_eq(buffer->cursor_pos, pos)) {
return;
}
+
+ if (labs((long)buffer->cursor_pos.line - (long)pos.line) > 20) {
+ // if this is a big jump, update the previous cursor pos
+ buffer->prev_cursor_pos = buffer->cursor_pos;
+ }
+
buffer->cursor_pos = pos;
buffer->selection = false;
buffer_scroll_to_cursor(buffer);
signature_help_retrigger(buffer->ted);
}
+void buffer_cursor_move_to_prev_pos(TextBuffer *buffer) {
+ buffer_cursor_move_to_pos(buffer, buffer->prev_cursor_pos);
+}
+
i64 buffer_cursor_move_left(TextBuffer *buffer, i64 by) {
BufferPos cur_pos = buffer->cursor_pos;
i64 ret = 0;
diff --git a/command.c b/command.c
index e9af9c3..0bad2a6 100644
--- a/command.c
+++ b/command.c
@@ -39,6 +39,7 @@ static CommandName command_names[] = {
{"select-down-blank-line", CMD_SELECT_DOWN_BLANK_LINE},
{"page-up", CMD_PAGE_UP},
{"page-down", CMD_PAGE_DOWN},
+ {"previous-position", CMD_PREVIOUS_POSITION},
{"tab", CMD_TAB},
{"backtab", CMD_BACKTAB},
{"insert-text", CMD_INSERT_TEXT},
@@ -265,6 +266,9 @@ void command_execute(Ted *ted, Command c, i64 argument) {
if (buffer) buffer_select_down_blank_lines(buffer, argument);
autocomplete_close(ted);
break;
+ case CMD_PREVIOUS_POSITION:
+ buffer_cursor_move_to_prev_pos(buffer);
+ break;
case CMD_INSERT_TEXT: {
const char *str = arg_get_string(ted, argument);
diff --git a/command.h b/command.h
index 6e8a57b..15c824b 100644
--- a/command.h
+++ b/command.h
@@ -47,6 +47,7 @@ typedef enum {
CMD_START_OF_FILE,
/// move cursor to end of buffer
CMD_END_OF_FILE,
+ CMD_PREVIOUS_POSITION,
CMD_SELECT_START_OF_FILE,
CMD_SELECT_END_OF_FILE,
/// select entire buffer
diff --git a/main.c b/main.c
index 5180282..c5c263a 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,6 @@ FUTURE FEATURES:
- styles ([color] sections)
- for this, it would be nice to have #include in ted.cfg
- make go-to-definition/hover/highlight modifier key configurable
-- return to previous location in buffer
- font setting & support for multiple fonts to cover more characters
- support for variable-width fonts
- robust find (results shouldn't move around when you type things)
diff --git a/ted.cfg b/ted.cfg
index 82fd2eb..3304ecb 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -211,6 +211,8 @@ Shift+End = :select-end-of-line
Ctrl+End = :end-of-file
Ctrl+Shift+End = :select-end-of-file
Ctrl+a = :select-all
+# go to previous cursor position
+Ctrl+p = :previous-position
# insertion
Tab = :tab
diff --git a/ted.h b/ted.h
index 82b123d..d1f758e 100644
--- a/ted.h
+++ b/ted.h
@@ -342,6 +342,8 @@ typedef struct {
BufferPos cursor_pos;
/// if `selection` is true, the text between `selection_pos` and `cursor_pos` is selected.
BufferPos selection_pos;
+ /// "previous" position of cursor, for CMD_PREVIOUS_POSITION
+ BufferPos prev_cursor_pos;
/// "line buffers" are buffers which can only have one line of text (used for inputs)
bool is_line_buffer;
/// is anything selected?
@@ -975,6 +977,8 @@ i64 buffer_pos_move_right_words(TextBuffer *buffer, BufferPos *pos, i64 nwords);
i64 buffer_cursor_move_left_words(TextBuffer *buffer, i64 nwords);
/// returns the number of words successfully moved by.
i64 buffer_cursor_move_right_words(TextBuffer *buffer, i64 nwords);
+/// move cursor to "previous" position (i.e. \ref CMD_PREVIOUS_POSITION)
+void buffer_cursor_move_to_prev_pos(TextBuffer *buffer);
/// Returns a string of word characters (see is32_word) around the position,
/// or an empty string if neither of the characters to the left and right of the cursor are word characters.
/// NOTE: The string is invalidated when the buffer is changed!!!