mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: Simplify UI API on mode change
Currently, there are two functions in the UI API that are called when the mode changes: insert_mode() and normal_mode(). These can be folded into a single mode_change() entrypoint which can do whatever it wants based on the mode it is passed, limited to INSERT and NORMAL for now.
This commit is contained in:
parent
61e4a32065
commit
fa48fc667a
@ -86,8 +86,7 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
|
|||||||
ui->busy_stop = remote_ui_busy_stop;
|
ui->busy_stop = remote_ui_busy_stop;
|
||||||
ui->mouse_on = remote_ui_mouse_on;
|
ui->mouse_on = remote_ui_mouse_on;
|
||||||
ui->mouse_off = remote_ui_mouse_off;
|
ui->mouse_off = remote_ui_mouse_off;
|
||||||
ui->insert_mode = remote_ui_insert_mode;
|
ui->mode_change = remote_ui_mode_change;
|
||||||
ui->normal_mode = remote_ui_normal_mode;
|
|
||||||
ui->set_scroll_region = remote_ui_set_scroll_region;
|
ui->set_scroll_region = remote_ui_set_scroll_region;
|
||||||
ui->scroll = remote_ui_scroll;
|
ui->scroll = remote_ui_scroll;
|
||||||
ui->highlight_set = remote_ui_highlight_set;
|
ui->highlight_set = remote_ui_highlight_set;
|
||||||
@ -214,16 +213,16 @@ static void remote_ui_mouse_off(UI *ui)
|
|||||||
push_call(ui, "mouse_off", args);
|
push_call(ui, "mouse_off", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remote_ui_insert_mode(UI *ui)
|
static void remote_ui_mode_change(UI *ui, int mode)
|
||||||
{
|
{
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
push_call(ui, "insert_mode", args);
|
if (mode == INSERT) {
|
||||||
}
|
ADD(args, STRING_OBJ(cstr_to_string("insert")));
|
||||||
|
} else {
|
||||||
static void remote_ui_normal_mode(UI *ui)
|
assert(mode == NORMAL);
|
||||||
{
|
ADD(args, STRING_OBJ(cstr_to_string("normal")));
|
||||||
Array args = ARRAY_DICT_INIT;
|
}
|
||||||
push_call(ui, "normal_mode", args);
|
push_call(ui, "mode_change", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remote_ui_set_scroll_region(UI *ui, int top, int bot, int left,
|
static void remote_ui_set_scroll_region(UI *ui, int top, int bot, int left,
|
||||||
|
@ -57,6 +57,7 @@ typedef struct {
|
|||||||
bool busy;
|
bool busy;
|
||||||
HlAttrs attrs, print_attrs;
|
HlAttrs attrs, print_attrs;
|
||||||
Cell **screen;
|
Cell **screen;
|
||||||
|
int showing_mode;
|
||||||
struct {
|
struct {
|
||||||
int enable_mouse, disable_mouse;
|
int enable_mouse, disable_mouse;
|
||||||
int enable_bracketed_paste, disable_bracketed_paste;
|
int enable_bracketed_paste, disable_bracketed_paste;
|
||||||
@ -98,6 +99,7 @@ UI *tui_start(void)
|
|||||||
data->can_use_terminal_scroll = true;
|
data->can_use_terminal_scroll = true;
|
||||||
data->bufpos = 0;
|
data->bufpos = 0;
|
||||||
data->bufsize = sizeof(data->buf) - CNORM_COMMAND_MAX_SIZE;
|
data->bufsize = sizeof(data->buf) - CNORM_COMMAND_MAX_SIZE;
|
||||||
|
data->showing_mode = 0;
|
||||||
data->unibi_ext.enable_mouse = -1;
|
data->unibi_ext.enable_mouse = -1;
|
||||||
data->unibi_ext.disable_mouse = -1;
|
data->unibi_ext.disable_mouse = -1;
|
||||||
data->unibi_ext.enable_bracketed_paste = -1;
|
data->unibi_ext.enable_bracketed_paste = -1;
|
||||||
@ -148,8 +150,7 @@ UI *tui_start(void)
|
|||||||
ui->busy_stop = tui_busy_stop;
|
ui->busy_stop = tui_busy_stop;
|
||||||
ui->mouse_on = tui_mouse_on;
|
ui->mouse_on = tui_mouse_on;
|
||||||
ui->mouse_off = tui_mouse_off;
|
ui->mouse_off = tui_mouse_off;
|
||||||
ui->insert_mode = tui_insert_mode;
|
ui->mode_change = tui_mode_change;
|
||||||
ui->normal_mode = tui_normal_mode;
|
|
||||||
ui->set_scroll_region = tui_set_scroll_region;
|
ui->set_scroll_region = tui_set_scroll_region;
|
||||||
ui->scroll = tui_scroll;
|
ui->scroll = tui_scroll;
|
||||||
ui->highlight_set = tui_highlight_set;
|
ui->highlight_set = tui_highlight_set;
|
||||||
@ -178,7 +179,7 @@ static void tui_stop(UI *ui)
|
|||||||
// Destroy input stuff
|
// Destroy input stuff
|
||||||
term_input_destroy(data->input);
|
term_input_destroy(data->input);
|
||||||
// Destroy output stuff
|
// Destroy output stuff
|
||||||
tui_normal_mode(ui);
|
tui_mode_change(ui, NORMAL);
|
||||||
tui_mouse_off(ui);
|
tui_mouse_off(ui);
|
||||||
unibi_out(ui, unibi_exit_attribute_mode);
|
unibi_out(ui, unibi_exit_attribute_mode);
|
||||||
// cursor should be set to normal before exiting alternate screen
|
// cursor should be set to normal before exiting alternate screen
|
||||||
@ -404,16 +405,21 @@ static void tui_mouse_off(UI *ui)
|
|||||||
data->mouse_enabled = false;
|
data->mouse_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tui_insert_mode(UI *ui)
|
static void tui_mode_change(UI *ui, int mode)
|
||||||
{
|
{
|
||||||
TUIData *data = ui->data;
|
TUIData *data = ui->data;
|
||||||
unibi_out(ui, data->unibi_ext.enter_insert_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tui_normal_mode(UI *ui)
|
if (mode == INSERT) {
|
||||||
{
|
if (data->showing_mode != INSERT) {
|
||||||
TUIData *data = ui->data;
|
unibi_out(ui, data->unibi_ext.enter_insert_mode);
|
||||||
unibi_out(ui, data->unibi_ext.exit_insert_mode);
|
}
|
||||||
|
} else {
|
||||||
|
assert(mode == NORMAL);
|
||||||
|
if (data->showing_mode != NORMAL) {
|
||||||
|
unibi_out(ui, data->unibi_ext.exit_insert_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data->showing_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tui_set_scroll_region(UI *ui, int top, int bot, int left,
|
static void tui_set_scroll_region(UI *ui, int top, int bot, int left,
|
||||||
|
@ -121,7 +121,7 @@ void ui_update_encoding(void)
|
|||||||
// May update the shape of the cursor.
|
// May update the shape of the cursor.
|
||||||
void ui_cursor_shape(void)
|
void ui_cursor_shape(void)
|
||||||
{
|
{
|
||||||
ui_change_mode();
|
ui_mode_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_refresh(void)
|
void ui_refresh(void)
|
||||||
@ -469,25 +469,18 @@ static void flush_cursor_update(void)
|
|||||||
|
|
||||||
// Notify that the current mode has changed. Can be used to change cursor
|
// Notify that the current mode has changed. Can be used to change cursor
|
||||||
// shape, for example.
|
// shape, for example.
|
||||||
static void ui_change_mode(void)
|
static void ui_mode_change(void)
|
||||||
{
|
{
|
||||||
static int showing_insert_mode = MAYBE;
|
int mode;
|
||||||
|
|
||||||
if (!full_screen) {
|
if (!full_screen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
/* Get a simple UI mode out of State. */
|
||||||
if (State & INSERT) {
|
if (State & INSERT)
|
||||||
if (showing_insert_mode != TRUE) {
|
mode = INSERT;
|
||||||
UI_CALL(insert_mode);
|
else
|
||||||
}
|
mode = NORMAL;
|
||||||
showing_insert_mode = TRUE;
|
UI_CALL(mode_change, mode);
|
||||||
} else {
|
|
||||||
if (showing_insert_mode != FALSE) {
|
|
||||||
UI_CALL(normal_mode);
|
|
||||||
}
|
|
||||||
showing_insert_mode = FALSE;
|
|
||||||
}
|
|
||||||
conceal_check_cursur_line();
|
conceal_check_cursur_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ struct ui_t {
|
|||||||
void (*busy_stop)(UI *ui);
|
void (*busy_stop)(UI *ui);
|
||||||
void (*mouse_on)(UI *ui);
|
void (*mouse_on)(UI *ui);
|
||||||
void (*mouse_off)(UI *ui);
|
void (*mouse_off)(UI *ui);
|
||||||
void (*insert_mode)(UI *ui);
|
void (*mode_change)(UI *ui, int mode);
|
||||||
void (*normal_mode)(UI *ui);
|
|
||||||
void (*set_scroll_region)(UI *ui, int top, int bot, int left, int right);
|
void (*set_scroll_region)(UI *ui, int top, int bot, int left, int right);
|
||||||
void (*scroll)(UI *ui, int count);
|
void (*scroll)(UI *ui, int count);
|
||||||
void (*highlight_set)(UI *ui, HlAttrs attrs);
|
void (*highlight_set)(UI *ui, HlAttrs attrs);
|
||||||
|
@ -340,12 +340,9 @@ function Screen:_handle_mouse_off()
|
|||||||
self._mouse_enabled = false
|
self._mouse_enabled = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:_handle_insert_mode()
|
function Screen:_handle_mode_change(mode)
|
||||||
self._mode = 'insert'
|
assert(mode == 'insert' or mode == 'normal')
|
||||||
end
|
self._mode = mode
|
||||||
|
|
||||||
function Screen:_handle_normal_mode()
|
|
||||||
self._mode = 'normal'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:_handle_set_scroll_region(top, bot, left, right)
|
function Screen:_handle_set_scroll_region(top, bot, left, right)
|
||||||
|
Loading…
Reference in New Issue
Block a user