Commit 7701d345 authored by Victor Yacovlev's avatar Victor Yacovlev

Keyboard layout autocorrection

parent ee8ccd33
Pipeline #354 passed with stages
in 28 minutes and 1 second
......@@ -50,6 +50,8 @@ public:
*/
inline virtual QString correctCapitalization(const QString & name, LexemType lxType) const
{ return name; }
inline virtual bool isKnownLexem(const QString &lexem, int lineNo, int colNo, const QString &context) const
{ return false; }
};
......
This diff is collapsed.
......@@ -99,6 +99,10 @@ protected:
void doAutocomplete();
void keyReleaseEvent(QKeyEvent *);
void setProperFormat(QPainter * p, Shared::LexemType type, const QChar &c);
QString tryCorrectKeyboardLayout(const QString &source) const;
void tryCorrectKeyboardLayoutForLastLexem();
protected slots:
void updateCursor();
void updateText(int fromLine, int toLine);
......@@ -131,6 +135,7 @@ private:
QLabel * marginHintBox_;
bool escPressFlag_;
bool typeTextFlag_;
signals:
void urlsDragAndDropped(const QList<QUrl> &);
......
......@@ -19,6 +19,31 @@ void Analizer::connectSignalImportsChanged(QObject *receiver, const char *slot)
receiver, slot);
}
bool Analizer::isKnownLexem(const QString &lexem, int lineNo, int colNo, const QString &context) const
{
// Check for keyword
if (lexem.length()>=2 && _lexer->isLanguageReservedName(lexem)) {
return true;
}
// TODO check for russian one-letter keyword 'и'
// Check for function/variable name
if (lexem.length()>=3) {
QString before = context.mid(0, colNo-lexem.length());
QString after = context.mid(colNo);
using Shared::Analizer::Suggestion;
QList<Suggestion> suggestions = suggestAutoComplete(lineNo, before, after);
Q_FOREACH(Suggestion suggestion, suggestions) {
if (suggestion.value.trimmed() == lexem) {
return true;
}
}
}
return false;
}
void Analizer::setSourceLanguage(const QDir & resourcesRoot, const QLocale::Language &language)
{
Lexer::setLanguage(resourcesRoot, language);
......
......@@ -48,6 +48,7 @@ public:
static void setSourceLanguage(const QDir & resourcesRoot, const QLocale::Language & language);
static void setModuleAlwaysAvailable(const QByteArray & moduleName);
void connectSignalImportsChanged(QObject *receiver, const char *slot);
bool isKnownLexem(const QString &lexem, int lineNo, int colNo, const QString &context) const;
public slots:
......
......@@ -1542,6 +1542,17 @@ void Lexer::setSourceDirName(const QString &dir)
_sourceDirName = dir;
}
bool Lexer::isLanguageReservedName(const QString &lexem) const
{
if (_RxKeyWords.exactMatch(lexem) || _KeyWords.contains(lexem))
return true;
if (_RxTypes.exactMatch(lexem))
return true;
if (_RxConst.exactMatch(lexem))
return true;
return false;
}
QString Lexer::testingAlgorhitmName()
{
QString name = tr("@testing");
......
......@@ -29,6 +29,8 @@ public:
inline QString outputLexemName() const{ return QString::fromUtf8("вывод"); }
void setSourceDirName(const QString &dir);
bool isLanguageReservedName(const QString &lexem) const;
public slots:
int splitIntoStatements(const QStringList &lines
, int baseLineNo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment