前へ 次へ
技術文章qvi

o コマンドはカーソル行の直後に、O コマンドはカーソル行の直前に1行を追加して、挿入モードに以降するコマンドである。

実装

 1: bool ViEngine::doViCommand(const QChar &qch)
 2: {
 3:     ....
 4:         switch( ch ) {
 5:             .....
 6:         case 'o':
 7:         case 'O':
 8:             m_joinPrevEditBlock = true;
 9:             m_editor->doOpenLine(/*next=*/ch == 'o');
10:             cur = m_editor->textCursor();
11:             toInsertMode = true;
12:             break;
13:         }
14:     ....
15: }
 1: void ViEditView::doOpenLine(bool next)
 2: {
 3:     QTextCursor cur = textCursor();
 4:     bool EOFLine = false;
 5:     if( next ) {
 6:         if( cur.block() == cur.document()->lastBlock() ) {
 7:             EOFLine = true;
 8:             cur.movePosition(QTextCursor::EndOfBlock);
 9:         } else {
10:             cur.movePosition(QTextCursor::NextBlock);
11:             cur.movePosition(QTextCursor::StartOfBlock);
12:         }
13:     } else
14:         cur.movePosition(QTextCursor::StartOfBlock);
15:     cur.insertText("\n");
16:     if( !EOFLine )
17:         cur.movePosition(QTextCursor::Left);
18:     setTextCursor(cur);
19: }


Tweet


前へ 次へ
技術文章qvi