summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-10-19 23:12:04 +0200
committerAlbert Cervin <albert@acervin.com>2023-10-19 23:12:04 +0200
commit05f61f7e7ab314187ff5d28281a6d6d7facb17ae (patch)
tree193055fddeb00fecb5bd3f47794af5e950668112
parent54c9b4b533210b77be998f458ff96bdc54272f64 (diff)
downloaddged-05f61f7e7ab314187ff5d28281a6d6d7facb17ae.tar.gz
dged-05f61f7e7ab314187ff5d28281a6d6d7facb17ae.tar.xz
dged-05f61f7e7ab314187ff5d28281a6d6d7facb17ae.zip
follow-up fixes after refactoring
-rw-r--r--src/dged/buffer.c7
-rw-r--r--src/dged/buffer_view.c42
-rw-r--r--src/main/search-replace.c10
3 files changed, 37 insertions, 22 deletions
diff --git a/src/dged/buffer.c b/src/dged/buffer.c
index 117fab5..c95da91 100644
--- a/src/dged/buffer.c
+++ b/src/dged/buffer.c
@@ -753,9 +753,10 @@ void render_line(struct text_chunk *line, void *userdata) {
// calculate character properties
uint32_t nproperties = 0;
- text_get_properties(cmdbuf->buffer->text,
- (struct location){.line = line->line, .col = coli + cmdbuf->origin.col},
- properties, 16, &nproperties);
+ text_get_properties(
+ cmdbuf->buffer->text,
+ (struct location){.line = line->line, .col = coli + cmdbuf->origin.col},
+ properties, 16, &nproperties);
// handle changes to properties
uint32_t nnew_props = 0;
diff --git a/src/dged/buffer_view.c b/src/dged/buffer_view.c
index 2c69161..a95e3b0 100644
--- a/src/dged/buffer_view.c
+++ b/src/dged/buffer_view.c
@@ -348,6 +348,11 @@ void buffer_view_update(struct buffer_view *view,
uint32_t height = params->height;
uint32_t width = params->width;
+ /* Make sure the dot is always inside buffer limits.
+ * It can be outside for example if the text is changed elsewhere. */
+ view->dot = buffer_clamp(view->buffer, (int64_t)view->dot.line,
+ (int64_t)view->dot.col);
+
// render modeline
uint32_t modeline_height = 0;
if (view->modeline != NULL) {
@@ -358,6 +363,16 @@ void buffer_view_update(struct buffer_view *view,
height -= modeline_height;
+ // update scroll position if needed
+ if (view->dot.line >= view->scroll.line + height ||
+ view->dot.line < view->scroll.line) {
+ // put dot in the middle, height-wise
+ view->scroll.line =
+ buffer_clamp(view->buffer, (int64_t)view->dot.line - params->height / 2,
+ 0)
+ .line;
+ }
+
// render line numbers
uint32_t linum_width = 0;
if (view->line_numbers) {
@@ -367,20 +382,10 @@ void buffer_view_update(struct buffer_view *view,
width -= linum_width;
view->fringe_width = linum_width;
- /* Make sure the dot is always inside buffer limits.
- * It can be outside for example if the text is changed elsewhere. */
- view->dot = buffer_clamp(view->buffer, (int64_t)view->dot.line,
- (int64_t)view->dot.col);
-
- // update scroll position if needed
- if (view->dot.line >= view->scroll.line + height || view->dot.line < view->scroll.line) {
- // put dot in the middle, height-wise
- view->scroll.line = buffer_clamp(view->buffer, (int64_t)view->dot.line - params->height / 2,
- 0).line;
- }
-
- if (view->dot.col >= view->scroll.col + width || view->dot.col < view->scroll.col) {
- view->scroll.col = buffer_clamp(view->buffer, view->dot.line, view->dot.col).col;
+ if (view->dot.col >= view->scroll.col + width ||
+ view->dot.col < view->scroll.col) {
+ view->scroll.col =
+ buffer_clamp(view->buffer, view->dot.line, view->dot.col).col;
}
// color region
@@ -412,6 +417,15 @@ void buffer_view_update(struct buffer_view *view,
};
buffer_update(view->buffer, &bufparams);
+ /* Make sure the dot is always inside buffer limits.
+ * Updating the buffer above could have removed text.
+ * TODO: this is not really correct, since it may have caused
+ * changes that would need a re-eval of scroll and redraw.
+ * Hooks should prob not get width and height and be ran before rendering.
+ */
+ view->dot = buffer_clamp(view->buffer, (int64_t)view->dot.line,
+ (int64_t)view->dot.col);
+
// draw buffer commands nested inside this command list
command_list_draw_command_list(params->commands, buf_cmds);
buffer_clear_text_properties(view->buffer);
diff --git a/src/main/search-replace.c b/src/main/search-replace.c
index cd12d5d..a94e2b1 100644
--- a/src/main/search-replace.c
+++ b/src/main/search-replace.c
@@ -275,9 +275,8 @@ void do_search(struct buffer_view *view, const char *pattern, bool reverse) {
// find the "nearest" match
if (m.found) {
- buffer_view_goto(view,
- (struct location){.line = m.closest.begin.line,
- .col = m.closest.begin.col});
+ buffer_view_goto(view, (struct location){.line = m.closest.begin.line,
+ .col = m.closest.begin.col});
} else {
minibuffer_echo_timeout(4, "%s not found", pattern);
}
@@ -291,7 +290,8 @@ int32_t search_interactive(struct command_ctx ctx, int argc,
// recall the last search, if any
if (g_last_search != NULL) {
struct buffer_view *view = window_buffer_view(minibuffer_window());
- buffer_set_text(view->buffer, (uint8_t *)g_last_search, strlen(g_last_search));
+ buffer_set_text(view->buffer, (uint8_t *)g_last_search,
+ strlen(g_last_search));
pattern = g_last_search;
}
} else {
@@ -302,7 +302,7 @@ int32_t search_interactive(struct command_ctx ctx, int argc,
pattern = p;
}
- minibuffer_set_prompt(search_prompt(*(bool*)ctx.userdata));
+ minibuffer_set_prompt(search_prompt(*(bool *)ctx.userdata));
if (pattern != NULL) {
do_search(window_buffer_view(minibuffer_target_window()), pattern,