[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kate/KDE/4.12] /: vi-mode: backport of altgr and key parsing removal
From: Michal Humpula <michal.humpula () seznam ! cz>
Date: 2014-02-24 20:34:03
Message-ID: E1WI2Dz-000555-TM () scm ! kde ! org
[Download RAW message or body]
Git commit 9d2f955f521fc53a5385ea96990e3b9a63920aea by Michal Humpula.
Committed on 29/11/2013 at 19:31.
Pushed by michalhumpula into branch 'KDE/4.12'.
vi-mode: backport of altgr and key parsing removal
This is a squash of 9d06f5bc, d6820b72 and 14886143.
Was in master for couple of weeks without anyone complaining, so
it should be mostly ok.
BUG: 329756
M +5 -1 part/vimode/kateviinputmodemanager.cpp
M +6 -151 part/vimode/katevikeyparser.cpp
M +0 -5 part/vimode/katevikeyparser.h
M +0 -5 part/vimode/katevinormalmode.cpp
M +61 -0 tests/vimode_test.cpp
M +2 -0 tests/vimode_test.h
http://commits.kde.org/kate/9d2f955f521fc53a5385ea96990e3b9a63920aea
diff --git a/part/vimode/kateviinputmodemanager.cpp \
b/part/vimode/kateviinputmodemanager.cpp index 15cb9cc..2451d34 100644
--- a/part/vimode/kateviinputmodemanager.cpp
+++ b/part/vimode/kateviinputmodemanager.cpp
@@ -128,6 +128,10 @@ bool KateViInputModeManager::handleKeypress(const QKeyEvent *e)
if (!isReplayingLastChange() && !isSyntheticSearchCompletedKeyPress)
{
+ if (e->key() == Qt::Key_AltGr) {
+ return true; // do nothing:)
+ }
+
// Hand off to the key mapper, and decide if this key is part of a mapping.
if (e->key() != Qt::Key_Control && e->key() != Qt::Key_Shift && e->key() != \
Qt::Key_Alt && e->key() != Qt::Key_Meta) {
@@ -913,4 +917,4 @@ bool KateViInputModeManager::Completion::removeTail() const
KateViInputModeManager::Completion::CompletionType \
KateViInputModeManager::Completion::completionType() const {
return m_completionType;
-}
\ No newline at end of file
+}
diff --git a/part/vimode/katevikeyparser.cpp b/part/vimode/katevikeyparser.cpp
index bfef2a8..ea1f290 100644
--- a/part/vimode/katevikeyparser.cpp
+++ b/part/vimode/katevikeyparser.cpp
@@ -31,7 +31,6 @@ KateViKeyParser::KateViKeyParser()
m_katevi2qt = new QHash<QString, int>;
m_nameToKeyCode = new QHash<QString, int>;
m_keyCodeToName = new QHash<int, QString>;
- m_altGrPressed = false;
initKeyTables();
}
@@ -659,136 +658,21 @@ const QString KateViKeyParser::decodeKeySequence( const \
QString &keys ) const return ret;
}
-char KateViKeyParser::scanCodeToChar(quint32 code, Qt::KeyboardModifiers modifiers, \
bool isLetter) const
-{
- //Do not forget to ignore letters with shift. Should work with punctuation and \
special characters ($, ^) only.
- //any punctuation (without shift) that has different signs in different layouts \
should be added to the second switch.
- if ((modifiers & Qt::ShiftModifier) && !isLetter)
- {
- switch(code)
- {
- case 10:
- return '!';
- case 11:
- return '@';
- case 12:
- return '#';
- case 13:
- return '$';
- case 14:
- return '%';
- case 15:
- return '^';
- case 16:
- return '&';
- case 17:
- return '*';
- case 18:
- return '(';
- case 19:
- return ')';
- default:
- return '0';
- }
- }
- switch(code)
- {
- case 24:
- return 'q';
- case 25:
- return 'w';
- case 26:
- return 'e';
- case 27:
- return 'r';
- case 28:
- return 't';
- case 29:
- return 'y';
- case 30:
- return 'u';
- case 31:
- return 'i';
- case 32:
- return 'o';
- case 33:
- return 'p';
- case 34:
- return '[';
- case 35:
- return ']';
- case 38:
- return 'a';
- case 39:
- return 's';
- case 40:
- return 'd';
- case 41:
- return 'f';
- case 42:
- return 'g';
- case 43:
- return 'h';
- case 44:
- return 'j';
- case 45:
- return 'k';
- case 46:
- return 'l';
- case 47:
- return ';';
- case 48:
- return '\'';
- case 49:
- return '`';
- case 52:
- return 'z';
- case 53:
- return 'x';
- case 54:
- return 'c';
- case 55:
- return 'v';
- case 56:
- return 'b';
- case 57:
- return 'n';
- case 58:
- return 'm';
- case 59:
- return ',';
- case 60:
- return '.';
- case 61:
- return '/';
- default:
- return 0;
- }
- return 0;
-}
-
const QChar KateViKeyParser::KeyEventToQChar(const QKeyEvent& keyEvent)
{
const int keyCode = keyEvent.key();
const QString &text = keyEvent.text();
const Qt::KeyboardModifiers mods = keyEvent.modifiers();
- const quint32 nativeScanCode = keyEvent.nativeScanCode();
-
- QChar key;
-
- if ( !text.isEmpty() ) {
- key = text.at(0);
- }
// If previous key press was AltGr, return key value right away and don't go
// down the "handle modifiers" code path. AltGr is really confusing...
- if ( m_altGrPressed ) {
- setAltGrStatus( false );
- return key;
+ //if ( m_altGrPressed ) {
+ if ( mods & Qt::GroupSwitchModifier ) {
+ return ( !text.isEmpty() ) ? text.at(0) : QChar();
}
if ( text.isEmpty() || ( text.length() == 1 && text.at(0) < 0x20 ) || keyCode == \
Qt::Key_Delete
- || ( mods != Qt::NoModifier && mods != Qt::ShiftModifier && mods != \
Qt::KeypadModifier && mods != Qt::GroupSwitchModifier) ) { + || ( mods != \
Qt::NoModifier && mods != Qt::ShiftModifier && mods != Qt::KeypadModifier) ) { \
QString keyPress;
keyPress.append( '<' );
@@ -799,37 +683,8 @@ const QChar KateViKeyParser::KeyEventToQChar(const QKeyEvent& \
keyEvent)
keyPress.append( keyCode <= 0xFF ? QChar( keyCode ) : qt2vi( keyCode ) );
keyPress.append( '>' );
- key = encodeKeySequence( keyPress ).at( 0 );
+ return encodeKeySequence( keyPress ).at( 0 );
} else {
- //maybe we have a non-latin letter, try to convert to latin charachter
- //note that non-latin letter in Latin layout can be a punctuation character \
(also some punctuation differs too)
- QChar tempChar(text.at(0));
- //don't touch latin keys
- if (mods == Qt::KeypadModifier && keyCode >= Qt::Key_0 && keyCode <= \
Qt::Key_9)
- {
- // Keypad numbers to ordinary numbers.
- key = tempChar;
- }
- if ((keyCode < Qt::Key_A || keyCode > Qt::Key_Z) && tempChar.isLetter()) {
- char ch = scanCodeToChar(nativeScanCode, mods, tempChar.isLetter());
- if (ch != 0) {
- key = QChar(ch);
- if (key.isLetter()) {
- if (tempChar.isUpper()) {
- key = QChar(ch).toUpper();
- } else {
- key = QChar(ch).toLower(); //scanCodeToChar returns lower, but \
we don't want to depend on it
- }
- }
- }
- else {
- key = tempChar;
- }
- }
- else {
- key = tempChar;
- }
+ return text.at(0);
}
-
- return key;
}
diff --git a/part/vimode/katevikeyparser.h b/part/vimode/katevikeyparser.h
index 8bcdf56..1150111 100644
--- a/part/vimode/katevikeyparser.h
+++ b/part/vimode/katevikeyparser.h
@@ -47,11 +47,8 @@ public:
const QString decodeKeySequence( const QString &keys ) const;
QString qt2vi( int key ) const;
int vi2qt( const QString &keypress ) const;
- char scanCodeToChar(quint32 code, Qt::KeyboardModifiers modifiers, bool isLetter) \
const; const QChar KeyEventToQChar(const QKeyEvent &keyEvent);
- void setAltGrStatus( bool active ) { m_altGrPressed = active; }
-
private:
void initKeyTables();
@@ -60,8 +57,6 @@ private:
QHash<QString, int> *m_nameToKeyCode;
QHash<int, QString> *m_keyCodeToName;
- bool m_altGrPressed;
-
static KateViKeyParser *m_instance;
};
diff --git a/part/vimode/katevinormalmode.cpp b/part/vimode/katevinormalmode.cpp
index e8af968..76be563 100644
--- a/part/vimode/katevinormalmode.cpp
+++ b/part/vimode/katevinormalmode.cpp
@@ -117,11 +117,6 @@ bool KateViNormalMode::handleKeypress( const QKeyEvent *e )
return false;
}
- if ( keyCode == Qt::Key_AltGr ) {
- KateViKeyParser::self()->setAltGrStatus( true );
- return true;
- }
-
clearYankHighlight();
if ( keyCode == Qt::Key_Escape || (keyCode == Qt::Key_C && e->modifiers() == \
Qt::ControlModifier) || (keyCode == Qt::Key_BracketLeft && e->modifiers() == \
Qt::ControlModifier)) {
diff --git a/tests/vimode_test.cpp b/tests/vimode_test.cpp
index b32c177..a9927e9 100644
--- a/tests/vimode_test.cpp
+++ b/tests/vimode_test.cpp
@@ -7359,4 +7359,65 @@ void ViModeTest::textRemoved(Document* document, Range range)
m_docChanges.append(DocChange(DocChange::TextRemoved, range));
}
+
+void ViModeTest::keyParsingTests()
+{
+
+ // BUG #298726
+ const QChar char_o_diaeresis(246);
+
+ // Test that we can correctly translate finnish key ö
+ QKeyEvent *k = QKeyEvent::createExtendedKeyEvent( QEvent::KeyPress, 214, \
Qt::NoModifier, 47, 246, 16400, char_o_diaeresis); + \
QCOMPARE(KateViKeyParser::self()->KeyEventToQChar(*k), QChar(246)); +
+ // Test that it can be used in mappings
+ clearAllMappings();
+ KateGlobal::self()->viInputModeGlobal()->addMapping(KateViGlobal::NormalModeMapping, \
char_o_diaeresis, "ifoo", KateViGlobal::Recursive); + DoTest("hello", \
QString("ll%1bar").arg(char_o_diaeresis), "hefoobarllo"); +}
+
+void ViModeTest::AltGr()
+{
+ QKeyEvent *altGrDown;
+ QKeyEvent *altGrUp;
+
+ // Test Alt-gr still works - this isn't quite how things work in "real-life": in \
real-life, something like + // Alt-gr+7 would be a "{", but I don't think this can \
be reproduced without sending raw X11 + // keypresses to Qt, so just duplicate the \
keypress events we would receive if we pressed + // Alt-gr+7 (that is: Alt-gr down; \
"{"; Alt-gr up). + BeginTest("");
+ TestPressKey("i");
+ altGrDown = new QKeyEvent(QEvent::KeyPress, Qt::Key_AltGr, Qt::NoModifier);
+ QApplication::postEvent(kate_view->focusProxy(), altGrDown);
+ QApplication::sendPostedEvents();
+ // Not really Alt-gr and 7, but this is the key event that is reported by Qt if we \
press that. + QKeyEvent *altGrAnd7 = new QKeyEvent(QEvent::KeyPress, \
Qt::Key_BraceLeft, Qt::GroupSwitchModifier, "{" ); + \
QApplication::postEvent(kate_view->focusProxy(), altGrAnd7); + \
QApplication::sendPostedEvents(); + altGrUp = new QKeyEvent(QEvent::KeyRelease, \
Qt::Key_AltGr, Qt::NoModifier); + QApplication::postEvent(kate_view->focusProxy(), \
altGrUp); + QApplication::sendPostedEvents();
+ TestPressKey("\\ctrl-c");
+ FinishTest("{");
+
+ // French Bepo keyabord AltGr + Shift + s = Ù = Unicode(0x00D9);
+ const QString ugrave = QString(QChar(0x00D9));
+ BeginTest("");
+ TestPressKey("i");
+ altGrDown = new QKeyEvent(QEvent::KeyPress, Qt::Key_AltGr, Qt::NoModifier);
+ QApplication::postEvent(kate_view->focusProxy(), altGrDown);
+ QApplication::sendPostedEvents();
+ altGrDown = new QKeyEvent(QEvent::KeyPress, Qt::Key_Shift, Qt::ShiftModifier | \
Qt::GroupSwitchModifier); + QApplication::postEvent(kate_view->focusProxy(), \
altGrDown); + QApplication::sendPostedEvents();
+ QKeyEvent *altGrAndUGrave = new QKeyEvent(QEvent::KeyPress, Qt::Key_Ugrave, \
Qt::ShiftModifier | Qt::GroupSwitchModifier, ugrave); + qDebug() << \
QString("%1").arg(altGrAndUGrave->modifiers(), 10, 16); + \
QApplication::postEvent(kate_view->focusProxy(), altGrAndUGrave); + \
QApplication::sendPostedEvents(); + altGrUp = new QKeyEvent(QEvent::KeyRelease, \
Qt::Key_AltGr, Qt::NoModifier); + QApplication::postEvent(kate_view->focusProxy(), \
altGrUp); + QApplication::sendPostedEvents();
+ FinishTest(ugrave);
+}
+
// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/tests/vimode_test.h b/tests/vimode_test.h
index be6afa3..b982bc8 100644
--- a/tests/vimode_test.h
+++ b/tests/vimode_test.h
@@ -168,6 +168,8 @@ private Q_SLOTS:
void MacroTests();
void debuggingTests();
+ void keyParsingTests();
+ void AltGr();
private:
enum Expectation { ShouldPass, ShouldFail };
void BeginTest(const QString& original_text);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic