📄 mouse.c
字号:
if (goal_col < 0) goal_col = 0; /* window has a status line? */ if (((TW *)bw->object)->staon) /* clicked on it? */ if (y == w->y) { if (y != maint->wind) drag_size = y; return -1; } else goal_line = y - w->y + bw->top->line - 1; else goal_line = y - w->y + bw->top->line; pline(bw->cursor, goal_line); pcol(bw->cursor, goal_col); if (floatmouse) bw->cursor->xcol = goal_col; else bw->cursor->xcol = piscol(bw->cursor); return 0; } } else if (w->watom->what == TYPEPW) { PW *pw = (PW *)bw->object; /* only one line in prompt windows */ pcol(bw->cursor,x - w->x + bw->offset - pw->promptlen + pw->promptofst); bw->cursor->xcol = piscol(bw->cursor); return 0; } else if (w->watom->what == TYPEMENU) { menujump((MENU *)w->object, x - w->x, y - w->y); return 0; } else return -1;}/* same as utomouse but won't change windows, and always floats. puts the * position that utomouse would use into tmspos. */static int tmspos;static int tomousestay(){ BW *bw; int x = Cx - 1,y = Cy - 1; W *w; /* w = watpos(maint,x,y); if(!w || w != maint->curwin) return -1; */ w = maint->curwin; bw = w->object; if (w->watom->what == TYPETW) { if (bw->o.hex) { int goal_col = x - w->x + bw->offset - 60; int goal_line; long goal_byte; if (goal_col < 0) goal_col = 0; if (goal_col > 15) goal_col = 15; /* window has a status line? */ if (((TW *)bw->object)->staon) if (y <= w->y) { goal_col = 0; goal_line = bw->top->byte/16; } else if (y >= w->y + w->h) { goal_line = bw->top->byte/16 + w->h - 2; goal_col = 15; } else goal_line = y - w->y + bw->top->byte/16 - 1; else if (y < w->y) { goal_col = 0; goal_line = bw->top->byte/16; } else if (y >= w->y + w->h) { goal_line = bw->top->byte/16 + w->h - 1; goal_col = 15; } else goal_line = y - w->y + bw->top->byte/16; goal_byte = goal_line*16L + goal_col; if (goal_byte > bw->b->eof->byte) goal_byte = bw->b->eof->byte; pgoto(bw->cursor, goal_byte); /* This is not right... */ tmspos = bw->cursor->xcol = piscol(bw->cursor); return 0; } else { int goal_col = x - w->x + bw->offset - (bw->o.linums ? LINCOLS : 0); int goal_line; if (goal_col < 0) goal_col = 0; /* window has a status line? */ if (((TW *)bw->object)->staon) if (y <= w->y) { goal_col = 0; goal_line = bw->top->line; } else if (y >= w->y + w->h) { goal_col = 1000; goal_line = w->h + bw->top->line - 2; } else goal_line = y - w->y + bw->top->line - 1; else if (y < w->y) { goal_col = 0; goal_line = bw->top->line; } else if (y >= w->y + w->h) { goal_col = 1000; goal_line = w->h + bw->top->line - 1; } else goal_line = y - w->y + bw->top->line; pline(bw->cursor, goal_line); pcol(bw->cursor, goal_col); tmspos = bw->cursor->xcol = goal_col; if (!floatmouse) tmspos = piscol(bw->cursor); return 0; } } else if (w->watom->what == TYPEPW) { PW *pw = (PW *)bw->object; /* only one line in prompt windows */ pcol(bw->cursor,x - w->x + bw->offset - pw->promptlen + pw->promptofst); tmspos = bw->cursor->xcol = piscol(bw->cursor); return 0; } else return -1;}static long anchor; /* byte where mouse was originally pressed */static long anchorn; /* near side of the anchored word */static int marked; /* mark was set by defmdrag? */static int reversed; /* mouse was dragged above the anchor? */int udefmdown(BW *xx){ BW *bw; if (utomouse(xx)) return -1; if ((maint->curwin->watom->what & (TYPEPW | TYPETW)) == 0) return 0; bw = (BW *)maint->curwin->object; anchor = bw->cursor->byte; marked = reversed = 0; return 0;}void reset_trig_time(){ if (!auto_rate) auto_rate = 1; auto_trig_time = mnow() + 300 / (1 + auto_rate);}int udefmdrag(BW *xx){ BW *bw = (BW *)maint->curwin->object; int ay = Cy - 1; int new_scroll; int new_rate; if (drag_size) { while (ay > bw->parent->y) { int y = bw->parent->y; wgrowdown(bw->parent); if (y == bw->parent->y) return -1; } while (ay < bw->parent->y) { int y = bw->parent->y; wgrowup(bw->parent); if (y == bw->parent->y) return -1; } return 0; } if (ay < bw->y) { new_scroll = -1; new_rate = bw->y - ay; } else if (ay >= bw->y + bw->h) { new_scroll = 1; new_rate = ay - (bw->y + bw->h) + 1; } else { new_scroll = 0; new_rate = 1; } if (new_rate > 10) new_rate = 10; if (!new_scroll) auto_scroll = 0; else if (new_scroll != auto_scroll) { auto_scroll = new_scroll; auto_rate = new_rate; reset_trig_time(); } else if (new_rate != auto_rate) {/* int left = auto_trig_time - mnow(); if (left > 0) { left = left * auto_rate / new_rate; }*/ auto_rate = new_rate; } if (!marked) marked++, umarkb(bw); if (tomousestay()) return -1; selecting = 1; if (reversed) umarkb(bw); else umarkk(bw); if ((!reversed && bw->cursor->byte < anchor) || (reversed && bw->cursor->byte > anchor)) { P *q = pdup(markb, USTR "udefmdrag"); int tmp = markb->xcol; pset(markb,markk); pset(markk,q); markb->xcol = markk->xcol; markk->xcol = tmp; prm(q); reversed = !reversed; } bw->cursor->xcol = tmspos; return 0;}int udefmup(BW *bw){ return 0;}int udefm2down(BW *xx){ BW *bw; if (utomouse(xx)) return -1; if (maint->curwin->watom->what & TYPEMENU) { return maint->curwin->watom->rtn((MENU *)maint->curwin->object); } if ((maint->curwin->watom->what & (TYPEPW | TYPETW)) == 0) return 0; bw = (BW *)maint->curwin->object; /* set anchor to left side, anchorn to right side */ u_goto_prev(bw); anchor = bw->cursor->byte; umarkb(bw); markb->xcol = piscol(markb); u_goto_next(bw); anchorn = bw->cursor->byte; umarkk(bw); markk->xcol = piscol(markk); reversed = 0; bw->cursor->xcol = piscol(bw->cursor); selecting = 1; return 0;}int udefm2drag(BW *xx){ BW *bw=(BW *)maint->curwin->object; if (tomousestay()) return -1; if (!reversed && bw->cursor->byte < anchor) { pgoto(markk,anchorn); markk->xcol = piscol(markk); reversed = 1; } else if(reversed && bw->cursor->byte > anchorn) { pgoto(markb,anchor); markb->xcol = piscol(markb); reversed = 0; } bw->cursor->xcol = piscol(bw->cursor); if(reversed) { if (!pisbol(bw->cursor)) u_goto_prev(bw), bw->cursor->xcol = piscol(bw->cursor); umarkb(bw); } else { if (!piseol(bw->cursor)) u_goto_next(bw), bw->cursor->xcol = piscol(bw->cursor); umarkk(bw); } return 0;}int udefm2up(BW *bw){ return 0;}int udefm3down(BW *xx){ BW *bw; if (utomouse(xx)) return -1; if ((maint->curwin->watom->what & (TYPEPW | TYPETW)) == 0) return 0; bw = (BW *)maint->curwin->object; /* set anchor to beginning of line, anchorn to beginning of next line */ p_goto_bol(bw->cursor); bw->cursor->xcol = piscol(bw->cursor); anchor = bw->cursor->byte; umarkb(bw); umarkk(bw); pnextl(markk); anchorn = markk->byte; reversed = 0; bw->cursor->xcol = piscol(bw->cursor); selecting = 1; return 0;}int udefm3drag(BW *xx){ BW *bw = (BW *)maint->curwin->object; if (tomousestay()) return -1; if (!reversed && bw->cursor->byte < anchor) { pgoto(markk,anchorn); markk->xcol = piscol(markk); reversed = 1; } else if (reversed && bw->cursor->byte > anchorn) { pgoto(markb,anchor); markb->xcol = piscol(markb); reversed = 0; } p_goto_bol(bw->cursor); bw->cursor->xcol = piscol(bw->cursor); if(reversed) umarkb(bw), markb->xcol = piscol(markb); else umarkk(bw), pnextl(markk), markk->xcol = markk->xcol = piscol(markk); return 0;}int udefm3up(BW *bw){ return 0;}void mouseopen(){#ifdef MOUSE_XTERM if (usexmouse) { ttputs(USTR "\33[?1002h"); if (joexterm) ttputs(USTR "\33[?2007h"); ttflsh(); }#endif}void mouseclose(){#ifdef MOUSE_XTERM if (usexmouse) { if (joexterm) ttputs(USTR "\33[?2007l"); ttputs(USTR "\33[?1002l"); ttflsh(); }#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -