Fix MOVE flag handling and remove key code (not actually needed).

This commit is contained in:
nicm
2026-06-23 21:00:20 +00:00
parent 0c5e6770df
commit 89027bd22c
7 changed files with 53 additions and 49 deletions

View File

@@ -35,7 +35,7 @@ static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
struct cmdq_item *);
static int cmd_command_prompt_callback(struct client *, void *,
const char *, key_code, int);
const char *, int);
static void cmd_command_prompt_free(void *);
const struct cmd_entry cmd_command_prompt_entry = {
@@ -178,7 +178,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
static int
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
__unused key_code key, int flags)
int flags)
{
struct cmd_command_prompt_cdata *cdata = data;
char *error;

View File

@@ -34,7 +34,7 @@ static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
struct cmdq_item *);
static int cmd_confirm_before_callback(struct client *, void *,
const char *, key_code, int);
const char *, int);
static void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = {
@@ -120,7 +120,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
static int
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
__unused key_code key, __unused int flags)
__unused int flags)
{
struct cmd_confirm_before_data *cdata = data;
struct cmdq_item *item = cdata->item, *new_item;

View File

@@ -1068,7 +1068,7 @@ mode_tree_search_set(struct mode_tree_data *mtd)
static int
mode_tree_search_callback(__unused struct client *c, void *data, const char *s,
__unused key_code key, __unused int flags)
__unused int flags)
{
struct mode_tree_data *mtd = data;
@@ -1095,7 +1095,7 @@ mode_tree_search_free(void *data)
static int
mode_tree_filter_callback(__unused struct client *c, void *data, const char *s,
__unused key_code key, __unused int flags)
__unused int flags)
{
struct mode_tree_data *mtd = data;

View File

@@ -673,7 +673,7 @@ status_prompt_accept(__unused struct cmdq_item *item, void *data)
void *pd = c->prompt_data;
if (c->prompt_string != NULL) {
c->prompt_inputcb(c, pd, "y", KEYC_NONE, PROMPT_INPUT_DONE);
c->prompt_inputcb(c, pd, "y", PROMPT_INPUT_DONE);
status_prompt_clear(c);
}
return (CMD_RETURN_NORMAL);
@@ -686,7 +686,7 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs,
prompt_free_cb freecb, void *data, int flags, enum prompt_type prompt_type)
{
struct format_tree *ft;
char *tmp;
char *tmp, *cp;
server_client_clear_overlay(c);
@@ -735,8 +735,13 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs,
c->tty.flags |= TTY_FREEZE;
c->flags |= CLIENT_REDRAWSTATUS;
if (flags & PROMPT_INCREMENTAL)
c->prompt_inputcb(c, data, "=", KEYC_NONE, 0);
if (flags & PROMPT_INCREMENTAL) {
tmp = utf8_tocstr(c->prompt_buffer);
xasprintf(&cp, "=%s", tmp);
c->prompt_inputcb(c, c->prompt_data, cp, 0);
free(cp);
free(tmp);
}
if ((flags & PROMPT_SINGLE) && (flags & PROMPT_ACCEPT))
cmdq_append(c, cmdq_get_callback(status_prompt_accept, c));
@@ -1425,10 +1430,25 @@ status_prompt_backward_word(struct client *c, const char *separators)
c->prompt_index = idx;
}
/* Should this key exit incremental prompt? */
static int
status_prompt_incremental_exit_key(key_code key)
/* Fire input callback when done. */
static void
status_prompt_done(struct client *c, const char *s)
{
struct prompt_data *pd = c->prompt_data;
if (c->prompt_inputcb(c, pd, s, PROMPT_INPUT_DONE) == 0)
status_prompt_clear(c);
}
/* Check for a movement key. */
static int
status_prompt_check_move(struct client *c, key_code key)
{
struct prompt_data *pd = c->prompt_data;
char *s;
if (~c->prompt_flags & PROMPT_INCREMENTAL)
return (0);
switch (key) {
case KEYC_UP:
case KEYC_DOWN:
@@ -1436,21 +1456,14 @@ status_prompt_incremental_exit_key(key_code key)
case KEYC_RIGHT:
case KEYC_PPAGE:
case KEYC_NPAGE:
return (1);
}
return (0);
}
/* Fire input callback when done. */
static int
status_prompt_done(struct client *c, const char *s)
{
struct prompt_data *pd = c->prompt_data;
if (c->prompt_inputcb(c, pd, s, KEYC_NONE, PROMPT_INPUT_DONE) == 0) {
status_prompt_clear(c);
break;
default:
return (0);
}
s = utf8_tocstr(c->prompt_buffer);
if (c->prompt_inputcb(c, pd, s, PROMPT_INPUT_MOVE) == 0)
status_prompt_clear(c);
free(s);
return (1);
}
@@ -1468,7 +1481,7 @@ status_prompt_key(struct client *c, key_code key)
if (c->prompt_flags & PROMPT_KEY) {
ks = key_string_lookup_key(key, 0);
c->prompt_inputcb(c, pd, ks, KEYC_NONE, PROMPT_INPUT_DONE);
c->prompt_inputcb(c, pd, ks, PROMPT_INPUT_DONE);
status_prompt_clear(c);
return (0);
}
@@ -1481,7 +1494,7 @@ status_prompt_key(struct client *c, key_code key)
if (key >= '0' && key <= '9')
goto append_key;
s = utf8_tocstr(c->prompt_buffer);
c->prompt_inputcb(c, pd, s, KEYC_NONE, PROMPT_INPUT_DONE);
c->prompt_inputcb(c, pd, s, PROMPT_INPUT_DONE);
status_prompt_clear(c);
free(s);
return (1);
@@ -1513,16 +1526,8 @@ status_prompt_key(struct client *c, key_code key)
}
process_key:
if ((c->prompt_flags & PROMPT_INCREMENTAL) &&
status_prompt_incremental_exit_key(key)) {
s = utf8_tocstr(c->prompt_buffer);
if (status_prompt_done(c, s) == 0) {
free(s);
return (1);
}
return (0);
}
if (status_prompt_check_move(c, key))
return (1);
switch (key) {
case KEYC_LEFT:
case 'b'|KEYC_CTRL:
@@ -1786,7 +1791,7 @@ changed:
if (c->prompt_flags & PROMPT_INCREMENTAL) {
s = utf8_tocstr(c->prompt_buffer);
xasprintf(&cp, "%c%s", prefix, s);
c->prompt_inputcb(c, pd, cp, KEYC_NONE, 0);
c->prompt_inputcb(c, pd, cp, 0);
free(cp);
free(s);
}

3
tmux.h
View File

@@ -1993,8 +1993,7 @@ RB_HEAD(client_windows, client_window);
/* Client connection. */
#define PROMPT_INPUT_DONE 0x1
#define PROMPT_INPUT_MOVE 0x2
typedef int (*prompt_input_cb)(struct client *, void *, const char *, key_code,
int);
typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
typedef void (*prompt_free_cb)(void *);
typedef struct visible_ranges *(*overlay_check_cb)(struct client *, void *,
u_int, u_int, u_int);

View File

@@ -981,7 +981,7 @@ window_customize_free_item_callback(void *itemdata)
static int
window_customize_set_option_callback(struct client *c, void *itemdata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_customize_itemdata *item = itemdata;
struct window_customize_modedata *data = item->data;
@@ -1195,7 +1195,7 @@ window_customize_reset_option(struct window_customize_modedata *data,
static int
window_customize_set_command_callback(struct client *c, void *itemdata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_customize_itemdata *item = itemdata;
struct window_customize_modedata *data = item->data;
@@ -1234,7 +1234,7 @@ fail:
static int
window_customize_set_note_callback(__unused struct client *c, void *itemdata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_customize_itemdata *item = itemdata;
struct window_customize_modedata *data = item->data;
@@ -1372,7 +1372,7 @@ window_customize_change_each(void *modedata, void *itemdata,
static int
window_customize_change_current_callback(__unused struct client *c,
void *modedata, const char *s, __unused key_code key, __unused int flags)
void *modedata, const char *s, __unused int flags)
{
struct window_customize_modedata *data = modedata;
struct window_customize_itemdata *item;
@@ -1408,7 +1408,7 @@ window_customize_change_current_callback(__unused struct client *c,
static int
window_customize_change_tagged_callback(struct client *c, void *modedata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_customize_modedata *data = modedata;

View File

@@ -1082,7 +1082,7 @@ window_tree_command_done(__unused struct cmdq_item *item, void *modedata)
static int
window_tree_command_callback(struct client *c, void *modedata, const char *s,
__unused key_code key, __unused int flags)
__unused int flags)
{
struct window_tree_modedata *data = modedata;
@@ -1141,7 +1141,7 @@ window_tree_kill_each(__unused void *modedata, void *itemdata,
static int
window_tree_kill_current_callback(struct client *c, void *modedata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_tree_modedata *data = modedata;
struct mode_tree_data *mtd = data->data;
@@ -1162,7 +1162,7 @@ window_tree_kill_current_callback(struct client *c, void *modedata,
static int
window_tree_kill_tagged_callback(struct client *c, void *modedata,
const char *s, __unused key_code key, __unused int flags)
const char *s, __unused int flags)
{
struct window_tree_modedata *data = modedata;
struct mode_tree_data *mtd = data->data;