Ejemplo n.º 1
0
/*
 * AddSelRgnToSavebufAndDelete - copy selected text to savebuf, then kill it
 */
vi_rc AddSelRgnToSavebufAndDelete( void )
{
    AddSelRgnToSavebuf();
    DeleteSelectedRegion();
    return( ERR_NO_ERR );
}
Ejemplo n.º 2
0
/*
 * insertGenericSavebuf - insert contents of a savebuf before/after current pos
 */
static vi_rc insertGenericSavebuf( int buf, bool afterflag )
{
#ifdef __WIN__
    savebuf     clip;
#endif
    savebuf     *tmp;
    fcb_list    fcblist;
    fcb         *end;
    int         i, scol, len;
    int         maxCursor;
    vi_rc       rc;

    rc = ModificationTest();
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    if( EditFlags.Modeless ) {
        DeleteSelectedRegion();
        SelRgn.selected = false;
    }

#ifdef __WIN__
    if( buf == CLIPBOARD_SAVEBUF ) {
        rc = GetClipboardSavebuf( &clip );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
        tmp = &clip;
    } else
#endif
    if( buf >= MAX_SAVEBUFS ) {
        tmp = &SpecialSavebufs[buf - MAX_SAVEBUFS];
    } else {
        tmp = &Savebufs[buf];
    }
    switch( tmp->type ) {
    case SAVEBUF_NOP:
        rc = ERR_EMPTY_SAVEBUF;
        break;
    case SAVEBUF_LINE:
        /*
         * get starting data
         */
        len = strlen( tmp->u.data );
        if( len + CurrentLine->len >= EditVars.MaxLine ) {
            rc = ERR_LINE_FULL;
            break;
        }
        if( afterflag ) {
            scol = CurrentPos.column;
        } else {
            scol = CurrentPos.column - 1;
        }
        CurrentLineReplaceUndoStart();
        GetCurrentLine();

        /*
         * open up line and copy in data
         */
        if( WorkLine->len == 0 ) {
            scol = 0;
        }
        for( i = WorkLine->len; i >= scol; i-- ) {
            WorkLine->data[i + len] = WorkLine->data[i];
        }
        for( i = 0; i < len; i++ ) {
            WorkLine->data[i + scol] = tmp->u.data[i];
        }
        WorkLine->len += len;
        DisplayWorkLine( true );
        ReplaceCurrentLine();
        CurrentLineReplaceUndoEnd( true );
        scol += len + 1;

        maxCursor = CurrentLine->len;
        if( EditFlags.Modeless ) {
            maxCursor++;
        }
        if( scol > maxCursor ) {
            scol = maxCursor;
        }
        rc = GoToColumn( scol, maxCursor );
        break;

    case SAVEBUF_FCBS:
        fcblist.head = NULL;
        fcblist.tail = NULL;
        end = tmp->u.fcbs.tail->next;
        tmp->u.fcbs.tail->next = NULL;
        CreateDuplicateFcbList( tmp->u.fcbs.head, &fcblist );
        tmp->u.fcbs.tail->next = end;

        if( !EditFlags.LineBased ) {
            rc = InsertLinesAtCursor( &fcblist, UndoStack );
        } else {
            if( afterflag) {
                rc = InsertLines( CurrentPos.line, &fcblist, UndoStack );
            } else {
                rc = InsertLines( CurrentPos.line - 1, &fcblist, UndoStack );
            }
        }
        break;
    }
#ifdef __WIN__
    if( tmp == &clip ) {
        freeSavebuf( &clip );
    }
#endif

    EditFlags.Dotable = true;

    return( rc );

} /* insertGenericSavebuf */
Ejemplo n.º 3
0
/*
 * DoLastEvent - process the last keystroke event
 */
vi_rc DoLastEvent( void )
{
    event       *event;
    vi_rc       rc;
    bool        keep_sel;

    if( LastEvent >= MAX_EVENTS ) {
        rc = InvalidKey();
    } else if( !EditFlags.Modeless && EditFlags.InsertModeActive ) {
//        UnselectRegion();
        if( EditFlags.EscapedInsertChar ) {
            rc = IMChar();
        } else if( InputKeyMaps[LastEvent].data != NULL && !InputKeyMaps[LastEvent].inuse ) {
            rc = StartInputKeyMap( LastEvent );
        } else {
            rc = (EventList[LastEvent].ins)();
        }
    } else if( !EditFlags.Modeless && KeyMaps[LastEvent].data != NULL && !KeyMaps[LastEvent].inuse ) {
        rc = DoKeyMap( LastEvent );
    } else {
        event = &EventList[LastEvent];
        keep_sel = event->b.keep_selection;
        if( event->b.keep_selection_maybe ) {
            if( SelRgn.selected ) {
                keep_sel = true;
            }
        }
        if( !keep_sel && !EditFlags.ScrollCommand ) {
            UnselectRegion();
        }
        if( !EditFlags.ScrollCommand ) {
            ensureCursorDisplayed();
        }
        rc = ERR_NO_ERR;
        switch( event->b.type ) {
        case EVENT_INS:
            if( EditFlags.Modeless ) {
                /* don't allow following cursor movements to affect seln
                 */
                keep_sel = SelRgn.selected;
                DeleteSelectedRegion();
                SelRgn.selected = keep_sel;
                InsertLikeLast();
                rc = event->rtn.ins();
                DoneCurrentInsert( false );
                SelRgn.selected = false;
            } else {
                if( !EditFlags.InsertModeActive ) {
                    InsertLikeLast();
                }
                rc = event->rtn.ins();
            }
            break;
        case EVENT_OP:
            DoneCurrentInsert( true );
            rc = doOperator( event );
            break;
        case EVENT_REL_MOVE:
        case EVENT_ABS_MOVE:
            DoneCurrentInsert( true );
            rc = DoMove( event );
            break;
        case EVENT_MISC:
            DoneCurrentInsert( true );
            rc = event->rtn.old();
            break;
        }
    }
    return( rc );

} /* DoLastEvent */