前へ 次へ
技術文章qvi

前稿で vi 使いが大好きな .(dot) コマンドを実装したが、以下の問題があった。

BackSpace 対応

 1: bool ViEngine::insModeKeyPressEvent(QKeyEvent *event)
 2: {
 3:     .....
 4:     if( m_redoRecording ) {
 5:         const QString text = event->text();
 6:         if( !text.isEmpty() ) {
 7:             if( text[0] == 0x08 ) {     //  BackSpace
 8:                 if( !m_insertedText.isEmpty() )
 9:                     m_insertedText = m_insertedText.left(m_insertedText.length() - 1);
10:             } else
11:                 m_insertedText += text[0];
12:         }
13:     }
14:     return false;
15: }

カーソル移動対応

 1: bool ViEngine::insModeKeyPressEvent(QKeyEvent *event)
 2: {
 3:     .....
 4:     if( m_redoRecording ) {
 5:         const QString text = event->text();
 6:         if( !text.isEmpty() ) {
 7:             if( text[0] == 0x08 ) {     //  BackSpace
 8:                 if( !m_insertedText.isEmpty() )
 9:                     m_insertedText = m_insertedText.left(m_insertedText.length() - 1);
10:             } else if( text[0].unicode() < ' ' && text[0] != '\r' && text[0] != '\n' )
11:                 m_redoRecording = false;
12:             else
13:                 m_insertedText += text[0];
14:         } else if( m_redoRecording ) {
15:             const int key = event->key();
16:             if( key == Qt::Key_Left || key == Qt::Key_Right ||
17:                 key == Qt::Key_Up || key == Qt::Key_Down ||
18:                 key == Qt::Key_PageUp || key == Qt::Key_PageDown ||
19:                 key == Qt::Key_Home || key == Qt::Key_End )
20:             {
21:                 m_redoRecording = false;
22:             }
23:         }
24:     }
25:     return false;
26: }

Tweet


前へ 次へ
技術文章qvi