Implement M-u, M-l, M-c from Readline
This commit is contained in:
parent
d8e0d1b2fe
commit
b6dd940720
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* line-editor.c: a line editor component for the TUI part of liberty
|
||||
*
|
||||
* Copyright (c) 2017 - 2018, Přemysl Eric Janouch <p@janouch.name>
|
||||
* Copyright (c) 2017 - 2022, Přemysl Eric Janouch <p@janouch.name>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted.
|
||||
|
@ -48,6 +48,10 @@ enum line_editor_action
|
|||
LINE_EDITOR_HOME, ///< Go to start of line
|
||||
LINE_EDITOR_END, ///< Go to end of line
|
||||
|
||||
LINE_EDITOR_UPCASE_WORD, ///< Convert word to uppercase
|
||||
LINE_EDITOR_DOWNCASE_WORD, ///< Convert word to lowercase
|
||||
LINE_EDITOR_CAPITALIZE_WORD, ///< Capitalize word
|
||||
|
||||
LINE_EDITOR_B_DELETE, ///< Delete last character
|
||||
LINE_EDITOR_F_DELETE, ///< Delete next character
|
||||
LINE_EDITOR_B_KILL_WORD, ///< Delete last word
|
||||
|
@ -197,6 +201,41 @@ line_editor_action (struct line_editor *self, enum line_editor_action action)
|
|||
self->point = self->len;
|
||||
return true;
|
||||
|
||||
case LINE_EDITOR_UPCASE_WORD:
|
||||
{
|
||||
int i = self->point;
|
||||
for (; i < (int) self->len && self->line[i] == ' '; i++);
|
||||
for (; i < (int) self->len && self->line[i] != ' '; i++)
|
||||
self->line[i] = uc_toupper (self->line[i]);
|
||||
self->point = i;
|
||||
line_editor_changed (self);
|
||||
return true;
|
||||
}
|
||||
case LINE_EDITOR_DOWNCASE_WORD:
|
||||
{
|
||||
int i = self->point;
|
||||
for (; i < (int) self->len && self->line[i] == ' '; i++);
|
||||
for (; i < (int) self->len && self->line[i] != ' '; i++)
|
||||
self->line[i] = uc_tolower (self->line[i]);
|
||||
self->point = i;
|
||||
line_editor_changed (self);
|
||||
return true;
|
||||
}
|
||||
case LINE_EDITOR_CAPITALIZE_WORD:
|
||||
{
|
||||
int i = self->point;
|
||||
ucs4_t (*converter) (ucs4_t) = uc_totitle;
|
||||
for (; i < (int) self->len && self->line[i] == ' '; i++);
|
||||
for (; i < (int) self->len && self->line[i] != ' '; i++)
|
||||
{
|
||||
self->line[i] = converter (self->line[i]);
|
||||
converter = uc_tolower;
|
||||
}
|
||||
self->point = i;
|
||||
line_editor_changed (self);
|
||||
return true;
|
||||
}
|
||||
|
||||
case LINE_EDITOR_B_DELETE:
|
||||
{
|
||||
if (self->point < 1)
|
||||
|
|
|
@ -65,6 +65,10 @@ EDITOR_F_WORD, Go forward a word
|
|||
EDITOR_HOME, Go to start of line
|
||||
EDITOR_END, Go to end of line
|
||||
|
||||
EDITOR_UPCASE_WORD, Convert word to uppercase
|
||||
EDITOR_DOWNCASE_WORD, Convert word to lowercase
|
||||
EDITOR_CAPITALIZE_WORD, Capitalize word
|
||||
|
||||
EDITOR_B_DELETE, Delete last character
|
||||
EDITOR_F_DELETE, Delete next character
|
||||
EDITOR_B_KILL_WORD, Delete last word
|
||||
|
|
11
nncmpp.c
11
nncmpp.c
|
@ -2774,6 +2774,13 @@ app_editor_process_action (enum action action)
|
|||
case ACTION_EDITOR_END:
|
||||
return line_editor_action (&g.editor, LINE_EDITOR_END);
|
||||
|
||||
case ACTION_EDITOR_UPCASE_WORD:
|
||||
return line_editor_action (&g.editor, LINE_EDITOR_UPCASE_WORD);
|
||||
case ACTION_EDITOR_DOWNCASE_WORD:
|
||||
return line_editor_action (&g.editor, LINE_EDITOR_DOWNCASE_WORD);
|
||||
case ACTION_EDITOR_CAPITALIZE_WORD:
|
||||
return line_editor_action (&g.editor, LINE_EDITOR_CAPITALIZE_WORD);
|
||||
|
||||
case ACTION_EDITOR_B_DELETE:
|
||||
return line_editor_action (&g.editor, LINE_EDITOR_B_DELETE);
|
||||
case ACTION_EDITOR_F_DELETE:
|
||||
|
@ -3020,6 +3027,10 @@ g_editor_defaults[] =
|
|||
{ "C-a", ACTION_EDITOR_HOME },
|
||||
{ "C-e", ACTION_EDITOR_END },
|
||||
|
||||
{ "M-u", ACTION_EDITOR_UPCASE_WORD },
|
||||
{ "M-l", ACTION_EDITOR_DOWNCASE_WORD },
|
||||
{ "M-c", ACTION_EDITOR_CAPITALIZE_WORD },
|
||||
|
||||
{ "C-h", ACTION_EDITOR_B_DELETE },
|
||||
{ "DEL", ACTION_EDITOR_B_DELETE },
|
||||
{ "Backspace", ACTION_EDITOR_B_DELETE },
|
||||
|
|
Loading…
Reference in New Issue