2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/**************************************************************************
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** This file is part of Qt Creator
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-17 00:01:27 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** Contact: Nokia Corporation (qt-info@nokia.com)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** Commercial Usage
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** Licensees holding valid Qt Commercial licenses may use this file in
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** accordance with the Qt Commercial License Agreement provided with the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** Software or, alternatively, in accordance with the terms contained in
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** a written agreement between you and Nokia.
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** GNU Lesser General Public License Usage
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** Alternatively, this file may be used under the terms of the GNU Lesser
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** General Public License version 2.1 as published by the Free Software
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** Foundation and appearing in the file LICENSE.LGPL included in the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** packaging of this file.  Please review the following information to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** ensure the GNU Lesser General Public License version 2.1 requirements
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** If you are unsure which license is appropriate for your use, please
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-17 00:01:27 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								** contact the sales department at http://www.qtsoftware.com/contact.
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								**
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								**************************************************************************/
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 16:54:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "fakevimhandler.h"
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// ATTENTION:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 1 Please do not add any direct dependencies to other Qt Creator code here.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   Instead emit signals and let the FakeVimPlugin channel the information to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   Qt Creator. The idea is to keep this file here in a "clean" state that
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 2 There are a few auto tests located in ../../../tests/auto/fakevim.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   Commands that are covered there are marked as "// tested" below.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 3 Some conventions:
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//   Use 1 based line numbers and 0 based column numbers. Even though
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   the 1 based line are not nice it matches vim's and QTextEdit's 'line'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   concepts.
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//   Do not pass QTextCursor etc around unless really needed. Convert
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   early to  line/column.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   There is always a "current" cursor (m_tc). A current "region of interest"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   spans between m_anchor (== anchor()) and  m_tc.position() (== position())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//   The value of m_tc.anchor() is not used.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <utils/qtcassert.h>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 13:32:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QDebug>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QFile>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QObject>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QPointer>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QProcess>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QRegExp>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QTextStream>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QtAlgorithms>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtCore/QStack>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QApplication>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QKeyEvent>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QLineEdit>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QPlainTextEdit>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QScrollBar>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QTextBlock>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QTextCursor>
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QTextDocumentFragment>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <QtGui/QTextEdit>
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//#define DEBUG_KEY  1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#if DEBUG_KEY
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#   define KEY_DEBUG(s) qDebug() << s
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#   define KEY_DEBUG(s)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								//#define DEBUG_UNDO  1
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#if DEBUG_UNDO
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#   define UNDO_DEBUG(s) qDebug() << << m_tc.document()->revision() << s
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#   define UNDO_DEBUG(s)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								using namespace Core::Utils;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespace FakeVim {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespace Internal {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								///////////////////////////////////////////////////////////////////////
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// FakeVimHandler
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								///////////////////////////////////////////////////////////////////////
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-14 15:47:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#define StartOfLine     QTextCursor::StartOfLine
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define EndOfLine       QTextCursor::EndOfLine
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define MoveAnchor      QTextCursor::MoveAnchor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define KeepAnchor      QTextCursor::KeepAnchor
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define Up              QTextCursor::Up
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define Down            QTextCursor::Down
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define Right           QTextCursor::Right
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define Left            QTextCursor::Left
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define EndOfDocument   QTextCursor::End
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#define StartOfDocument QTextCursor::Start
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 18:29:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#define EDITOR(s) (m_textedit ? m_textedit->s : m_plaintextedit->s)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const int ParagraphSeparator = 0x00002029;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								using namespace Qt;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum Mode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    InsertMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    CommandMode,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ExMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    SearchForwardMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    SearchBackwardMode,
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum SubMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NoSubMode,
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ChangeSubMode,     // used for c
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    DeleteSubMode,     // used for d
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    FilterSubMode,     // used for !
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 16:33:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    IndentSubMode,     // used for =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    RegisterSubMode,   // used for "
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:08:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ReplaceSubMode,    // used for R and r
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ShiftLeftSubMode,  // used for <
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ShiftRightSubMode, // used for >
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 16:33:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    WindowSubMode,     // used for Ctrl-w
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    YankSubMode,       // used for y
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ZSubMode,          // used for z
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    CapitalZSubMode    // used for Z
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum SubSubMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:08:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // typically used for things that require one more data item
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // and are 'nested' behind a mode
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    NoSubSubMode,
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    FtSubSubMode,       // used for f, F, t, T
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MarkSubSubMode,     // used for m
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    BackTickSubSubMode, // used for `
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 14:19:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    TickSubSubMode,     // used for '
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum VisualMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    NoVisualMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    VisualCharMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    VisualLineMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    VisualBlockMode,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum MoveType
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MoveExclusive,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    MoveInclusive,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    MoveLineWise,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QDebug &operator<<(QDebug &ts, const QList<QTextEdit::ExtraSelection> &sels)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    foreach (QTextEdit::ExtraSelection sel, sels)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ts << "SEL: " << sel.cursor.anchor() << sel.cursor.position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return ts;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:09:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QString quoteUnprintable(const QString &ba)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:09:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString res;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (int i = 0, n = ba.size(); i != n; ++i) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QChar c = ba.at(i);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (c.isPrint())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            res += c;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            res += QString("\\x%1").arg(c.unicode(), 2, 16);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return res;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								enum EventResult
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventHandled,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventUnhandled,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventPassedToCore
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								class FakeVimHandler::Private
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Private(FakeVimHandler *parent, QWidget *widget);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EventResult handleEvent(QKeyEvent *ev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool wantsOverride(QKeyEvent *ev);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void handleCommand(const QString &cmd); // sets m_tc + handleExCommand
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void handleExCommand(const QString &cmd);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void installEventFilter();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void setupWidget();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void restoreWidget();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 17:31:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    friend class FakeVimHandler;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    static int shift(int key) { return key + 32; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    static int control(int key) { return key + 256; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void init();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EventResult handleKey(int key, int unmodified, const QString &text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventResult handleInsertMode(int key, int unmodified, const QString &text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventResult handleCommandMode(int key, int unmodified, const QString &text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventResult handleRegisterMode(int key, int unmodified, const QString &text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EventResult handleMiniBufferModes(int key, int unmodified, const QString &text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void finishMovement(const QString &text = QString());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void search(const QString &needle, bool forward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void highlightMatches(const QString &needle);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int mvCount() const { return m_mvcount.isEmpty() ? 1 : m_mvcount.toInt(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int opCount() const { return m_opcount.isEmpty() ? 1 : m_opcount.toInt(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int count() const { return mvCount() * opCount(); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int leftDist() const { return m_tc.position() - m_tc.block().position(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int rightDist() const { return m_tc.block().length() - leftDist() - 1; }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool atEndOfLine() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { return m_tc.atBlockEnd() && m_tc.block().length() > 1; }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int lastPositionInDocument() const;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int firstPositionInLine(int line) const; // 1 based line, 0 based pos
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int lastPositionInLine(int line) const; // 1 based line, 0 based pos
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int lineForPosition(int pos) const;  // 1 based line, 0 based pos
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // all zero-based counting
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int cursorLineOnScreen() const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int linesOnScreen() const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int columnsOnScreen() const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int cursorLineInDocument() const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int cursorColumnInDocument() const;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int linesInDocument() const;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void scrollToLineInDocument(int line);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void scrollUp(int count);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void scrollDown(int count) { scrollUp(-count); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // helper functions for indenting
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 14:11:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool isElectricCharacter(QChar c) const
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        { return c == '{' || c == '}' || c == '#'; }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void indentRegion(QChar lastTyped = QChar());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void shiftRegionLeft(int repeat = 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void shiftRegionRight(int repeat = 1);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 15:41:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void setTargetColumn() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_targetColumn = leftDist();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "TARGET: " << m_targetColumn;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToNextWord(bool simple);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-13 12:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToMatchingParanthesis();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToWordBoundary(bool simple, bool forward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 14:11:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // to reduce line noise
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:51:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToEndOfDocument() { m_tc.movePosition(EndOfDocument, MoveAnchor); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveToEndOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void moveUp(int n = 1) { moveDown(-n); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void moveDown(int n = 1); // { m_tc.movePosition(Down, MoveAnchor, n); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:51:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void moveRight(int n = 1) { m_tc.movePosition(Right, MoveAnchor, n); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void moveLeft(int n = 1) { m_tc.movePosition(Left, MoveAnchor, n); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void setAnchor() { m_anchor = m_tc.position(); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void setAnchor(int position) { m_anchor = position; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void setPosition(int position) { m_tc.setPosition(position, MoveAnchor); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void handleFfTt(int key);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // helper function for handleExCommand. return 1 based line index.
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int readLineCode(QString &cmd);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void selectRange(int beginLine, int endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 17:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void enterExMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void showRedMessage(const QString &msg);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void showBlackMessage(const QString &msg);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void notImplementedYet();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 17:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:21:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QWidget *editor() const;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 14:36:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QChar characterAtCursor() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { return m_tc.document()->characterAt(m_tc.position()); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void beginEditBlock() { UNDO_DEBUG("BEGIN EDIT BLOCK"); m_tc.beginEditBlock(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void endEditBlock() { UNDO_DEBUG("END EDIT BLOCK"); m_tc.endEditBlock(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void joinPreviousEditBlock() { UNDO_DEBUG("JOIN EDIT BLOCK"); m_tc.joinPreviousEditBlock(); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // this asks the layer above (e.g. the fake vim plugin or the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // stand-alone test application to handle the command)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void passUnknownExCommand(const QString &cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextEdit *m_textedit;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QPlainTextEdit *m_plaintextedit;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool m_wasReadOnly; // saves read-only state of document
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    FakeVimHandler *q;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Mode m_mode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool m_passing; // let the core see the next event
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    SubMode m_submode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    SubSubMode m_subsubmode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int m_subsubdata;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString m_input;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextCursor m_tc;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextCursor m_oldTc; // copy from last event to check for external changes
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_anchor;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QHash<int, QString> m_registers;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int m_register;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString m_mvcount;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString m_opcount;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    MoveType m_moveType;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool m_fakeEnd;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool isSearchMode() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { return m_mode == SearchForwardMode || m_mode == SearchBackwardMode; }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_gflag;  // whether current command started with 'g'
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString m_commandBuffer;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString m_currentFileName;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString m_currentMessage;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:29:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool m_lastSearchForward;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString m_lastInsertion;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int anchor() const { return m_anchor; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int position() const { return m_tc.position(); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString selectedText() const;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // undo handling
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void undo();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void redo();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QMap<int, int> m_undoCursorPosition; // revision -> position
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // extra data for '.'
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void replay(const QString &text, int count);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void setDotCommand(const QString &cmd) { m_dotCommand = cmd; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void setDotCommand(const QString &cmd, int n) { m_dotCommand = cmd.arg(n); }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString m_dotCommand;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 14:52:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool m_inReplay; // true if we are executing a '.'
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:48:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // extra data for ';'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString m_semicolonCount;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int m_semicolonType;  // 'f', 'F', 't', 'T'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int m_semicolonKey;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // history for '/'
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString lastSearchString() const;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 15:31:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QStringList m_searchHistory;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_searchHistoryIndex;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // history for ':'
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 15:31:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QStringList m_commandHistory;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_commandHistoryIndex;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:28:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // visual line mode
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void enterVisualMode(VisualMode visualMode);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    VisualMode m_visualMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // marks as lines
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QHash<int, int> m_marks;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString m_oldNeedle;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:28:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // vi style configuration
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QVariant config(int code) const { return theFakeVimSetting(code)->value(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool hasConfig(int code) const { return config(code).toBool(); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool hasConfig(int code, const char *value) const // FIXME
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { return config(code).toString().contains(value); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // for restoring cursor position
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_savedYankPosition;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_targetColumn;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int m_cursorWidth;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // auto-indent
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    void insertAutomaticIndentation(bool goingDown);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool removeAutomaticIndentation(); // true if something removed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // number of autoindented characters
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int m_justAutoIndented;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    void recordNewUndo();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QList<int> m_jumpListUndo;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QList<int> m_jumpListRedo;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QList<QTextEdit::ExtraSelection> m_searchSelections;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 15:31:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QStringList FakeVimHandler::Private::m_searchHistory;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								QStringList FakeVimHandler::Private::m_commandHistory;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FakeVimHandler::Private::Private(FakeVimHandler *parent, QWidget *widget)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    q = parent;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_textedit = qobject_cast<QTextEdit *>(widget);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_plaintextedit = qobject_cast<QPlainTextEdit *>(widget);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    init();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::init()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_mode = CommandMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_passing = false;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_fakeEnd = false;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:29:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_lastSearchForward = true;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_register = '"';
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_gflag = false;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_visualMode = NoVisualMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_targetColumn = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_moveType = MoveInclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_anchor = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_savedYankPosition = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_cursorWidth = EDITOR(cursorWidth());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 14:52:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_inReplay = false;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_justAutoIndented = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								bool FakeVimHandler::Private::wantsOverride(QKeyEvent *ev)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const int key = ev->key();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const int mods = ev->modifiers();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    KEY_DEBUG("SHORTCUT OVERRIDE" << key << "  PASSING: " << m_passing);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (key == Key_Escape) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // Not sure this feels good. People often hit Esc several times
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_visualMode == NoVisualMode && m_mode == CommandMode)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // We are interested in overriding  most Ctrl key combinations
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (mods == Qt::ControlModifier && key >= Key_A && key <= Key_Z && key != Key_K) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Ctrl-K is special as it is the Core's default notion of QuickOpen
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_passing) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            KEY_DEBUG(" PASSING CTRL KEY");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // We get called twice on the same key
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            //m_passing = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return false;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 17:57:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG(" NOT PASSING CTRL KEY");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return true;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Let other shortcuts trigger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int key = ev->key();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const int um = key; // keep unmodified key around
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const int mods = ev->modifiers();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (key == Key_Shift || key == Key_Alt || key == Key_Control
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            || key == Key_Alt || key == Key_AltGr || key == Key_Meta)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG("PLAIN MODIFIER");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return EventUnhandled;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (m_passing) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG("PASSING PLAIN KEY..." << ev->key() << ev->text());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //if (key == ',') { // use ',,' to leave, too.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //    qDebug() << "FINISHED...";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //    return EventHandled;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_passing = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG("   PASS TO CORE");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return EventPassedToCore;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Fake "End of line"
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 18:29:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_tc.position() != m_oldTc.position())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.setVisualNavigation(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:50:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_fakeEnd)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if ((mods & Qt::ControlModifier) != 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        key += 256;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 16:20:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        key += 32; // make it lower case
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key >= Key_A && key <= Key_Z && (mods & Qt::ShiftModifier) == 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 16:20:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        key += 32;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 08:45:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_undoCursorPosition[m_tc.document()->revision()] = m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //if (m_mode == InsertMode)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //    joinPreviousEditBlock();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //    beginEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EventResult result = handleKey(key, um, ev->text());
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //endEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // We fake vi-style end-of-line behaviour
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_fakeEnd = (atEndOfLine() && m_mode == CommandMode);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:50:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_fakeEnd)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_oldTc = m_tc;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 18:29:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return result;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::installEventFilter()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(installEventFilter(q));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::setupWidget()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //EDITOR(setCursorWidth(QFontMetrics(ed->font()).width(QChar('x')));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_textedit) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_textedit->setLineWrapMode(QTextEdit::NoWrap);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_plaintextedit) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_plaintextedit->setLineWrapMode(QPlainTextEdit::NoWrap);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_wasReadOnly = EDITOR(isReadOnly());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //EDITOR(setReadOnly(true));
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextCursor tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (tc.hasSelection()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int pos = tc.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int anc = tc.anchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_marks['<'] = anc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_marks['>'] = pos;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_anchor = anc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_visualMode = VisualCharMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        tc.clearSelection();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setTextCursor(tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc = tc; // needed in updateSelection
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateSelection();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //showBlackMessage("vi emulation mode. Type :q to leave. Use , Ctrl-R to trigger run.");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::restoreWidget()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //showBlackMessage(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //EDITOR(removeEventFilter(q));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setReadOnly(m_wasReadOnly));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setCursorWidth(m_cursorWidth));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setOverwriteMode(false));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_visualMode == VisualLineMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int beginLine = lineForPosition(m_marks['<']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int endLine = lineForPosition(m_marks['>']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(firstPositionInLine(beginLine), MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(lastPositionInLine(endLine), KeepAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_visualMode == VisualCharMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_marks['<'], MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_marks['>'], KeepAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_visualMode = NoVisualMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								EventResult FakeVimHandler::Private::handleKey(int key, int unmodified,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const QString &text)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "KEY: " << key << text << "POS: " << m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (m_mode == InsertMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return handleInsertMode(key, unmodified, text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_mode == CommandMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return handleCommandMode(key, unmodified, text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_mode == ExMode || m_mode == SearchForwardMode
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            || m_mode == SearchBackwardMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return handleMiniBufferModes(key, unmodified, text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return EventUnhandled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveDown(int n)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 13:48:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#if 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // does not work for "hidden" documents like in the autotests
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.movePosition(Down, MoveAnchor, n);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 15:44:51 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const int col = m_tc.position() - m_tc.block().position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 11:52:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const int lastLine = m_tc.document()->lastBlock().blockNumber();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const int targetLine = qMax(0, qMin(lastLine, m_tc.block().blockNumber() + n));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const QTextBlock &block = m_tc.document()->findBlockByNumber(targetLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 15:44:51 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const int pos = block.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setPosition(pos + qMin(block.length() - 1, col));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    moveToTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 13:48:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToEndOfLine()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 13:48:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#if 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // does not work for "hidden" documents like in the autotests
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.movePosition(EndOfLine, MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const QTextBlock &block = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setPosition(block.position() + block.length() - 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 13:48:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToStartOfLine()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#if 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // does not work for "hidden" documents like in the autotests
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.movePosition(StartOfLine, MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const QTextBlock &block = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setPosition(block.position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "ANCHOR: " << position() << anchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_submode == FilterSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int beginLine = lineForPosition(anchor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int endLine = lineForPosition(position());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(qMin(anchor(), position()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterExMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-08 09:30:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_currentMessage.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer = QString(".,+%1!").arg(qAbs(endLine - beginLine));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistory.append(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistoryIndex = m_commandHistory.size() - 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:42:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_visualMode != NoVisualMode)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_marks['>'] = m_tc.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (m_submode == ChangeSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_moveType == MoveInclusive)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveRight(); // correction
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:48:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (anchor() >= position())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           m_anchor++;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!dotCommand.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setDotCommand("c" + dotCommand);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString text = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "CHANGING TO INSERT MODE" << text;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = text;
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-04 16:07:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == DeleteSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_moveType == MoveInclusive)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveRight(); // correction
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:48:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (anchor() >= position())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           m_anchor++;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!dotCommand.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setDotCommand("d" + dotCommand);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 15:41:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == YankSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = selectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(m_savedYankPosition);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:19:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ReplaceSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == IndentSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        indentRegion();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ShiftRightSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        shiftRegionRight(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ShiftLeftSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        shiftRegionLeft(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:40:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_moveType = MoveInclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_mvcount.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_opcount.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_gflag = false;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_register = '"';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.clearSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::updateSelection()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QList<QTextEdit::ExtraSelection> selections = m_searchSelections;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_visualMode != NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QTextEdit::ExtraSelection sel;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sel.cursor = m_tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sel.format = m_tc.blockCharFormat();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#if 0
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sel.format.setFontWeight(QFont::Bold);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sel.format.setFontUnderline(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#else
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sel.format.setForeground(Qt::white);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        sel.format.setBackground(Qt::black);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#endif
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int cursorPos = m_tc.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int anchorPos = m_marks['<'];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "POS: " << cursorPos << " ANCHOR: " << anchorPos;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_visualMode == VisualCharMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sel.cursor.setPosition(anchorPos, KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            selections.append(sel);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (m_visualMode == VisualLineMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sel.cursor.setPosition(qMin(cursorPos, anchorPos), MoveAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sel.cursor.movePosition(StartOfLine, MoveAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sel.cursor.setPosition(qMax(cursorPos, anchorPos), KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            sel.cursor.movePosition(EndOfLine, KeepAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            selections.append(sel);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (m_visualMode == VisualBlockMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            QTextCursor tc = m_tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            tc.setPosition(anchorPos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            tc.movePosition(StartOfLine, MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QTextBlock anchorBlock = tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QTextBlock cursorBlock = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int anchorColumn = anchorPos - anchorBlock.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int cursorColumn = cursorPos - cursorBlock.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int startColumn = qMin(anchorColumn, cursorColumn);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int endColumn = qMax(anchorColumn, cursorColumn);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int endPos = cursorBlock.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            while (tc.position() <= endPos) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (startColumn < tc.block().length() - 1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    int last = qMin(tc.block().length() - 1, endColumn);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    int len = last - startColumn + 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    sel.cursor = tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    sel.cursor.movePosition(Right, MoveAnchor, startColumn);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    sel.cursor.movePosition(Right, KeepAnchor, len);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    selections.append(sel);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                tc.movePosition(Down, MoveAnchor, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "SELECTION: " << selections;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    emit q->selectionChanged(selections);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::updateMiniBuffer()
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString msg;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_passing) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        msg = "-- PASSING --  ";
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (!m_currentMessage.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        msg = m_currentMessage;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_mode == CommandMode && m_visualMode != NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_visualMode == VisualCharMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = "-- VISUAL --";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (m_visualMode == VisualLineMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = "-- VISUAL LINE --";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (m_visualMode == VisualBlockMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = "-- VISUAL BLOCK --";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:49:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_mode == InsertMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-04 09:35:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == ReplaceSubMode)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = "-- REPLACE --";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            msg = "-- INSERT --";
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_mode == SearchForwardMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            msg += '/';
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        else if (m_mode == SearchBackwardMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            msg += '?';
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        else if (m_mode == ExMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            msg += ':';
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        foreach (QChar c, m_commandBuffer) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (c.unicode() < 32) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                msg += '^';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                msg += QChar(c.unicode() + 64);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                msg += c;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:41:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!msg.isEmpty() && m_mode != CommandMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            msg += QChar(10073); // '|'; // FIXME: Use a real "cursor"
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:41:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:05:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    emit q->commandBufferChanged(msg);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int linesInDoc = linesInDocument();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int l = cursorLineInDocument();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString status;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString pos = tr("%1,%2").arg(l + 1).arg(cursorColumnInDocument() + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:05:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    status += tr("%1").arg(pos, -10);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // FIXME: physical "-" logical
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (linesInDoc != 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:05:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        status += tr("%1").arg(l * 100 / linesInDoc, 4);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        status += "%";
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:05:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        status += "All";
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:05:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    emit q->statusDataChanged(status);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::showRedMessage(const QString &msg)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "MSG: " << msg;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_currentMessage = msg;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::showBlackMessage(const QString &msg)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "MSG: " << msg;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_commandBuffer = msg;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::notImplementedYet()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 13:36:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    qDebug() << "Not implemented in FakeVim";
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-17 21:11:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    showRedMessage(tr("Not implemented in FakeVim"));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const QString &text)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EventResult handled = EventHandled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 13:55:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 16:33:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_submode == WindowSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        emit q->windowCommandRequested(key);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == RegisterSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_register = key;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ChangeSubMode && key == 'c') { // tested
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() - 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveUp(count() - 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:01:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1cc", count());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == DeleteSubMode && key == 'd') { // tested
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-29 15:29:03 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn(); 
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:01:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-29 15:29:03 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1dd", count());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == YankSubMode && key == 'y') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement("y");
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ShiftLeftSubMode && key == '<') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() - 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1<<", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ShiftRightSubMode && key == '>') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() - 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1>>", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == IndentSubMode && key == '=') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() - 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 08:46:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1==", count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:19:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ZSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "Z_MODE " << cursorLineInDocument() << linesOnScreen();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (key == Key_Return || key == 't') { // cursor line to top of window
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!m_mvcount.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                setPosition(firstPositionInLine(count()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            scrollUp(- cursorLineOnScreen());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (key == Key_Return)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (key == '.' || key == 'z') { // cursor line to center of window
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!m_mvcount.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                setPosition(firstPositionInLine(count()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            scrollUp(linesOnScreen() / 2 - cursorLineOnScreen());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (key == '.')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:11:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (key == '-' || key == 'b') { // cursor line to bottom of window
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!m_mvcount.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                setPosition(firstPositionInLine(count()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            scrollUp(linesOnScreen() - cursorLineOnScreen());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:44:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (key == '-')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 12:29:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 13:20:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            qDebug() << "IGNORED Z_MODE " << key << text;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == CapitalZSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // Recognize ZZ and ZQ as aliases for ":x" and ":q!".
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (key == 'Z')
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 11:34:11 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            handleCommand("x");
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        else if (key == 'Q')
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 11:34:11 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            handleCommand("q!");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_subsubmode == FtSubSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:48:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_semicolonType = m_subsubdata;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_semicolonKey = key;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleFfTt(key);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 14:56:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement(QString("%1%2%3")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .arg(count())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .arg(QChar(m_semicolonType))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .arg(QChar(m_semicolonKey)));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:08:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_submode == ReplaceSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 15:08:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (count() <= (rightDist() + atEndOfLine()) && text.size() == 1
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 14:19:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                && (text.at(0).isPrint() || text.at(0).isSpace())) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 15:08:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (atEndOfLine())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 14:19:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveRight(count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 15:08:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            QString rem = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_tc.insertText(QString(count(), text.at(0)));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 14:19:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setDotCommand("%1r" + text, count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 14:19:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 15:08:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (m_subsubmode == MarkSubSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_marks[key] = m_tc.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (m_subsubmode == BackTickSubSubMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            || m_subsubmode == TickSubSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_marks.contains(key)) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setPosition(m_marks[key]);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (m_subsubmode == TickSubSubMode)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveToFirstNonBlankOnLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("E20: Mark '%1' not set").arg(text));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key >= '0' && key <= '9') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (key == '0' && m_mvcount.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 16:07:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:41:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_mvcount.append(QChar(key));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 16:07:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '^') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToFirstNonBlankOnLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:48:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (0 && key == ',') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: fakevim uses ',' by itself, so it is incompatible
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // HACK: toggle 'f' <-> 'F', 't' <-> 'T'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = m_semicolonType ^ 32;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        handleFfTt(m_semicolonKey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == ';') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = m_semicolonType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        handleFfTt(m_semicolonKey);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == ':') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterExMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-08 09:30:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_currentMessage.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:42:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_visualMode != NoVisualMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_commandBuffer = "'<,'>";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistory.append(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistoryIndex = m_commandHistory.size() - 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '/' || key == '?') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 11:56:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (hasConfig(ConfigIncSearch)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // re-use the core dialog.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            emit q->findRequested(key == '?');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // FIXME: make core find dialog sufficiently flexible to
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // produce the "default vi" behaviour too. For now, roll our own.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            enterExMode(); // to get the cursor disabled
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-08 09:30:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_currentMessage.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 11:56:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_mode = (key == '/') ? SearchForwardMode : SearchBackwardMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_commandBuffer.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_searchHistory.append(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_searchHistoryIndex = m_searchHistory.size() - 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '`') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = BackTickSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '#' || key == '*') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: That's not proper vim behaviour
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.select(QTextCursor::WordUnderCursor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString needle = "\\<" + m_tc.selection().toPlainText() + "\\>";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_searchHistory.append(needle);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_lastSearchForward = (key == '*');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        search(needle, m_lastSearchForward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '\'') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = TickSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '|') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(count(), rightDist()) - 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '!' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = FilterSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '!' && m_visualMode != NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterExMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-08 09:30:32 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_currentMessage.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer = "'<,'>!";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistory.append(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandHistoryIndex = m_commandHistory.size() - 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '"') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = RegisterSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (unmodified == Key_Return) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-13 14:02:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:04:13 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '-') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveUp();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToFirstNonBlankOnLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Home) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '$' || key == Key_End) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 18:35:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int submode = m_submode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 02:13:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 18:35:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (submode == NoSubMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_targetColumn = -1;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-07 17:13:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == ',') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: use some other mechanism
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //m_passing = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_passing = !m_passing;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:51:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '.') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:09:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        qDebug() << "REPEATING" << quoteUnprintable(m_dotCommand);
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 22:43:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString savedCommand = m_dotCommand;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_dotCommand.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        replay(savedCommand, count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 14:08:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterCommandMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_dotCommand = savedCommand;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '<' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = ShiftLeftSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '<' && m_visualMode != NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        shiftRegionLeft(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '>' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = ShiftRightSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '>' && m_visualMode != NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        shiftRegionRight(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '=' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = IndentSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '=' && m_visualMode != NoVisualMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        indentRegion();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 10:43:28 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '%') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:48:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-13 12:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToMatchingParanthesis();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 10:43:28 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:51:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'a') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-04 16:07:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:51:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!atEndOfLine())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveRight();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:49:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'A') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-04 16:07:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:22:37 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("A");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:51:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-17 14:58:01 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('a')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: eat it to prevent the global "select all" shortcut to trigger
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'b') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToWordBoundary(false, false);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'B') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToWordBoundary(true, false);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 11:58:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'c' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = ChangeSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'c' && m_visualMode == VisualCharMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 11:58:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = ChangeSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'C') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-04 16:07:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:09:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("C");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 10:53:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('c')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage("Type Alt-v,Alt-v  to quit FakeVim mode");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'd' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_opcount = m_mvcount;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_mvcount.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = DeleteSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == 'd' || key == 'x') && m_visualMode == VisualCharMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-16 11:17:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = DeleteSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 11:58:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == 'd' || key == 'x') && m_visualMode == VisualLineMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int beginLine = lineForPosition(m_marks['<']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int endLine = lineForPosition(m_marks['>']);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        selectRange(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'D') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = DeleteSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(qMax(count() - 1, 0));
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 02:13:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-12 11:43:51 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("D");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('d')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int sline = cursorLineOnScreen();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: this should use the "scroll" option, and "count"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(linesOnScreen() / 2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        scrollToLineInDocument(cursorLineInDocument() - sline);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'e') { // tested
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveInclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToWordBoundary(false, true);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'E') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveInclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToWordBoundary(true, true);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('e')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: this should use the "scroll" option, and "count"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (cursorLineOnScreen() == 0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveDown(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        scrollDown(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 15:04:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'f') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 15:04:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveInclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = key;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'F') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = key;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'g') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 21:35:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_gflag) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_gflag = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_tc.setPosition(firstPositionInLine(1), KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 21:35:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_gflag = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:28:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'G') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int n = m_mvcount.isEmpty() ? linesInDocument() : count();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(firstPositionInLine(n), KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:28:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'h' || key == Key_Left
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            || key == Key_Backspace || key == control('h')) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int n = qMin(count(), leftDist());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_fakeEnd && m_tc.block().length() > 1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ++n;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveLeft(n);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:50:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("h");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'H') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 18:29:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(cursorForPosition(QPoint(0, 0)));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(qMax(count() - 1, 0));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-04 09:35:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'i' || key == Key_Insert) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("i"); // setDotCommand("%1i", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:49:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:44:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'I') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("I"); // setDotCommand("%1I", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:49:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_gflag)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:49:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 23:39:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.clearSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('i')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!m_jumpListRedo.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_jumpListUndo.append(position());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setPosition(m_jumpListRedo.takeLast());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'j' || key == Key_Down) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 13:10:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == NoSubMode || m_submode == ZSubMode
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                || m_submode == CapitalZSubMode || m_submode == RegisterSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveDown(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 22:03:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 22:04:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 22:04:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveDown(count() + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 22:03:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:50:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("j");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'J') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == NoSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (int i = qMax(count(), 2) - 1; --i >= 0; ) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                moveRight();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 14:36:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                while (characterAtCursor() == ' ')
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    moveRight();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:50:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                if (!m_gflag)
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    m_tc.insertText(" ");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:50:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (!m_gflag)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 13:39:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'k' || key == Key_Up) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == NoSubMode || m_submode == ZSubMode
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                || m_submode == CapitalZSubMode || m_submode == RegisterSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveUp(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 22:03:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 22:04:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveLineWise;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveDown();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-01 22:04:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveUp(count() + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 22:03:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:50:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("k");
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 17:10:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'l' || key == Key_Right || key == ' ') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:35:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(count(), rightDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-17 00:50:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("l");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:43:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'L') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:50:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()))));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveUp(qMax(count(), 1));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:43:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('l')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // screen redraw. should not be needed
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'm') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = MarkSubSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 15:00:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'M') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:50:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(cursorForPosition(QPoint(0, EDITOR(height()) / 2)));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 15:00:06 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 11:56:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'n') { // FIXME: see comment for '/'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (hasConfig(ConfigIncSearch))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            emit q->findNextRequested(false);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            search(lastSearchString(), m_lastSearchForward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'N') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 11:56:58 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (hasConfig(ConfigIncSearch))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            emit q->findNextRequested(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            search(lastSearchString(), !m_lastSearchForward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'o' || key == 'O') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1o", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 09:46:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (key == 'O')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveUp();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToEndOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText("\n");
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        insertAutomaticIndentation(key == 'o');
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('o')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!m_jumpListUndo.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_jumpListRedo.append(position());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setPosition(m_jumpListUndo.takeLast());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:43:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'p' || key == 'P') {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString text = m_registers[m_register];
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 17:09:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int n = text.count(QChar('\n'));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "REGISTERS: " << m_registers << "MOVE: " << m_moveType;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "LINES: " << n << text << m_register;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (n > 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_targetColumn = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:38:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (int i = count(); --i >= 0; ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (key == 'p')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    moveDown();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                m_tc.insertText(text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:38:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                moveUp(n);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-02 12:04:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_targetColumn = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:38:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            for (int i = count(); --i >= 0; ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (key == 'p')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    moveRight();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                m_tc.insertText(text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:38:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                moveLeft();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1p", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:38:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:19:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'r') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:08:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = ReplaceSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("r");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'R') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // FIXME: right now we repeat the insertion count() times,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:08:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // but not the deletion
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-04 16:07:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = ReplaceSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("R");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('r')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        redo();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 's') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:52:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 09:46:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(count(), rightDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("s"); // setDotCommand("%1s", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 09:46:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_opcount.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_mvcount.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        enterInsertMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 15:04:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 't') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveInclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = key;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'T') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_subsubmode = FtSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_subsubdata = key;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'u') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        undo();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('u')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int sline = cursorLineOnScreen();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME: this should use the "scroll" option, and "count"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveUp(linesOnScreen() / 2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        scrollToLineInDocument(cursorLineInDocument() - sline);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'v') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        enterVisualMode(VisualCharMode);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'V') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterVisualMode(VisualLineMode);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('v')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        enterVisualMode(VisualBlockMode);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'w') { // tested
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:42:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // Special case: "cw" and "cW" work the same as "ce" and "cE" if the
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // cursor is on a non-blank.
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == ChangeSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:42:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToWordBoundary(false, true);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveInclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:42:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveToNextWord(false);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:42:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveExclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("w");
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'W') {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:48:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == ChangeSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveToWordBoundary(true, true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveInclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveToNextWord(true);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_moveType = MoveExclusive;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement("W");
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 16:33:28 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == control('w')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = WindowSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-16 09:06:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'x' && m_visualMode == NoVisualMode) { // = "dl"
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 18:35:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveExclusive;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 15:15:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = DeleteSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(count(), rightDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setDotCommand("%1x", count());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 14:08:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'X') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (leftDist() > 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            moveLeft(qMin(count(), leftDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_registers[m_register] = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'y' && m_visualMode == NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_savedYankPosition = m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = YankSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'y' && m_visualMode == VisualLineMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int beginLine = lineForPosition(m_marks['<']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int endLine = lineForPosition(m_marks['>']);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        selectRange(beginLine, endLine);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_registers[m_register] = selectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(qMin(position(), anchor()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:38:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'Y') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToStartOfLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveDown(count());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_moveType = MoveLineWise;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 16:20:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'z') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = ZSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == 'Z') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_submode = CapitalZSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == '~' && !atEndOfLine()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(count(), rightDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString str = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:22:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int i = str.size(); --i >= 0; ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QChar c = str.at(i);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            str[i] = c.isUpper() ? c.toLower() : c.toUpper();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText(str);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_PageDown || key == control('f')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 15:17:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() * (linesOnScreen() - 2) - cursorLineOnScreen());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        scrollToLineInDocument(cursorLineInDocument());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_PageUp || key == control('b')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 15:17:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveUp(count() * (linesOnScreen() - 2) + cursorLineOnScreen());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        scrollToLineInDocument(cursorLineInDocument() + linesOnScreen() - 2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handleStartOfLine();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        finishMovement();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 13:59:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Delete) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-22 13:44:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setAnchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveRight(qMin(1, rightDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:57:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Escape) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 23:29:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_visualMode != NoVisualMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 23:29:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (m_submode != NoSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_subsubmode = NoSubSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            finishMovement();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-16 09:06:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        qDebug() << "IGNORED IN COMMAND MODE: " << key << text
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            << " VISUAL: " << m_visualMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        handled = EventUnhandled;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 22:28:46 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return handled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const QString &text)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 10:48:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (key == Key_Escape || key == 27 || key == control('c')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // start with '1', as one instance was already physically inserted
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // while typing
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString data = m_lastInsertion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (int i = 1; i < count(); ++i) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_tc.insertText(m_lastInsertion);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            data += m_lastInsertion;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveLeft(qMin(1, leftDist()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-16 22:43:19 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_dotCommand += m_lastInsertion;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 17:25:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_dotCommand += QChar(27);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        recordNewUndo();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-04 09:35:46 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Insert) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == ReplaceSubMode) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            EDITOR(setCursorWidth(m_cursorWidth));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            EDITOR(setOverwriteMode(false));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            EDITOR(setCursorWidth(m_cursorWidth));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            EDITOR(setOverwriteMode(true));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_submode = ReplaceSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Left) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveLeft(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Down) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        removeAutomaticIndentation();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Up) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        removeAutomaticIndentation();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveUp(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Right) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight(count());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Return) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_submode = NoSubMode;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion += "\n";
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        insertAutomaticIndentation(true);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 15:15:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Backspace || key == control('h')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!removeAutomaticIndentation()) 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!m_lastInsertion.isEmpty() || hasConfig(ConfigBackspace, "start")) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                m_tc.deletePreviousChar();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                m_lastInsertion.chop(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 13:59:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Delete) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.deleteChar();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_PageDown || key == control('f')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        removeAutomaticIndentation();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveDown(count() * (linesOnScreen() - 2));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_PageUp || key == control('b')) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        removeAutomaticIndentation();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveUp(count() * (linesOnScreen() - 2));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 17:55:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Tab && hasConfig(ConfigExpandTab)) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString str = QString(theFakeVimSetting(ConfigTabStop)->value().toInt(), ' ');
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 17:31:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.append(str);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText(str);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 16:44:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key >= control('a') && key <= control('z')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // ignore these
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (!text.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 12:24:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_lastInsertion.append(text);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_submode == ReplaceSubMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 10:13:12 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (atEndOfLine())
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 14:31:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                m_submode = NoSubMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                m_tc.deleteChar();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 13:55:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText(text);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 17:55:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (0 && hasConfig(ConfigAutoIndent) && isElectricCharacter(text.at(0))) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            const QString leftText = m_tc.block().text()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                .left(m_tc.position() - 1 - m_tc.block().position());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (leftText.simplified().isEmpty())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                indentRegion(text.at(0));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!m_inReplay)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-25 13:31:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            emit q->completionRequested();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return EventUnhandled;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:49:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return EventHandled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								EventResult FakeVimHandler::Private::handleMiniBufferModes(int key, int unmodified,
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const QString &text)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 13:55:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Q_UNUSED(text)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 10:48:12 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (key == Key_Escape || key == control('c')) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Backspace) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 17:55:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_commandBuffer.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 17:55:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_commandBuffer.chop(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-19 17:55:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Left) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // FIXME:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!m_commandBuffer.isEmpty())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_commandBuffer.chop(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (unmodified == Key_Return && m_mode == ExMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!m_commandBuffer.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_commandHistory.takeLast();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_commandHistory.append(m_commandBuffer);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            handleExCommand(m_commandBuffer);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:42:10 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 16:57:11 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (unmodified == Key_Return && isSearchMode()) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!m_commandBuffer.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_searchHistory.takeLast();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_searchHistory.append(m_commandBuffer);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_lastSearchForward = (m_mode == SearchForwardMode);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            search(lastSearchString(), m_lastSearchForward);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            recordJump();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        enterCommandMode();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 15:59:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == Key_Up || key == Key_PageUp) && isSearchMode()) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 03:07:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // FIXME: This and the three cases below are wrong as vim
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-10 15:31:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // takes only matching entries in the history into account.
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_searchHistoryIndex > 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            --m_searchHistoryIndex;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(m_searchHistory.at(m_searchHistoryIndex));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 15:59:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == Key_Up || key == Key_PageUp) && m_mode == ExMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_commandHistoryIndex > 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            --m_commandHistoryIndex;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(m_commandHistory.at(m_commandHistoryIndex));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 15:59:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == Key_Down || key == Key_PageDown) && isSearchMode()) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_searchHistoryIndex < m_searchHistory.size() - 1) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            ++m_searchHistoryIndex;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(m_searchHistory.at(m_searchHistoryIndex));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 15:59:20 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if ((key == Key_Down || key == Key_PageDown) && m_mode == ExMode) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_commandHistoryIndex < m_commandHistory.size() - 1) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 00:32:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            ++m_commandHistoryIndex;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(m_commandHistory.at(m_commandHistoryIndex));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 22:41:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (key == Key_Tab) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer += QChar(9);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 16:32:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (QChar(key).isPrint()) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_commandBuffer += QChar(key);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 16:32:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        qDebug() << "IGNORED IN MINIBUFFER MODE: " << key << text;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return EventUnhandled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return EventHandled;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								// 1 based.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::readLineCode(QString &cmd)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "CMD: " << cmd;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (cmd.isEmpty())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QChar c = cmd.at(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    cmd = cmd.mid(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (c == '.')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return cursorLineInDocument() + 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (c == '$')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return linesInDocument();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-29 14:47:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (c == '\'' && !cmd.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int mark = m_marks.value(cmd.at(0).unicode());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!mark) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-23 21:34:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            cmd = cmd.mid(1);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-29 14:47:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            return -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        cmd = cmd.mid(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 14:19:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return lineForPosition(mark);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-29 14:47:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (c == '-') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int n = readLineCode(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return cursorLineInDocument() + 1 - (n == -1 ? 1 : n);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (c == '+') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int n = readLineCode(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return cursorLineInDocument() + 1 + (n == -1 ? 1 : n);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (c == '\'' && !cmd.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int pos = m_marks.value(cmd.at(0).unicode(), -1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (pos == -1) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            cmd = cmd.mid(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            return -1;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        cmd = cmd.mid(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return lineForPosition(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (c.isDigit()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int n = c.unicode() - '0';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        while (!cmd.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            c = cmd.at(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!c.isDigit())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            cmd = cmd.mid(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            n = n * 10 + (c.unicode() - '0');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "N: " << n;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return n;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // not parsed
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    cmd = c + cmd;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return -1;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::selectRange(int beginLine, int endLine)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (beginLine == -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        beginLine = cursorLineInDocument();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (endLine == -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        endLine = cursorLineInDocument();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (beginLine > endLine)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        qSwap(beginLine, endLine);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setAnchor(firstPositionInLine(beginLine));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (endLine == linesInDocument())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       setPosition(lastPositionInLine(endLine));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								       setPosition(firstPositionInLine(endLine + 1));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::handleCommand(const QString &cmd)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    handleExCommand(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString cmd = cmd0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-14 17:02:30 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (cmd.startsWith(QLatin1Char('%')))
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        cmd = "1,$" + cmd.mid(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:52:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:37:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int beginLine = -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int endLine = -1;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int line = readLineCode(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (line != -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        beginLine = line;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 13:16:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (cmd.startsWith(',')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        cmd = cmd.mid(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        line = readLineCode(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (line != -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            endLine = line;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0 << m_marks;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reQuit("^qa?!?$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reDelete("^d( (.*))?$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reHistory("^his(tory)?( (.*))?$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reNormal("^norm(al)?( (.*))?$");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reSet("^set?( (.*))?$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reWrite("^[wx]q?a?!?( (.*))?$");
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-11 08:52:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    static QRegExp reSubstitute("^s(.)(.*)\\1(.*)\\1([gi]*)");
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    enterCommandMode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    showBlackMessage(QString());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (cmd.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(firstPositionInLine(beginLine));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(QString());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (reDelete.indexIn(cmd) != -1) { // :d
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        selectRange(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString reg = reDelete.cap(2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString text = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (!reg.isEmpty())
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_registers[reg.at(0).unicode()] = text;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (reWrite.indexIn(cmd) != -1) { // :w and :x
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        bool noArgs = (beginLine == -1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (beginLine == -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            beginLine = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (endLine == -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            endLine = linesInDocument();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "LINES: " << beginLine << endLine;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int indexOfSpace = cmd.indexOf(QChar(' '));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString prefix;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (indexOfSpace < 0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            prefix = cmd;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            prefix = cmd.left(indexOfSpace);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool forced = prefix.contains(QChar('!'));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool quit = prefix.contains(QChar('q')) || prefix.contains(QChar('x'));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool quitAll = quit && prefix.contains(QChar('a'));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString fileName = reWrite.cap(2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (fileName.isEmpty())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            fileName = m_currentFileName;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QFile file1(fileName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        bool exists = file1.exists();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:51:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (exists && !forced && !noArgs) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("File '%1' exists (add ! to override)").arg(fileName));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (file1.open(QIODevice::ReadWrite)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            file1.close();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:48:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            QTextCursor tc = m_tc;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            selectRange(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:14:10 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            QString contents = selectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 10:48:37 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_tc = tc;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            qDebug() << "LINES: " << beginLine << endLine;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            bool handled = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            emit q->writeFileRequested(&handled, fileName, contents);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // nobody cared, so act ourselves
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (!handled) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                //qDebug() << "HANDLING MANUAL SAVE TO " << fileName;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                QFile::remove(fileName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                QFile file2(fileName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (file2.open(QIODevice::ReadWrite)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    QTextStream ts(&file2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    ts << contents;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    showRedMessage(tr("Cannot open file '%1' for writing").arg(fileName));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // check result by reading back
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            QFile file3(fileName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            file3.open(QIODevice::ReadOnly);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QByteArray ba = file3.readAll();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(tr("\"%1\" %2 %3L, %4C written")
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 19:47:29 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                .arg(fileName).arg(exists ? " " : " [New] ")
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                .arg(ba.count('\n')).arg(ba.size()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (quitAll)
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                passUnknownExCommand(forced ? "qa!" : "qa");
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 08:34:06 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            else if (quit)
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                passUnknownExCommand(forced ? "q!" : "q");
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("Cannot open file '%1' for reading").arg(fileName));
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 19:47:29 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (cmd.startsWith("r ")) { // :r
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 01:02:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_currentFileName = cmd.mid(2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QFile file(m_currentFileName);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        file.open(QIODevice::ReadOnly);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QTextStream ts(&file);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString data = ts.readAll();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setPlainText(data));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(tr("\"%1\" %2L, %3C")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .arg(m_currentFileName).arg(data.count('\n')).arg(data.size()));
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-14 17:02:30 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (cmd.startsWith(QLatin1Char('!'))) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        selectRange(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString command = cmd.mid(1).trimmed();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString text = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QProcess proc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        proc.start(cmd.mid(1));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        proc.waitForStarted();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        proc.write(text.toUtf8());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        proc.closeWriteChannel();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        proc.waitForFinished();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString result = QString::fromUtf8(proc.readAllStandardOutput());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText(result);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(firstPositionInLine(beginLine));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "FILTER: " << command;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-14 17:02:30 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(tr("%n lines filtered", 0, text.count('\n')));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (cmd.startsWith(QLatin1Char('>'))) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_anchor = firstPositionInLine(beginLine);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setPosition(firstPositionInLine(endLine));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        shiftRegionRight(1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        leaveVisualMode();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-14 17:02:30 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(tr("%n lines >ed %1 time", 0, (endLine - beginLine + 1)).arg(1));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:21:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (cmd == "red" || cmd == "redo") { // :redo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        redo();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (reNormal.indexIn(cmd) != -1) { // :normal
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "REPLAY: " << reNormal.cap(3);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        replay(reNormal.cap(3), 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-11 08:52:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (reSubstitute.indexIn(cmd) != -1) { // :substitute
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString needle = reSubstitute.cap(2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const QString replacement = reSubstitute.cap(3);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString flags = reSubstitute.cap(4);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const bool startOfLineOnly = needle.startsWith('^');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (startOfLineOnly)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								           needle.remove(0, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        needle.replace('$', '\n');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        needle.replace("\\\n", "\\$");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QRegExp pattern(needle);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (flags.contains('i'))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            pattern.setCaseSensitivity(Qt::CaseInsensitive);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const bool global = flags.contains('g');
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        beginEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-11 08:52:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for (int line = beginLine; line <= endLine; ++line) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            const int start = firstPositionInLine(line);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            const int end = lastPositionInLine(line);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            for (int position = start; position <= end && position >= start; ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                position = pattern.indexIn(m_tc.document()->toPlainText(), position);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (startOfLineOnly && position != start)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (position != -1) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    m_tc.setPosition(position);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    m_tc.movePosition(QTextCursor::NextCharacter,
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-14 15:22:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                        KeepAnchor, pattern.matchedLength());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-11 08:52:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    QString text = m_tc.selectedText();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    if (text.endsWith(ParagraphSeparator)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        text = replacement + "\n";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        text.replace(ParagraphSeparator, "\n");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        text.replace(pattern, replacement);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    m_tc.removeSelectedText();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    m_tc.insertText(text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if (!global)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        endEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 15:36:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else if (reSet.indexIn(cmd) != -1) { // :set
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-31 11:44:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(QString());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 15:36:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QString arg = reSet.cap(2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        SavedAction *act = theFakeVimSettings()->item(arg);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 15:36:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (arg.isEmpty()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            theFakeVimSetting(SettingsDialog)->trigger(QVariant());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (act && act->value().type() == QVariant::Bool) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // boolean config to be switched on
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            bool oldValue = act->value().toBool();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (oldValue == false)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                act->setValue(true);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            else if (oldValue == true)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                {} // nothing to do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (act) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // non-boolean to show
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            showBlackMessage(arg + '=' + act->value().toString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else if (arg.startsWith("no")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                && (act = theFakeVimSettings()->item(arg.mid(2)))) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 13:36:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            // boolean config to be switched off
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            bool oldValue = act->value().toBool();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (oldValue == true)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                act->setValue(false);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            else if (oldValue == false)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                {} // nothing to do
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 13:36:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else if (arg.contains('=')) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            // non-boolean config to set
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int p = arg.indexOf('=');
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 15:27:59 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            act = theFakeVimSettings()->item(arg.left(p));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (act)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                act->setValue(arg.mid(p + 1));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 13:36:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("E512: Unknown option: ") + arg);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } else if (reHistory.indexIn(cmd) != -1) { // :history
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString arg = reSet.cap(3);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (arg.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QString info;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            info += "#  command history\n";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            int i = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            foreach (const QString &item, m_commandHistory) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                ++i;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                info += QString("%1 %2\n").arg(i, -8).arg(item);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            emit q->extraInformationChanged(info);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            notImplementedYet();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 15:36:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 17:57:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        passUnknownExCommand(cmd);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::passUnknownExCommand(const QString &cmd)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    emit q->handleExCommandRequested(cmd);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static void vimPatternToQtPattern(QString *needle, QTextDocument::FindFlags *flags)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // FIXME: Rough mapping of a common case
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (needle->startsWith("\\<") && needle->endsWith("\\>"))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        (*flags) |= QTextDocument::FindWholeWords;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    needle->replace("\\<", ""); // start of word
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    needle->replace("\\>", ""); // end of word
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "NEEDLE " << needle0 << needle;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::search(const QString &needle0, bool forward)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 17:44:24 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    showBlackMessage((forward ? '/' : '?') + needle0);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 13:20:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextCursor orig = m_tc;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextDocument::FindFlags flags = QTextDocument::FindCaseSensitively;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!forward)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        flags |= QTextDocument::FindBackward;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString needle = needle0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    vimPatternToQtPattern(&needle, &flags);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (forward)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 13:20:09 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.movePosition(Right, MoveAnchor, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 13:23:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int oldLine = cursorLineInDocument() - cursorLineOnScreen();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 18:29:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (EDITOR(find(needle, flags))) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc = EDITOR(textCursor());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 09:56:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_tc.anchor());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // making this unconditional feels better, but is not "vim like"
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-27 13:23:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (oldLine != cursorLineInDocument() - cursorLineOnScreen())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        highlightMatches(needle);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(forward ? 0 : lastPositionInDocument() - 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setTextCursor(m_tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (EDITOR(find(needle, flags))) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_tc.setPosition(m_tc.anchor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (oldLine != cursorLineInDocument() - cursorLineOnScreen())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (forward)
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-17 21:11:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                showRedMessage(tr("search hit BOTTOM, continuing at TOP"));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            else
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-17 21:11:52 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                showRedMessage(tr("search hit TOP, continuing at BOTTOM"));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            highlightMatches(needle);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_tc = orig;
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            showRedMessage(tr("Pattern not found: ") + needle);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            highlightMatches(QString());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::highlightMatches(const QString &needle0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!hasConfig(ConfigHlSearch))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (needle0 == m_oldNeedle)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_oldNeedle = needle0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_searchSelections.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!needle0.isEmpty()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QTextCursor tc = m_tc;
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-14 15:47:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        tc.movePosition(StartOfDocument, MoveAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QTextDocument::FindFlags flags = QTextDocument::FindCaseSensitively;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString needle = needle0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        vimPatternToQtPattern(&needle, &flags);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EDITOR(setTextCursor(tc));
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 09:26:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        while (EDITOR(find(needle, flags))) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            tc = EDITOR(textCursor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            QTextEdit::ExtraSelection sel;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sel.cursor = tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sel.format = tc.blockCharFormat();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            sel.format.setBackground(QColor(177, 177, 0));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            m_searchSelections.append(sel);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            tc.movePosition(Right, MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            EDITOR(setTextCursor(tc));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 18:05:36 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    updateSelection();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToFirstNonBlankOnLine()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextDocument *doc = m_tc.document();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const QTextBlock &block = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int firstPos = block.position();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (int i = firstPos, n = firstPos + block.length(); i < n; ++i) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (!doc->characterAt(i).isSpace()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            setPosition(i);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setPosition(block.position());
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 14:35:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::indentRegion(QChar typedChar)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //int savedPos = anchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int beginLine = lineForPosition(anchor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int endLine = lineForPosition(position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (beginLine > endLine)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        qSwap(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-03 10:39:57 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int amount = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    emit q->indentRegion(&amount, beginLine, endLine, typedChar);
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setPosition(firstPositionInLine(beginLine));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    moveToFirstNonBlankOnLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setDotCommand("%1==", endLine - beginLine + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 10:36:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::shiftRegionRight(int repeat)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int beginLine = lineForPosition(anchor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int endLine = lineForPosition(position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (beginLine > endLine)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        qSwap(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int len = config(ConfigShiftWidth).toInt() * repeat;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString indent(len, ' ');
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int firstPos = firstPositionInLine(beginLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (int line = beginLine; line <= endLine; ++line) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setPosition(firstPositionInLine(line));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.insertText(indent);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setPosition(firstPos);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setDotCommand("%1>>", endLine - beginLine + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 12:12:35 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::shiftRegionLeft(int repeat)
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int beginLine = lineForPosition(anchor());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int endLine = lineForPosition(position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (beginLine > endLine)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        qSwap(beginLine, endLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int shift = config(ConfigShiftWidth).toInt() * repeat;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int tab = config(ConfigTabStop).toInt();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int firstPos = firstPositionInLine(beginLine);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (int line = beginLine; line <= endLine; ++line) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int pos = firstPositionInLine(line);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setPosition(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setAnchor(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        QString text = m_tc.block().text();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int amount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int i = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for (; i < text.size() && amount <= shift; ++i) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (text.at(i) == ' ')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                amount++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            else if (text.at(i) == '\t')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                amount += tab; // FIXME: take position into consideration
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        setPosition(pos + i);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        text = removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        setPosition(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:22:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setPosition(firstPos);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 13:03:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    moveToFirstNonBlankOnLine();
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-05 09:06:36 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setDotCommand("%1<<", endLine - beginLine + 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToTargetColumn()
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 18:35:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    const QTextBlock &block = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int col = m_tc.position() - m_tc.block().position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (col == m_targetColumn)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "CORRECTING COLUMN FROM: " << col << "TO" << m_targetColumn;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (m_targetColumn == -1 || m_tc.block().length() <= m_targetColumn)
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 15:44:51 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(block.position() + block.length() - 1, KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    else
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_tc.block().position() + m_targetColumn, KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-24 18:35:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 16:20:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/* if simple is given:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *  class 0: spaces
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *  class 1: non-spaces
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *  class 0: spaces
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *  class 1: non-space-or-letter-or-number
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 *  class 2: letter-or-number
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								static int charClass(QChar c, bool simple)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (simple)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return c.isSpace() ? 0 : 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (c.isLetterOrNumber() || c.unicode() == '_')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return 2;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return c.isSpace() ? 0 : 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int repeat = count();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextDocument *doc = m_tc.document();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int n = forward ? lastPositionInDocument() - 1 : 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:42:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int lastClass = -1;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    while (true) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QChar c = doc->characterAt(m_tc.position() + (forward ? 1 : -1));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //qDebug() << "EXAMINING: " << c << " AT " << position();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int thisClass = charClass(c, simple);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (thisClass != lastClass && lastClass != 0)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            --repeat;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:57:00 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (repeat == -1)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        lastClass = thisClass;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_tc.position() == n)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:04:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        forward ? moveRight() : moveLeft();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 16:20:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::handleFfTt(int key)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // m_subsubmode \in { 'f', 'F', 't', 'T' }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool forward = m_subsubdata == 'f' || m_subsubdata == 't';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int repeat = count();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextDocument *doc = m_tc.document();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextBlock block = m_tc.block();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int n = block.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (forward)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        n += block.length();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int pos = m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    while (true) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        pos += forward ? 1 : -1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (pos == n)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        int uc = doc->characterAt(pos).unicode();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (uc == ParagraphSeparator)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (uc == key)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            --repeat;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (repeat == 0) {
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (m_subsubdata == 't')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                --pos;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:25:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            else if (m_subsubdata == 'T')
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                ++pos;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:25:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (forward)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                m_tc.movePosition(Right, KeepAnchor, pos - m_tc.position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                m_tc.movePosition(Left, KeepAnchor, m_tc.position() - pos);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 16:20:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:50:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToNextWord(bool simple)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // FIXME: 'w' should stop on empty lines, too
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 00:18:03 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int repeat = count();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int n = lastPositionInDocument() - 1;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 14:36:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int lastClass = charClass(characterAtCursor(), simple);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    while (true) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-12 14:36:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QChar c = characterAtCursor();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        int thisClass = charClass(c, simple);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (thisClass != lastClass && thisClass != 0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            --repeat;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 22:42:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (repeat == 0)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        lastClass = thisClass;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:42:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        moveRight();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 20:12:17 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (m_tc.position() == n)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            break;
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 16:20:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-13 12:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::moveToMatchingParanthesis()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 22:03:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool moved = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bool forward = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    emit q->moveToMatchingParenthesis(&moved, &forward, &m_tc);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (moved && forward) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-29 09:22:00 +10:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								       if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == CapitalZSubMode || m_submode == RegisterSubMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 22:03:51 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            m_tc.movePosition(Left, KeepAnchor, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-09 16:20:49 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setTargetColumn();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-13 12:35:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::cursorLineOnScreen() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!editor())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return 0;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QRect rect = EDITOR(cursorRect());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return rect.y() / rect.height();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::linesOnScreen() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!editor())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return 1;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QRect rect = EDITOR(cursorRect());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return EDITOR(height()) / rect.height();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::columnsOnScreen() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (!editor())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return 1;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QRect rect = EDITOR(cursorRect());
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-07 18:11:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // qDebug() << "WID: " << EDITOR(width()) << "RECT: " << rect;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return EDITOR(width()) / rect.width();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::cursorLineInDocument() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return m_tc.block().blockNumber();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::cursorColumnInDocument() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return m_tc.position() - m_tc.block().position();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 21:01:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-28 02:15:26 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::linesInDocument() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return m_tc.isNull() ? 0 : m_tc.document()->blockCount();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::scrollToLineInDocument(int line)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // FIXME: works only for QPlainTextEdit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QScrollBar *scrollBar = EDITOR(verticalScrollBar());
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "SCROLL: " << scrollBar->value() << line;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:11:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    scrollBar->setValue(line);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 16:27:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-20 08:44:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::scrollUp(int count)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    scrollToLineInDocument(cursorLineInDocument() - cursorLineOnScreen() - count);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::lastPositionInDocument() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextBlock block = m_tc.document()->lastBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-25 19:11:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return block.position() + block.length();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-26 17:01:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QString FakeVimHandler::Private::lastSearchString() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								     return m_searchHistory.empty() ? QString() : m_searchHistory.back();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QString FakeVimHandler::Private::selectedText() const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextCursor tc = m_tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    tc.setPosition(m_anchor, KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 17:02:22 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return tc.selection().toPlainText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 16:15:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::firstPositionInLine(int line) const
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return m_tc.document()->findBlockByNumber(line - 1).position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:33:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::lastPositionInLine(int line) const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QTextBlock block = m_tc.document()->findBlockByNumber(line - 1);
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-05 17:06:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return block.position() + block.length() - 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								int FakeVimHandler::Private::lineForPosition(int pos) const
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextCursor tc = m_tc;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    tc.setPosition(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return tc.block().blockNumber() + 1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::enterVisualMode(VisualMode visualMode)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_visualMode = visualMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_marks['<'] = m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_marks['>'] = m_tc.position();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::leaveVisualMode()
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:05 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_visualMode = NoVisualMode;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateMiniBuffer();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:52:40 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    updateSelection();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:50:30 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QWidget *FakeVimHandler::Private::editor() const
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:43:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return m_textedit
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ? static_cast<QWidget *>(m_textedit)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        : static_cast<QWidget *>(m_plaintextedit);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:42:44 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::undo()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int current = m_tc.document()->revision();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //endEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 08:45:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(undo());
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //beginEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int rev = m_tc.document()->revision();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (current == rev)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(tr("Already at oldest change"));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    else
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:58:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(QString());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_undoCursorPosition.contains(rev))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_undoCursorPosition[rev]);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::redo()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int current = m_tc.document()->revision();
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //endEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 08:45:02 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(redo());
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //beginEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    int rev = m_tc.document()->revision();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (rev == current)
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:40:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(tr("Already at newest change"));
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    else
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-08 17:58:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        showBlackMessage(QString());
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (m_undoCursorPosition.contains(rev))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        m_tc.setPosition(m_undoCursorPosition[rev]);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 13:10:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QString FakeVimHandler::Private::removeSelectedText()
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-16 13:10:42 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 16:04:34 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "POS: " << position() << " ANCHOR: " << anchor() << m_tc.anchor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int pos = m_tc.position();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (pos == anchor())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return QString();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.setPosition(anchor(), MoveAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.setPosition(pos, KeepAnchor);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    QString from = m_tc.selection().toPlainText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-21 17:08:47 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_tc.removeSelectedText();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-16 09:18:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setAnchor();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    return from;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 11:45:56 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::enterInsertMode()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setCursorWidth(m_cursorWidth));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setOverwriteMode(false));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_mode = InsertMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_lastInsertion.clear();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::enterCommandMode()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setCursorWidth(m_cursorWidth));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setOverwriteMode(true));
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_mode = CommandMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-26 12:08:39 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::enterExMode()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setCursorWidth(0));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    EDITOR(setOverwriteMode(false));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_mode = ExMode;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::recordJump()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_jumpListUndo.append(position());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_jumpListRedo.clear();
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-06 11:22:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    UNDO_DEBUG("jumps: " << m_jumpListUndo);
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-28 19:22:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::recordNewUndo()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-02 16:43:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    //endEditBlock();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    UNDO_DEBUG("---- BREAK ----");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //beginEditBlock();
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 11:54:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!hasConfig(ConfigAutoIndent))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QTextBlock block = goingDown ? m_tc.block().previous() : m_tc.block().next();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    QString text = block.text();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    int pos = 0, n = text.size();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    while (pos < n && text.at(pos).isSpace())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        ++pos;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    text.truncate(pos);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // FIXME: handle 'smartindent' and 'cindent'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.insertText(text);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_justAutoIndented = text.size();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								bool FakeVimHandler::Private::removeAutomaticIndentation()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (!hasConfig(ConfigAutoIndent) || m_justAutoIndented == 0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.movePosition(StartOfLine, KeepAnchor);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_tc.removeSelectedText();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_lastInsertion.chop(m_justAutoIndented);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_justAutoIndented = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-03 14:58:41 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::handleStartOfLine()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (hasConfig(ConfigStartOfLine))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        moveToFirstNonBlankOnLine();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-08 16:05:24 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::Private::replay(const QString &command, int n)
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //qDebug() << "REPLAY: " << command;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    m_inReplay = true;
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 15:41:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    for (int i = n; --i >= 0; ) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        foreach (QChar c, command) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            //qDebug() << "  REPLAY: " << QString(c);
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            handleKey(c.unicode(), c.unicode(), QString(c));
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-11 15:41:20 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    m_inReplay = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								///////////////////////////////////////////////////////////////////////
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// FakeVimHandler
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								//
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								///////////////////////////////////////////////////////////////////////
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FakeVimHandler::FakeVimHandler(QWidget *widget, QObject *parent)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    : QObject(parent), d(new Private(this, widget))
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								FakeVimHandler::~FakeVimHandler()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    delete d;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    bool active = theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if (active && ev->type() == QEvent::KeyPress && ob == d->editor()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 16:32:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG("KEYPRESS" << kev->key());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        EventResult res = d->handleEvent(kev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        // returning false core the app see it
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 13:51:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //KEY_DEBUG("HANDLED CODE:" << res);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //return res != EventPassedToCore;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 13:51:27 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        //return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return res == EventHandled;
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-04 16:32:33 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:21:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (active && ev->type() == QEvent::ShortcutOverride && ob == d->editor()) {
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:21:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        if (d->wantsOverride(kev)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            KEY_DEBUG("OVERRIDING SHORTCUT" << kev->key());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            ev->accept(); // accepting means "don't run the shortcuts"
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:21:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-05 11:06:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        KEY_DEBUG("NO SHORTCUT OVERRIDE" << kev->key());
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        return true;
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-09 12:21:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return QObject::eventFilter(ob, ev);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-19 12:20:04 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 16:54:25 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::installEventFilter()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    d->installEventFilter();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::setupWidget()
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    d->setupWidget();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::restoreWidget()
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    d->restoreWidget();
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::handleCommand(const QString &cmd)
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 10:58:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    d->handleCommand(cmd);
							 | 
						
					
						
							
								
									
										
										
										
											2008-12-27 16:42:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-15 15:27:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::setCurrentFileName(const QString &fileName)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   d->m_currentFileName = fileName;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-06-15 15:14:16 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::showBlackMessage(const QString &msg)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   d->showBlackMessage(msg);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void FakeVimHandler::showRedMessage(const QString &msg)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								   d->showRedMessage(msg);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								QWidget *FakeVimHandler::widget()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    return d->editor();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-30 12:40:08 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								} // namespace Internal
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								} // namespace FakeVim
							 |