1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 21:23:01 +01:00

couple fixes

This commit is contained in:
Jfreegman 2013-12-14 15:38:21 -05:00
parent c371c37bce
commit 14c9599a30
5 changed files with 32 additions and 43 deletions

View File

@ -373,19 +373,15 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
}
else if (key == KEY_UP) { /* fetches previous item in history */
if (ctx->hst_pos >= 0) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_UP);
mv_curs_end(self->window, ctx->len, y2, x2);
}
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_UP);
mv_curs_end(self->window, ctx->len, y2, x2);
}
else if (key == KEY_DOWN) { /* fetches next item in history */
if (ctx->hst_pos < ctx->hst_tot) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_DWN);
mv_curs_end(self->window, ctx->len, y2, x2);
}
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_DWN);
mv_curs_end(self->window, ctx->len, y2, x2);
}
else if (key == '\t') { /* TAB key: command */

View File

@ -301,7 +301,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
if (key == 0x107 || key == 0x8 || key == 0x7f) { /* BACKSPACE key: Remove character behind pos */
if (ctx->pos > 0) {
cur_len = wcwidth(ctx->line[ctx->pos - 1]);
cur_len = MAX(1, wcwidth(ctx->line[ctx->pos - 1]));
del_char_buf_bck(ctx->line, &ctx->pos, &ctx->len);
if (x == 0)
@ -367,19 +367,15 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
}
else if (key == KEY_UP) { /* fetches previous item in history */
if (ctx->hst_pos >= 0) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_UP);
mv_curs_end(self->window, ctx->len, y2, x2);
}
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_UP);
mv_curs_end(self->window, ctx->len, y2, x2);
}
else if (key == KEY_DOWN) { /* fetches next item in history */
if (ctx->hst_pos < ctx->hst_tot) {
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_DWN);
mv_curs_end(self->window, ctx->len, y2, x2);
}
fetch_hist_item(ctx->line, &ctx->pos, &ctx->len, ctx->ln_history, ctx->hst_tot,
&ctx->hst_pos, LN_HIST_MV_DWN);
mv_curs_end(self->window, ctx->len, y2, x2);
}
else if (key == '\t') { /* TAB key: completes peer name */

View File

@ -166,35 +166,31 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
}
else if (key == KEY_UP) { /* fetches previous item in history */
if (prt->hst_pos >= 0) {
wmove(self->window, prt->orig_y, X_OFST);
fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
&prt->hst_pos, LN_HIST_MV_UP);
wmove(self->window, prt->orig_y, X_OFST);
fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
&prt->hst_pos, LN_HIST_MV_UP);
/* adjust line y origin appropriately when window scrolls down */
if (prt->at_bottom && prt->len >= x2 - X_OFST) {
int px2 = prt->len >= x2 ? x2 : x2 - X_OFST;
int p_ofst = px2 != x2 ? 0 : X_OFST;
/* adjust line y origin appropriately when window scrolls down */
if (prt->at_bottom && prt->len >= x2 - X_OFST) {
int px2 = prt->len >= x2 ? x2 : x2 - X_OFST;
int p_ofst = px2 != x2 ? 0 : X_OFST;
if (px2 <= 0)
return;
if (px2 <= 0)
return;
int k = prt->orig_y + ((prt->len + p_ofst) / px2);
int k = prt->orig_y + ((prt->len + p_ofst) / px2);
if (k >= y2) {
wprintw(self->window, "\n");
--prt->orig_y;
}
if (k >= y2) {
wprintw(self->window, "\n");
--prt->orig_y;
}
}
}
else if (key == KEY_DOWN) { /* fetches next item in history */
if (prt->hst_pos < prt->hst_tot) {
wmove(self->window, prt->orig_y, X_OFST);
fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
&prt->hst_pos, LN_HIST_MV_DWN);
}
wmove(self->window, prt->orig_y, X_OFST);
fetch_hist_item(prt->line, &prt->pos, &prt->len, prt->ln_history, prt->hst_tot,
&prt->hst_pos, LN_HIST_MV_DWN);
}
else if (key == '\t') { /* TAB key: completes command */

View File

@ -130,7 +130,8 @@ void fetch_hist_item(wchar_t *buf, size_t *pos, size_t *len, wchar_t (*hst)[MAX_
beep();
}
} else {
if (++(*hst_pos) == hst_tot) {
if (++(*hst_pos) > hst_tot) {
--(*hst_pos);
discard_buf(buf, pos, len);
return;
}

View File

@ -22,7 +22,7 @@
#define MAX_STR_SIZE 256
#define MAX_CMDNAME_SIZE 64
#define KEY_SIZE_BYTES 32
#define TOXIC_MAX_NAME_LENGTH 32 /* Must be < TOX_MAX_NAME_LENGTH */
#define TOXIC_MAX_NAME_LENGTH 32 /* Must be <= TOX_MAX_NAME_LENGTH */
#define N_DEFAULT_WINS 2 /* number of permanent default windows */
#define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */
#define CHATBOX_HEIGHT 4