/* * LookUpCharToken - look up to token for a specified character */ char *LookUpCharToken( vi_key key, bool want_single ) { int i; static int num = 0; if( num == 0 ) { if( readKeyData() != ERR_NO_ERR ) { return( NULL ); } num = GetNumberOfTokens( charTokens ); } if( want_single ) { switch( key ) { case VI_KEY( ESC ): return( "e" ); case VI_KEY( ENTER ): return( "n" ); case VI_KEY( TAB ): return( "t" ); case NO_ADD_TO_HISTORY_KEY: return( "h" ); case '\\': return( "\\" ); } } for( i = 0; i < num; i++ ) { if( key == keyVals[i] ) { return( GetTokenString( charTokens, i ) ); } } return( NULL ); } /* LookUpCharToken */
static change_resp ChangePrompt( void ) { #ifdef __WIN__ int i; i = MyMessageBox( Root, "Change this occurence?", "Replace Text", MB_ICONQUESTION | MB_YESNOCANCEL ); if( i == IDNO ) { return( CHANGE_NO ); } else if( i == IDCANCEL ) { return( CHANGE_CANCEL ); } else { return( CHANGE_OK ); } #else vi_key key = 0; Message1( "Change? (y)es/(n)o/(a)ll/(q)uit" ); for( ;; ) { key = GetNextEvent( false ); if( key == VI_KEY( y ) ) { return( CHANGE_OK ); } else if( key == VI_KEY( n ) ) { return( CHANGE_NO ); } else if( key == VI_KEY( a ) ) { return( CHANGE_ALL ); } else if( key == VI_KEY( q ) ) { return( CHANGE_CANCEL ); } } #endif }
/* * BIOSKeyboardHit - read the keyboard */ vi_key BIOSGetKeyboard( int *scan ) { INPUT_RECORD ir; DWORD rd, ss; WORD vk; BOOL has_alt, has_shift, has_ctrl, has_capsl; map *ev, what; vi_key key; do { ReadConsoleInput( InputHandle, &ir, 1, &rd ); } while( !eventWeWant( &ir ) ); if( ir.EventType == MOUSE_EVENT ) { return( VI_KEY( MOUSEEVENT ) ); } vk = ir.Event.KeyEvent.wVirtualKeyCode; key = (unsigned char)ir.Event.KeyEvent.uChar.AsciiChar; ss = ir.Event.KeyEvent.dwControlKeyState; has_shift = ((ss & SHIFT_PRESSED) ? TRUE : FALSE); has_ctrl = ((ss & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) ? TRUE : FALSE); has_alt = ((ss & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) ? TRUE : FALSE); has_capsl = ((ss & CAPSLOCK_ON) ? TRUE : FALSE); what.vk = vk; ev = bsearch( &what, events, sizeof( events ) / sizeof( events[0] ), sizeof( what ), CompareEvents ); if( ev != NULL ) { if( has_ctrl && has_alt ) { // it handles AltGr + key } else if( has_ctrl ) { key = ev->ctrl; } else if( has_alt ) { key = ev->alt; // Caps lock has efect to keys which generate character // don't apply to extended keys as down, up, page down, // page up, insert, end, delete, .... } else if( has_shift ^ ( key && has_capsl ) ) { if( key == 0 ) { key = ev->shift; } } else { if( key == 0 ) { key = ev->reg; } } } if( key == 0 ) { // ignore unknown keys key = VI_KEY( DUMMY ); } if( scan != NULL ) { *scan = 0; } return( key ); } /* BIOSGetKeyboard */
/* * InvokeColSelHook - invoke column hook with specified data */ vi_rc InvokeColSelHook( int sc, int ec ) { int j, i; char wordbuff[MAX_STR]; char data[MAX_STR + 32]; int lne; #ifndef __WIN__ int x1; int has_bord; #endif #ifndef __WIN__ has_bord = WindowAuxInfo( CurrentWindow, WIND_INFO_HAS_BORDER ); x1 = WindowAuxInfo( CurrentWindow, WIND_INFO_X1 ); if( LastEvent != VI_KEY( MOUSEEVENT ) ) { lne = WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 ) + CurrentPos.line - LeftTopPos.line; if( has_bord ) { ++lne; } } else { lne = MouseRow; } #else if( LastEvent != VI_KEY( FAKEMOUSE ) ) { lne = (CurrentPos.line - LeftTopPos.line) * FontHeight( WIN_FONT( &EditWindow ) ); } else { lne = MouseY; } #endif j = 0; if( ec - sc >= MAX_STR ) { ec = sc + MAX_STR - 2; } for( i = sc - 1; i <= ec - 1; i++ ) { wordbuff[j++] = CurrentLine->data[i]; } wordbuff[j] = 0; #ifndef __WIN__ sc = x1 + VirtualColumnOnCurrentLine( sc ) - LeftTopPos.column; ec = x1 + VirtualColumnOnCurrentLine( ec ) - LeftTopPos.column; if( !has_bord ) { sc--; ec--; } #else sc = MyTextExtent( CurrentWindow, WIN_STYLE( &EditWindow ), &CurrentLine->data[0], sc ); ec = MyTextExtent( CurrentWindow, WIN_STYLE( &EditWindow ), &CurrentLine->data[0], ec ); #endif MySprintf( data, "\"%s\" %d %d %d %d", wordbuff, lne, sc, ec, ec - sc + 1 ); return( SourceHookData( SRC_HOOK_MOUSE_CHARSEL, data ) ); } /* InvokeColSelHook */
/* * getOverrideKey - get next key from the override buffer */ static vi_key getOverrideKey( void ) { int c; bool mouse = FALSE; int mcnt = 0; for( ;; ) { c = overrideKeyBuff[overrideKeyPos]; if( overrideKeyPos == MAX_OVERRIDE_KEY_BUFF - 1 ) { overrideKeyPos = 0; } else { overrideKeyPos++; } if( overrideKeyPos == overrideKeyEnd ) { EditFlags.KeyOverride = FALSE; } if( c == VI_KEY( MOUSEEVENT ) && !mouse ) { mouse = TRUE; mcnt = 0; } else { if( mouse ) { switch( mcnt ) { case 0: LastMouseEvent = c; break; case 1: MouseRow = c; break; case 2: MouseCol = c; break; case 3: MouseStatus = c; mouse = FALSE; c = VI_KEY( MOUSEEVENT ); RedrawMouse( MouseRow, MouseCol ); DisplayMouse( TRUE ); break; } mcnt++; } if( !mouse ) { #ifndef __WIN__ if( c == 3 ) { // ExitWithVerify(); } #endif break; } } } return( c ); } /* getOverrideKey */
/* * getOverrideKey - get next key from the override buffer */ static vi_key getOverrideKey( void ) { vi_key key; bool mouse = false; int mcnt = 0; for( ;; ) { key = overrideKeyBuff[overrideKeyPos]; if( overrideKeyPos == MAX_OVERRIDE_KEY_BUFF - 1 ) { overrideKeyPos = 0; } else { overrideKeyPos++; } if( overrideKeyPos == overrideKeyEnd ) { EditFlags.KeyOverride = false; } if( mouse ) { if( mcnt == 3 ) { MouseStatus = key; mouse = false; key = VI_KEY( MOUSEEVENT ); RedrawMouse( MouseRow, MouseCol ); DisplayMouse( true ); break; } if( mcnt == 0 ) { LastMouseEvent = key; } else if( mcnt == 1 ) { MouseRow = key; } else if( mcnt == 2 ) { MouseCol = key; } mcnt++; } else if( key == VI_KEY( MOUSEEVENT ) ) { mouse = true; mcnt = 0; } else { #ifndef __WIN__ if( key == VI_KEY( CTRL_C ) ) { // ExitWithVerify(); } #endif break; } } return( key ); } /* getOverrideKey */
/* * handleKey - handle a lost file recover check keystroke */ static bool handleKey( vi_key key ) { if( key == VI_KEY( i ) ) { EditFlags.IgnoreLostFiles = true; } else if( key == VI_KEY( r ) ) { EditFlags.RecoverLostFiles = true; EditFlags.NoInitialFileLoad = true; } else if( key == VI_KEY( q ) ) { noEraseFileList = true; ExitEditor( -1 ); } else { return( false ); } return( true ); } /* handleKey */
/* * FindCharOnCurrentLine - look for c char on a line ('f','F','t','T' cmds) */ vi_rc FindCharOnCurrentLine( bool fwdflag, int mod, int *col, int cnt ) { int i, c, j; char lst[2]; c = CurrentPos.column - 1; *col = -1; LastEvent = GetNextEvent( FALSE ); if( LastEvent == VI_KEY( ESC ) ) { return( ERR_NO_ERR ); } lst[0] = (char)LastEvent; lst[1] = 0; i = 0; for( j = 0; j < cnt; j++ ) { i = -1; if( fwdflag ) { if( c < CurrentLine->len - 1 ) { i = findFirstCharInListForward( CurrentLine, lst, c + 1 ); } } else { if( c > 0 ) { i = findFirstCharInListBackwards( CurrentLine, lst, c - 1 ); } } if( i < 0 ) { Error( GetErrorMsg( ERR_CHAR_NOT_FOUND ), LastEvent ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } c = i; } *col = 1 + i + mod; return( ERR_NO_ERR ); } /* FindCharOnCurrentLine */
/* * extractViKeyToken - extract the character token from a data string, * assumes we are pointing at <CHAR> */ vi_key extractViKeyToken( unsigned char **p ) { char str[MAX_STR]; int j; vi_rc rc; int c; for( j = 0; (c = **p) != '\0'; ++j ) { (*p)++; if( c == '>' ) break; str[j] = c; } str[j] = '\0'; rc = readKeyData(); if( rc != ERR_NO_ERR ) { return( VI_KEY( ESC ) ); } j = Tokenize( charTokens, str, TRUE ); if( j == TOK_INVALID ) { return( (unsigned char)str[0] ); } else { return( keyVals[j] ); } } /* extractViKeyToken */
WINEXPORT LRESULT CALLBACK CommandWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l ) { PAINTSTRUCT ps; HDC hdc; window_id wid; switch( msg ) { case WM_CREATE: command_window_id = hwnd; SET_WNDINFO( hwnd, (LONG_PTR)&CommandWindow ); break; case WM_SETFOCUS: /* turn on caret */ NewCursor( hwnd, EditVars.NormalCursorType ); break; case WM_KILLFOCUS: /* turn off the caret */ MyHideCaret( hwnd ); DestroyCaret(); wid = (window_id)w; if( !BAD_ID( wid ) && ( wid == root_window_id || GetWindow( wid, GW_OWNER ) == edit_container_id ) ) { /* hmmm... losing focus to one of our own windows - suicide */ if( ReadingAString ) { KeyAdd( VI_KEY( ESC ) ); } } break; case WM_KEYDOWN: if( WindowsKeyPush( w, HIWORD( l ) ) ) { return( 0 ); } break; case WM_PAINT: hdc = BeginPaint( hwnd, &ps ); FillRect( hdc, &ps.rcPaint, ColorBrush( WIN_TEXT_BACKCOLOR( &CommandWindow ) ) ); /* this will cause the command window to redraw itself in readstr.c */ KeyAdd( VI_KEY( ALT_END ) ); EndPaint( hwnd, &ps ); break; case WM_DESTROY: command_window_id = NO_WINDOW; break; } return( DefWindowProc( hwnd, msg, w, l ) ); }
/* * BIOSGetKeyboard - get a keyboard char */ vi_key BIOSGetKeyboard( int *scan ) { vi_key key; EVENT ev; key = VI_KEY( DUMMY ); do { ev = uieventsource( 0 ); if ( ev < EV_FIRST_UNUSED ) { key = vi_keys[ev]; } } while ( key == VI_KEY( DUMMY ) ); if( scan != NULL ) { *scan = 0; } return( key ); } /* BIOSGetKeyboard */
/* * HotkeyProc - pass hotkeys on to root for various modeless 'bars' */ long WINEXP HotkeyProc( HWND hwnd, UINT msg, UINT wparam, LONG lparam ) { vi_key key; switch( msg ) { case WM_KEYDOWN: key = MapVirtualKeyToVIKey( wparam, HIWORD( lparam ) ); if( key == VI_KEY( F7 ) || key == VI_KEY( F8 ) || key == VI_KEY( F9 ) ) { return( SendMessage( Root, msg, wparam, lparam ) ); } break; } return( CallWindowProc( SubclassGenericFindOldProc( hwnd ), hwnd, msg, wparam, lparam ) ); }
/* * AddCurrentMouseEvent - add current mouse event to the override buffer */ void AddCurrentMouseEvent( void ) { KeyAdd( VI_KEY( MOUSEEVENT ) ); KeyAdd( LastMouseEvent ); KeyAdd( MouseRow ); KeyAdd( MouseCol ); KeyAdd( MouseStatus ); } /* AddCurrentMouseEvent */
static vi_key get_vi_key( EVENT ev ) { if( iseditchar( ev ) ) { return( (vi_key)ev ); } if( ev >= EV_FUNC( 1 ) && ev <= EV_FUNC( 10 ) ) { return( VI_KEY( F1 ) + ev - EV_FUNC( 1 ) ); } if( ev >= EV_SHIFT_FUNC( 1 ) && ev <= EV_SHIFT_FUNC( 10 ) ) { return( VI_KEY( SHIFT_F1 ) + ev - EV_SHIFT_FUNC( 1 ) ); } if( ev >= EV_CTRL_FUNC( 1 ) && ev <= EV_CTRL_FUNC( 10 ) ) { return( VI_KEY( CTRL_F1 ) + ev - EV_CTRL_FUNC( 1 ) ); } if( ev >= EV_ALT_FUNC( 1 ) && ev <= EV_ALT_FUNC( 10 ) ) { return( VI_KEY( ALT_F1 ) + ev - EV_FUNC( 1 ) ); } return( VI_KEY( DUMMY ) ); }
static vi_key cursorKeyFilter( input_buffer *input, vi_key event ) { int max_pos; max_pos = strlen( input->buffer ); switch( event ) { case VI_KEY( NULL ): break; case VI_KEY( HOME ): input->curr_pos = 0; input->left_column = 0; break; case VI_KEY( END ): endColumn( input ); break; case VI_KEY( RIGHT ): if( input->curr_pos < max_pos ) { input->curr_pos += 1; if( input->curr_pos > input->left_column + input->window.width ) { input->left_column += 1; } } else { MyBeep(); } break; case VI_KEY( LEFT ): if( input->curr_pos > 0 ) { input->curr_pos -= 1; if( input->left_column > input->curr_pos ) { input->left_column = input->curr_pos; } } break; case VI_KEY( DEL ): case VI_KEY( BS ): saveStr( input ); if( !deleteChar( input, event == VI_KEY( BS ) || input->curr_pos == max_pos ) ) { MyBeep(); } break; default: return( event ); } return( VI_KEY( NULL ) ); } /* cursorKeyFilter */
static vi_key historyFilter( input_buffer *input, vi_key event ) { history_data *h; if( input->h == NULL || input->h->curr == 0 ) { return( event ); } h = input->h; switch( event ) { case VI_KEY( UP ): if( h->curr > 0 ) { input->curr_hist -= 1; if( input->curr_hist < 0 || input->curr_hist < h->curr - h->max ) { input->curr_hist = h->curr - 1; } getHistory( input ); } break; case VI_KEY( DOWN ): if( h->curr > 0 ) { input->curr_hist += 1; if( input->curr_hist >= h->curr ) { input->curr_hist = h->curr - h->max; if( input->curr_hist < 0 ) { input->curr_hist = 0; } } getHistory( input ); } break; case VI_KEY( CTRL_TAB ): case VI_KEY( ALT_TAB ): doHistorySearch( input ); break; default: return( event ); } return( VI_KEY( NULL ) ); } /* historyFilter */
static bool mouseHandler( window_id wid, int x, int y ) { /* unused parameters */ (void)x; (void)y; if( wid != thisWindow ) { if( LastMouseEvent == VI_MOUSE_PRESS ) { KeyAdd( VI_KEY( ESC ) ); AddCurrentMouseEvent(); } } return( false ); } /* mouseHandler */
static bool mouseHandler( window_id wid, int x, int y ) { x = x; y = y; if( wid != thisWindow ) { if( LastMouseEvent == MOUSE_PRESS ) { KeyAdd( VI_KEY( ESC ) ); AddCurrentMouseEvent(); } } return( false ); } /* mouseHandler */
/* * InvokeLineSelHook - invoke the mouse selection */ vi_rc InvokeLineSelHook( linenum s, linenum e ) { char tmp[32]; int lne, col; #ifndef __WIN__ int has_bord; #endif #ifndef __WIN__ if( LastEvent != VI_KEY( MOUSEEVENT ) ) { has_bord = WindowAuxInfo( CurrentWindow, WIND_INFO_HAS_BORDER ); lne = WindowAuxInfo( CurrentWindow, WIND_INFO_Y1 ) + CurrentPos.line - LeftTopPos.line; col = WindowAuxInfo( CurrentWindow, WIND_INFO_X1 ) + VirtualColumnOnCurrentLine( CurrentPos.column ) - LeftTopPos.column - 1; if( has_bord ) { ++lne; ++col; } if( col < 0 ) { col = 0; } } else { col = MouseCol; lne = MouseRow; } #else if( LastEvent != VI_KEY( FAKEMOUSE ) ) { /* assume we're not in insert mode *ouch* */ col = PixelFromColumnOnCurrentLine( CurrentPos.column ); lne = (CurrentPos.line - LeftTopPos.line) * FontHeight( WIN_FONT( &EditWindow ) ); } else { col = MouseX; lne = MouseY; } #endif MySprintf( tmp, "%d %d %l %l", lne, col, s, e ); return( SourceHookData( SRC_HOOK_MOUSE_LINESEL, tmp ) ); } /* InvokeLineSelHook */
/* * getHotKey - get the hot key specified in a string */ static vi_key getHotKey( const char *str ) { if( str == NULL ) { return( 0 ); } while( *str != '\0' ) { if( *str == HOT_KEY_CHAR ) { return( toupper( *(str + 1) ) - 'A' + VI_KEY( ALT_A ) ); } str++; } return( 0 ); } /* getHotKey */
static void doHistorySearch( input_buffer *input ) { int curr; char *str; vi_key event; curr = input->h->curr; str = alloca( strlen( input->buffer ) + 1 ); strcpy( str, input->buffer ); event = VI_KEY( CTRL_TAB ); while( curr != -1 ) { if( event == VI_KEY( ALT_TAB ) || event == VI_KEY( CTRL_TAB ) ) { saveStr( input ); curr = searchHistory( input, str, curr ); displayLine( input ); event = GetNextEvent( true ); continue; } KeyAdd( event ); return; } } /* doHistorySearch */
/* * KeyAddString - add an entire string */ void KeyAddString( const char *str ) { key_map scr; vi_rc rc; vi_key *keys; rc = AddKeyMap( &scr, str ); if( rc == ERR_NO_ERR ) { for( keys = scr.data; *keys != VI_KEY( NULL ); ++keys ) { KeyAdd( *keys ); } } MemFree( scr.data ); } /* KeyAddString */
/* * WindowsKeyPush - handle the press of a key */ bool WindowsKeyPush( WORD vk, WORD data ) { vi_key key; // if we're holding everything just eat the key quietly if( EditFlags.HoldEverything ) { return( TRUE ); } key = MapVirtualKeyToVIKey( vk, data ); if( key != VI_KEY( DUMMY ) ) { keyBuffer[bufferTop] = GetVIKey( key, 0, FALSE ); bufferTop = (bufferTop + 1) % KEY_BUFFER_SIZE; return( TRUE ); } return( FALSE ); } /* WindowsKeyPush */
/* * PickATag - pick a tag */ int PickATag( int clist, char **list, char *tagname ) { window_info tw; int i; bool show_lineno; selectitem si; vi_rc rc; char title[MAX_STR]; memcpy( &tw, &dirw_info, sizeof( window_info ) ); tw.x1 = 12; tw.x2 = EditVars.WindMaxWidth - 12; i = tw.y2 - tw.y1 + 1; if( tw.has_border ) { i -= 2; } if( clist < i ) { tw.y2 -= i - clist; } if( clist > i ) { show_lineno = TRUE; } else { show_lineno = FALSE; } MySprintf( title, "Pick A File For Tag \"%s\"", tagname ); memset( &si, 0, sizeof( si ) ); si.wi = &tw; si.title = title; si.list = list; si.maxlist = clist; si.num = 0; si.retevents = NULL; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = 1; si.eiw = NO_WINDOW; rc = SelectItem( &si ); if( rc != ERR_NO_ERR ) { return( -1 ); } return( si.num ); } /* PickATag */
/* * GetTextForSpecialKey - get text for ^D,^E,^W, ALT_L, ^L, ^R */ bool GetTextForSpecialKey( int str_max, vi_key event, char *tmp ) { int i, l; switch( event ) { case VI_KEY( CTRL_E ): case VI_KEY( CTRL_W ): tmp[0] = '\0'; GimmeCurrentWord( tmp, str_max, event == VI_KEY( CTRL_E ) ); tmp[str_max] = '\0'; break; case VI_KEY( ALT_L ): if( CurrentLine == NULL ) { break; } i = CurrentPos.column - 1; if( i < 0 ) i = 0; ExpandTabsInABuffer( &CurrentLine->data[i], CurrentLine->len - i, tmp, str_max ); break; case VI_KEY( CTRL_L ): if( CurrentLine == NULL ) { break; } ExpandTabsInABuffer( &CurrentLine->data[0], CurrentLine->len, tmp, str_max ); break; case VI_KEY( CTRL_R ): if( CurrentLine == NULL ) { break; } if( SelRgn.lines ) { assert( SelRgn.start.line == SelRgn.end.line ); i = 1; l = CurrentLine->len + 1; } else { if( SelRgn.start.column < SelRgn.end.column ) { i = SelRgn.start.column; l = SelRgn.end.column - SelRgn.start.column + 1; } else { i = SelRgn.end.column; l = SelRgn.start.column - SelRgn.end.column + 1; } } ExpandTabsInABuffer( &CurrentLine->data[i - 1], l, tmp, str_max ); tmp[l] = '\0'; default: return( false ); } return( true ); } /* GetTextForSpecialKey */
/* * MovePosition - move to a screen position */ vi_rc MovePosition( void ) { linenum lne, lines; vi_key key; vi_rc rc; if( RepeatDigits == 0 ) { lne = CurrentPos.line; } else { lne = GetRepeatCount(); if( IsPastLastLine( lne ) ) { return( ERR_INVALID_REDRAW ); } } lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ); key = GetNextEvent( false ); switch( key ) { case '.': LeftTopPos.line = lne - lines / 2; break; case VI_KEY( ENTER ): LeftTopPos.line = lne; break; case '-': LeftTopPos.line = lne - lines + 1; break; default: return( ERR_INVALID_REDRAW ); } if( LeftTopPos.line < 1 ) { LeftTopPos.line = 1; } SetCurrentLineNumber( lne ); rc = CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine ); CurrentPos.column = 1; DCInvalidateAllLines(); DCDisplayAllLines(); if( rc == ERR_NO_ERR ) { rc = GoToColumnOnCurrentLine( FindStartOfCurrentLine() ); } return( rc ); } /* MovePosition */
/* * StartSaveExit - prepare to do save & exit of file */ vi_rc StartSaveExit( void ) { vi_key key; vi_key levent; /* * get the next key */ levent = LastEvent; key = GetNextEvent( FALSE ); if( key != levent ) { if( key == VI_KEY( ESC ) ) { return( ERR_NO_ERR ); } return( InvalidKey() ); } return( SaveAndExit( NULL ) ); } /* StartSaveExit */
/* * GetTextForSpecialKey - get text for ^D,^E,^W, ALT_L, ^L, ^R */ bool GetTextForSpecialKey( vi_key event, char *buff, int buffsize ) { int i; int len; if( buffsize > 0 ) buff[0] = '\0'; switch( event ) { case VI_KEY( CTRL_E ): case VI_KEY( CTRL_W ): GimmeCurrentWord( buff, buffsize, event == VI_KEY( CTRL_E ) ); break; case VI_KEY( ALT_L ): if( CurrentLine != NULL ) { i = CurrentPos.column - 1; if( i < 0 ) i = 0; ExpandTabsInABuffer( &CurrentLine->data[i], CurrentLine->len - i, buff, buffsize ); } break; case VI_KEY( CTRL_L ): if( CurrentLine != NULL ) { ExpandTabsInABuffer( &CurrentLine->data[0], CurrentLine->len, buff, buffsize ); } break; case VI_KEY( CTRL_R ): if( CurrentLine != NULL ) { if( SelRgn.lines ) { assert( SelRgn.start.line == SelRgn.end.line ); i = 1; len = CurrentLine->len + 1; } else { if( SelRgn.start.column < SelRgn.end.column ) { i = SelRgn.start.column; len = SelRgn.end.column - SelRgn.start.column + 1; } else { i = SelRgn.end.column; len = SelRgn.start.column - SelRgn.end.column + 1; } } ExpandTabsInABuffer( &CurrentLine->data[i - 1], len, buff, buffsize ); } break; default: return( false ); } return( true ); } /* GetTextForSpecialKey */
static vi_key specialKeyFilter( input_buffer *input, vi_key event ) { char *tmp; switch( event ) { case VI_KEY( ALT_O ): case VI_KEY( CTRL_O ): InsertTextForSpecialKey( event, input->buffer ); break; case VI_KEY( CTRL_R ): if( !SelRgn.selected || (SelRgn.lines && (SelRgn.start.line != SelRgn.end.line)) ) { MyBeep(); break; } case VI_KEY( CTRL_W ): case VI_KEY( CTRL_E ): case VI_KEY( ALT_L ): case VI_KEY( CTRL_L ): if( input->curr_pos != strlen( input->buffer ) ) { MyBeep(); } else { tmp = MemAlloc( input->buffer_length ); assert( tmp != NULL ); GetTextForSpecialKey( input->buffer_length - strlen( input->buffer ) - 1, event, tmp ); saveStr( input ); insertString( input, tmp ); MemFree( tmp ); } break; default: return( event ); break; } return( VI_KEY( NULL ) ); } /* specialKeyFilter */
/* * DoSavebufNumber - get a savebuf number */ vi_rc DoSavebufNumber( void ) { vi_key key; char buff[2]; vi_rc rc; /* * get savebuf to use */ key = GetNextEvent( false ); if( key == VI_KEY( ESC ) ) { return( ERR_NO_ERR ); } buff[0] = (char)key; buff[1] = '\0'; rc = SetSavebufNumber( buff ); if( rc == ERR_NO_ERR ) { rc = GOT_A_SAVEBUF; } return( rc ); } /* DoSavebufNumber */