Introduction
Introduction Statistics Contact Development Disclaimer Help
tImprove(?) pasting and add backwards pasting (P) - ledit - Text editor (WIP)
git clone git://lumidify.org/ledit.git (fast, but not encrypted)
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow)
Log
Files
Refs
README
LICENSE
---
commit 5c1f64919a8a2974c107614f144fd932aa6db1bf
parent 271d268ba17415be9808bb1da36389036b4eb95d
Author: lumidify <[email protected]>
Date: Mon, 1 Nov 2021 16:47:45 +0100
Improve(?) pasting and add backwards pasting (P)
Diffstat:
M keys_basic.c | 68 +++++++++++++++++++++++++++++…
M keys_basic_config.h | 2 ++
2 files changed, 67 insertions(+), 3 deletions(-)
---
diff --git a/keys_basic.c b/keys_basic.c
t@@ -1,3 +1,4 @@
+/* FIXME: cursor isn't shown on spaces at end of softlines */
#include <stdio.h>
#include <stdlib.h>
t@@ -647,6 +648,10 @@ key_d_cb(ledit_buffer *buffer, int line, int char_pos, en…
/* FIXME: don't use the pango functions directly so normalize_and_set_pango_te…
always called properly */
+/* Note that these paste functions are a bit weird when working with softlines…
+ they always make sure the pasted text is separated from the surrounding tex…
+ hard lines, which may be unexpected, but the alternatives I could think of …
+ even weirder */
static struct action
paste_normal(ledit_buffer *buffer, char *text, int len) {
(void)text;
t@@ -666,11 +671,18 @@ paste_normal(ledit_buffer *buffer, char *text, int len) {
buffer, buffer->cur_line, sl->start_index + sl->length,
"\n", -1, buffer->cur_line, buffer->cur_index, 1
);
- /* remove trailing newline if it exists - this may be hacky */
int text_len = paste_buffer->len;
- if (paste_buffer->text[paste_buffer->len-1] == '\n') {
+ ll = ledit_buffer_get_line(buffer, buffer->cur_line + 1);
+ if (ll->len == 0 && paste_buffer->text[text_len-1] == '\n') {
+ /* remove trailing newline if it exists and text is al…
text_len--;
- paste_buffer->text[paste_buffer->len-1] = '\0';
+ paste_buffer->text[text_len] = '\0';
+ } else if (ll->len > 0 && paste_buffer->text[text_len-1] != '\…
+ /* ensure pasted text is on its own hard line */
+ insert_text(
+ buffer, buffer->cur_line + 1, 0,
+ "\n", -1, buffer->cur_line, buffer->cur_index, 0
+ );
}
insert_text(
buffer, buffer->cur_line + 1, 0,
t@@ -690,6 +702,56 @@ paste_normal(ledit_buffer *buffer, char *text, int len) {
}
static struct action
+paste_normal_backwards(ledit_buffer *buffer, char *text, int len) {
+ (void)text;
+ (void)len;
+ if (!paste_buffer) {
+ ledit_window_show_message(buffer->window, "Nothing to paste", …
+ discard_repetition_stack();
+ return (struct action){ACTION_NONE, NULL};
+ }
+ if (paste_buffer_line_based) {
+ int x, softline;
+ ledit_buffer_wipe_line_cursor_attrs(buffer, buffer->cur_line);
+ ledit_line *ll = ledit_buffer_get_line(buffer, buffer->cur_lin…
+ pango_layout_index_to_line_x(ll->layout, buffer->cur_index, 0,…
+ PangoLayoutLine *sl = pango_layout_get_line_readonly(ll->layou…
+ insert_text(
+ buffer, buffer->cur_line, sl->start_index,
+ "\n", -1, buffer->cur_line, buffer->cur_index, 1
+ );
+ int text_len = paste_buffer->len;
+ ll = ledit_buffer_get_line(buffer, buffer->cur_line);
+ if (paste_buffer->text[text_len-1] == '\n') {
+ /* remove trailing newline if it exists */
+ text_len--;
+ paste_buffer->text[text_len] = '\0';
+ }
+ int new_line = buffer->cur_line;
+ if (ll->len > 0) {
+ /* ensure pasted text is on its own hard line */
+ insert_text(
+ buffer, buffer->cur_line, ll->len,
+ "\n", -1, buffer->cur_line, buffer->cur_index, 0
+ );
+ new_line = buffer->cur_line + 1;
+ }
+ insert_text(
+ buffer, new_line, 0,
+ paste_buffer->text, text_len, new_line, 0, 0
+ );
+ } else {
+ insert_text(
+ buffer, buffer->cur_line, buffer->cur_index,
+ paste_buffer->text, paste_buffer->len, buffer->cur_line, b…
+ );
+ }
+ ledit_buffer_set_line_cursor_attrs(buffer, buffer->cur_line, buffer->c…
+ finalize_repetition_stack();
+ return (struct action){ACTION_NONE, NULL};
+}
+
+static struct action
key_x(ledit_buffer *buffer, char *text, int len) {
(void)buffer;
(void)text;
diff --git a/keys_basic_config.h b/keys_basic_config.h
t@@ -65,6 +65,7 @@ static struct action scroll_lines_up(ledit_buffer *buffer, c…
static struct action scroll_lines_down(ledit_buffer *buffer, char *text, int l…
static struct action move_to_line(ledit_buffer *buffer, char *text, int len);
static struct action paste_normal(ledit_buffer *buffer, char *text, int len);
+static struct action paste_normal_backwards(ledit_buffer *buffer, char *text, …
/* FIXME: maybe sort these and use binary search
-> but that would mess with the catch-all keys */
t@@ -123,6 +124,7 @@ static struct key keys_en[] = {
{"u", ControlMask, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &scroll_lin…
{"G", 0, 0, NORMAL, KEY_ANY, KEY_NUMBERALLOWED, &move_to_line},
{"p", 0, 0, NORMAL, KEY_ANY, KEY_ANY, &paste_normal},
+ {"P", 0, 0, NORMAL, KEY_ANY, KEY_ANY, &paste_normal_backwards},
{"", 0, 0, INSERT, KEY_ANY, KEY_ANY, &insert_mode_insert_text}
};
You are viewing proxied material from lumidify.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.