New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for prepending to the cutbuffer in addition to replacing it. #353
Changes from 4 commits
3c95f6a
4f8974f
0b2b3a0
1199ecc
7768f3e
f90e10c
bb8c0bb
15dfb27
5d99a3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -534,7 +534,7 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) | |
return buf; | ||
} | ||
|
||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer) | ||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer) | ||
{ | ||
int newpos, size = 0; | ||
|
||
|
@@ -545,7 +545,7 @@ void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer) | |
gui_entry_erase(entry, size, update_cutbuffer); | ||
} | ||
|
||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer) | ||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer) | ||
{ | ||
size_t w = 0; | ||
|
||
|
@@ -554,17 +554,39 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer) | |
if (size == 0 || entry->pos < size) | ||
return; | ||
|
||
if (update_cutbuffer) { | ||
/* put erased text to cutbuffer */ | ||
if (entry->cutbuffer_len < size) { | ||
g_free(entry->cutbuffer); | ||
entry->cutbuffer = g_new(unichar, size+1); | ||
} | ||
switch (update_cutbuffer) { | ||
case CUTBUFFER_UPDATE_PREPEND: | ||
if (entry->cutbuffer_len) { | ||
int cutbuffer_new_size = entry->cutbuffer_len + size; | ||
unichar *tmpcutbuffer = entry->cutbuffer; | ||
entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); | ||
|
||
memcpy(entry->cutbuffer, entry->text + entry->pos - size, | ||
size * sizeof(unichar)); | ||
memcpy(entry->cutbuffer + size, tmpcutbuffer, | ||
|
||
entry->cutbuffer_len * sizeof(unichar)); | ||
entry->cutbuffer_len = cutbuffer_new_size; | ||
entry->cutbuffer[cutbuffer_new_size] = '\0'; | ||
|
||
g_free(tmpcutbuffer); | ||
break; | ||
} | ||
/* fall through to REPLACE if cutbuffer_len was 0 */ | ||
case CUTBUFFER_UPDATE_REPLACE: | ||
/* put erased text to cutbuffer */ | ||
if (entry->cutbuffer_len < size) { | ||
g_free(entry->cutbuffer); | ||
entry->cutbuffer = g_new(unichar, size+1); | ||
} | ||
|
||
entry->cutbuffer_len = size; | ||
entry->cutbuffer[size] = '\0'; | ||
memcpy(entry->cutbuffer, entry->text + entry->pos - size, | ||
size * sizeof(unichar)); | ||
entry->cutbuffer_len = size; | ||
entry->cutbuffer[size] = '\0'; | ||
memcpy(entry->cutbuffer, entry->text + entry->pos - size, | ||
size * sizeof(unichar)); | ||
break; | ||
case CUTBUFFER_UPDATE_NOOP: | ||
break; | ||
} | ||
|
||
if (entry->utf8) | ||
|
@@ -601,7 +623,7 @@ void gui_entry_erase_cell(GUI_ENTRY_REC *entry) | |
gui_entry_draw(entry); | ||
} | ||
|
||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space) | ||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's up with this line being deleted? Mistake or somehow intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was not intentional. Fixed. |
||
int to; | ||
|
||
|
@@ -624,7 +646,6 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space) | |
} | ||
if (to > 0) to++; | ||
|
||
gui_entry_erase(entry, entry->pos-to, TRUE); | ||
} | ||
|
||
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) | ||
|
@@ -650,7 +671,7 @@ void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) | |
|
||
size = to-entry->pos; | ||
entry->pos = to; | ||
gui_entry_erase(entry, size, TRUE); | ||
gui_entry_erase(entry, size, CUTBUFFER_UPDATE_REPLACE); | ||
} | ||
|
||
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ifndef __GUI_ENTRY_H | ||
#define __GUI_ENTRY_H | ||
|
||
#define CUTBUFFER_PREPEND 42 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this line is redundant now |
||
|
||
typedef struct { | ||
int text_len, text_alloc; /* as shorts, not chars */ | ||
unichar *text; | ||
|
@@ -20,6 +22,12 @@ typedef struct { | |
unsigned int utf8:1; | ||
} GUI_ENTRY_REC; | ||
|
||
typedef enum { | ||
CUTBUFFER_UPDATE_NOOP, | ||
CUTBUFFER_UPDATE_REPLACE, | ||
CUTBUFFER_UPDATE_PREPEND | ||
} CUTBUFFER_UPDATE_OP; | ||
|
||
extern GUI_ENTRY_REC *active_entry; | ||
|
||
GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8); | ||
|
@@ -40,10 +48,10 @@ void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str); | |
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr); | ||
|
||
char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry); | ||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer); | ||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer); | ||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer); | ||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer); | ||
void gui_entry_erase_cell(GUI_ENTRY_REC *entry); | ||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space); | ||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op); | ||
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space); | ||
|
||
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry); | ||
|
@@ -60,4 +68,5 @@ void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space); | |
|
||
void gui_entry_redraw(GUI_ENTRY_REC *entry); | ||
|
||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation got really weird in this line.