[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: KDE/kdelibs/kate/vimode
From:       Allen Winter <winter () kde ! org>
Date:       2008-05-30 11:20:53
Message-ID: 200805300720.53931.winter () kde ! org
[Download RAW message or body]

On Friday 30 May 2008 03:07:29 Erlend Hamberg wrote:
> SVN commit 814366 by ehamberg:
>
> more commands. some up/down motions testing.

I'm concerned that all this work is for a new feature.
If so, you really need to stop.  We are in a feature freeze.

>
>
>  M  +117 -75   katevinormalmode.cpp
>  M  +21 -11    katevinormalmode.h
>  M  +7 -6      katevinormalmodecommand.cpp
>  M  +4 -4      katevinormalmodecommand.h
>
>
> --- trunk/KDE/kdelibs/kate/vimode/katevinormalmode.cpp #814365:814366
> @@ -53,34 +53,16 @@
>    kDebug( 13070 ) << key << "(" << keyCode << ")";
>
>
> -  //if ( m_findWaitingForChar ) {
> -  //  switch ( m_keys[ m_keys.size() -1 ].toAscii() ) {
> -  //  case 'f':
> -  //    commandFindChar();
> -  //    break;
> -  //  case 't':
> -  //    commandToChar( key );
> -  //    break;
> -  //  case 'F':
> -  //    commandFindCharBackwards( key );
> -  //    break;
> -  //  case 'T':
> -  //    commandToCharBackwards( key );
> -  //    break;
> -  //  default:
> -  //    kError( 13070 ) << "Error: m_findWaitingForChar should not be
> true, m_keys=" << m_keys; -  //  }
> -  //  reset();
> -  //  return true;
> -  //}
> -
>    // if keyCode is a number, append it to m_count
>    if ( m_gettingCount && keyCode >= Qt::Key_0 && keyCode <= Qt::Key_9 ) {
> -    m_count *= 10;
> -    m_count += keyCode-Qt::Key_0;
> -    kDebug( 13070 ) << "count: " << m_count;
> +    // the first digit can't be 0 ('0' is a command)
> +    if ( m_count != 0 || keyCode != Qt::Key_0 ) {
> +      m_count *= 10;
> +      m_count += keyCode-Qt::Key_0;
> +      kDebug( 13070 ) << "count: " << m_count;
>
> -    return false;
> +      return false;
> +    }
>    }
>
>    if ( m_gettingCount ) {
> @@ -107,42 +89,6 @@
>      return false;
>    }
>
> -  // deal with simple one-key commands quick'n'easy
> -  //switch ( key.toAscii() ) {
> -  //case 'a':
> -  //  enterInsertModeAppend();
> -  //  break;
> -  //case 'A':
> -  //  enterInsertModeAppendEOL();
> -  //  break;
> -  //case 'f':
> -  //case 'F':
> -  //case 't':
> -  //case 'T':
> -  //  m_findWaitingForChar = true;
> -  //  m_keys.append( key );
> -  //  return false;
> -  //  break;
> -  //case 'h':
> -  //  commandCursorLeft();
> -  //  break;
> -  //case 'i':
> -  //  enterInsertMode();
> -  //  break;
> -  //case 'j':
> -  //  commandCursorDown();
> -  //  break;
> -  //case 'k':
> -  //  commandCursorUp();
> -  //  break;
> -  //case 'l':
> -  //  commandCursorRight();
> -  //  break;
> -  //default:
> -  //  reset();
> -  //  return false;
> -  //}
> -
>    return false;
>  }
>
> @@ -160,7 +106,7 @@
>    m_matches.clear();
>  }
>
> -QString KateViNormalMode::getLine( int lineNumber )
> +QString KateViNormalMode::getLine( int lineNumber ) const
>  {
>    QString line;
>
> @@ -178,7 +124,7 @@
>   * enter insert mode at the cursor position
>   */
>
> -void KateViNormalMode::enterInsertMode()
> +bool KateViNormalMode::commandEnterInsertMode()
>  {
>    m_view->changeViMode( InsertMode );
>    m_viewInternal->repaint ();
> @@ -187,13 +133,15 @@
>
>    emit m_view->viewModeChanged( m_view );
>    //emit m_view->viewEditModeChanged( this,viewEditMode() );
> +
> +  return true;
>  }
>
>  /**
>   * enter insert mode after the current character
>   */
>
> -void KateViNormalMode::enterInsertModeAppend()
> +bool KateViNormalMode::commandEnterInsertModeAppend()
>  {
>    m_view->changeViMode( InsertMode );
>    m_viewInternal->cursorRight();
> @@ -201,13 +149,15 @@
>
>    emit m_view->viewModeChanged( m_view );
>    //emit viewEditModeChanged( this,viewEditMode() );
> +
> +  return false;
>  }
>
>  /**
>   * start insert mode after the last character of the line
>   */
>
> -void KateViNormalMode::enterInsertModeAppendEOL()
> +bool KateViNormalMode::commandEnterInsertModeAppendEOL()
>  {
>    m_view->changeViMode( InsertMode );
>    m_viewInternal->end();
> @@ -215,32 +165,74 @@
>
>    emit m_view->viewModeChanged( m_view );
>    //emit viewEditModeChanged( this,viewEditMode() );
> +
> +  return true;
>  }
>
> -void KateViNormalMode::commandCursorDown()
> +bool KateViNormalMode::commandGoDownDisplayLine()
>  {
>    m_viewInternal->cursorDown();
>    //m_viewInternal->repaint();
>  }
>
> -void KateViNormalMode::commandCursorUp()
> +bool KateViNormalMode::commandGoDown()
>  {
> +  KTextEditor::Cursor cursor ( m_view->cursorPosition() );
> +
> +  if ( m_viewInternal->m_doc->numVisLines()-1 > cursor.line() ) {
> +    cursor.setLine( cursor.line()+1 );
> +    if ( getLine( cursor.line() ).length()-1 < cursor.column() )
> +      cursor.setColumn( getLine( cursor.line() ).length()-1 );
> +
> +    m_viewInternal->updateCursor( cursor );
> +    return true;
> +  }
> +
> +  return false;
> +  //m_viewInternal->repaint();
> +}
> +
> +bool KateViNormalMode::commandGoUpDisplayLine()
> +{
>    m_viewInternal->cursorUp();
>    //m_viewInternal->repaint();
>  }
>
> -void KateViNormalMode::commandCursorLeft()
> +bool KateViNormalMode::commandGoUp()
>  {
> -  m_view->cursorLeft();
> +  KTextEditor::Cursor cursor ( m_view->cursorPosition() );
> +
> +  if ( cursor.line() > 0 ) {
> +    cursor.setLine( cursor.line()-1 );
> +    if ( getLine( cursor.line() ).length()-1 < cursor.column() )
> +      cursor.setColumn( getLine( cursor.line() ).length()-1 );
> +
> +    m_viewInternal->updateCursor( cursor );
> +    return true;
> +  }
> +
> +  return false;
>    //m_viewInternal->repaint();
>  }
>
> -void KateViNormalMode::commandCursorRight()
> +bool KateViNormalMode::commandGoLeft()
>  {
> -  m_view->cursorRight();
> +  KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
> +
> +  if ( cursor.column() != 0 )
> +    m_view->cursorLeft();
>    //m_viewInternal->repaint();
>  }
>
> +bool KateViNormalMode::commandGoRight()
> +{
> +  KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
> +
> +  if ( cursor.column() != getLine().length()-1 )
> +    m_view->cursorRight();
> +  //m_viewInternal->repaint();
> +}
> +
>  bool KateViNormalMode::commandFindChar()
>  {
>    KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
> @@ -258,7 +250,7 @@
>    return false;
>  }
>
> -bool KateViNormalMode::commandFindCharBackwards()
> +bool KateViNormalMode::commandFindCharBackward()
>  {
>    KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
>    QString line = getLine();
> @@ -297,7 +289,7 @@
>    return false;
>  }
>
> -bool KateViNormalMode::commandToCharBackwards()
> +bool KateViNormalMode::commandToCharBackward()
>  {
>    KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
>    QString line = getLine();
> @@ -319,10 +311,60 @@
>    return false;
>  }
>
> +bool KateViNormalMode::commandGoToEOL()
> +{
> +  KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
> +
> +  cursor.setColumn( getLine().length()-1 );
> +  m_viewInternal->updateCursor( cursor );
> +  return true;
> +}
> +
> +bool KateViNormalMode::commandGoToFirstCharacterOfLine()
> +{
> +  KTextEditor::Cursor cursor ( m_view->cursorPositionVirtual() );
> +
> +  cursor.setColumn( 0 );
> +  m_viewInternal->updateCursor( cursor );
> +  return true;
> +}
> +
> +bool KateViNormalMode::commandGoWordForward()
> +{
> +  return true;
> +}
> +
> +bool KateViNormalMode::commandGoWordBackward()
> +{
> +  return true;
> +}
> +
> +bool KateViNormalMode::commandGoWORDForward()
> +{
> +  return true;
> +}
> +
> +bool KateViNormalMode::commandGoWORDBackward()
> +{
> +  return true;
> +}
> +
> +
>  void KateViNormalMode::initializeCommands()
>  {
>    m_commands.push_back( new KateViNormalModeCommand( this, "f.",
> &KateViNormalMode::commandFindChar, true ) ); -  m_commands.push_back( new
> KateViNormalModeCommand( this, "F.",
> &KateViNormalMode::commandFindCharBackwards, true ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "F.",
> &KateViNormalMode::commandFindCharBackward, true ) ); m_commands.push_back(
> new KateViNormalModeCommand( this, "t.", &KateViNormalMode::commandToChar,
> true ) ); -  m_commands.push_back( new KateViNormalModeCommand( this, "T.",
> &KateViNormalMode::commandToCharBackwards, true ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "T.",
> &KateViNormalMode::commandToCharBackward, true ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "h",
> &KateViNormalMode::commandGoLeft, false ) ); +  m_commands.push_back( new
> KateViNormalModeCommand( this, "j", &KateViNormalMode::commandGoDown, false
> ) ); +  m_commands.push_back( new KateViNormalModeCommand( this, "k",
> &KateViNormalMode::commandGoUp, false ) ); +  m_commands.push_back( new
> KateViNormalModeCommand( this, "l", &KateViNormalMode::commandGoRight,
> false ) ); +  m_commands.push_back( new KateViNormalModeCommand( this,
> "gj", &KateViNormalMode::commandGoDownDisplayLine, false ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "gk",
> &KateViNormalMode::commandGoUpDisplayLine, false ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "0",
> &KateViNormalMode::commandGoToFirstCharacterOfLine, false ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "$",
> &KateViNormalMode::commandGoToEOL, false ) ); +  m_commands.push_back( new
> KateViNormalModeCommand( this, "i",
> &KateViNormalMode::commandEnterInsertMode, false ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "a",
> &KateViNormalMode::commandEnterInsertModeAppend, false ) ); + 
> m_commands.push_back( new KateViNormalModeCommand( this, "A",
> &KateViNormalMode::commandEnterInsertModeAppendEOL, false ) ); }
> --- trunk/KDE/kdelibs/kate/vimode/katevinormalmode.h #814365:814366
> @@ -37,26 +37,36 @@
>
>      bool handleKeypress( QKeyEvent *e );
>
> -    void enterInsertMode();
> -    void enterInsertModeAppend();
> -    void enterInsertModeAppendEOL();
> +    bool commandEnterInsertMode();
> +    bool commandEnterInsertModeAppend();
> +    bool commandEnterInsertModeAppendEOL();
>
> -    void commandCursorLeft();
> -    void commandCursorRight();
> -    void commandCursorDown();
> -    void commandCursorUp();
> +    bool commandGoLeft();
> +    bool commandGoRight();
> +    bool commandGoDown();
> +    bool commandGoUp();
> +    bool commandGoDownDisplayLine();
> +    bool commandGoUpDisplayLine();
>
>      bool commandFindChar();
> -    bool commandFindCharBackwards();
> +    bool commandFindCharBackward();
>      bool commandToChar();
> -    bool commandToCharBackwards();
> +    bool commandToCharBackward();
>
> -    unsigned int getCount() { return m_count; }
> +    bool commandGoToFirstCharacterOfLine();
> +    bool commandGoToEOL();
>
> +    bool commandGoWordForward();
> +    bool commandGoWordBackward();
> +    bool commandGoWORDForward();
> +    bool commandGoWORDBackward();
> +
> +    unsigned int getCount() const { return ( m_count > 0 ) ? m_count : 1;
> } +
>    private:
>      void reset();
>      void initializeCommands();
> -    QString getLine( int lineNumber = -1 );
> +    QString getLine( int lineNumber = -1 ) const;
>
>      KateView *m_view;
>      KateViewInternal *m_viewInternal;
> --- trunk/KDE/kdelibs/kate/vimode/katevinormalmodecommand.cpp
> #814365:814366 @@ -19,24 +19,24 @@
>
>  #include "katevinormalmodecommand.h"
>
> -KateViNormalModeCommand::KateViNormalModeCommand( KateViNormalMode
> *parent, QString pattern, bool(KateViNormalMode::*pt2Func)(), bool regex )
> +KateViNormalModeCommand::KateViNormalModeCommand( KateViNormalMode
> *parent, QString pattern, bool(KateViNormalMode::*commandMethod)(), bool
> regex ) {
>    m_parent = parent;
>    m_pattern = pattern;
>    m_regex = regex;
> -  m_pt2Func = pt2Func;
> +  m_ptr2commandMethod = commandMethod;
>  }
>
>  KateViNormalModeCommand::~KateViNormalModeCommand()
>  {
>  }
>
> -void KateViNormalModeCommand::execute()
> +bool KateViNormalModeCommand::execute() const
>  {
> -  (m_parent->*m_pt2Func)();
> +  return (m_parent->*m_ptr2commandMethod)();
>  }
>
> -bool KateViNormalModeCommand::matches( QString pattern )
> +bool KateViNormalModeCommand::matches( QString pattern ) const
>  {
>    if ( !m_regex )
>      return m_pattern.startsWith( pattern );
> @@ -47,8 +47,9 @@
>    }
>  }
>
> -bool KateViNormalModeCommand::matchesExact( QString pattern )
> +bool KateViNormalModeCommand::matchesExact( QString pattern ) const
>  {
> +  kDebug( 13070 ) << pattern << " " << m_pattern;
>    if ( !m_regex )
>      return ( m_pattern == pattern );
>    else {
> --- trunk/KDE/kdelibs/kate/vimode/katevinormalmodecommand.h #814365:814366
> @@ -29,15 +29,15 @@
>      KateViNormalModeCommand( KateViNormalMode *parent, QString pattern,
> bool(KateViNormalMode::*pt2Func)(), bool regex = true );
> ~KateViNormalModeCommand();
>
> -    bool matches( QString pattern );
> -    bool matchesExact( QString pattern );
> -    void execute();
> +    bool matches( QString pattern ) const;
> +    bool matchesExact( QString pattern ) const;
> +    bool execute() const;
>
>    private:
>      KateViNormalMode *m_parent;
>      QString m_pattern;
>      bool m_regex;
> -    bool (KateViNormalMode::*m_pt2Func)();
> +    bool (KateViNormalMode::*m_ptr2commandMethod)();
>  };
>
>  #endif

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic