mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-17 17:29:37 -06:00
New function for detecting mixed RTL-LTR texts
Qt's isRightToLeft() returns true only for all left-to-right characters in the string. That prevents the automatic switch to LTR Text mode, when the text contains one or more left-to-right characters. See #1793 and #1929
This commit is contained in:
15
src/Data.cpp
15
src/Data.cpp
@@ -43,6 +43,21 @@ bool isTextOnly(QByteArray data, const QString& encoding, bool quickTest)
|
||||
}
|
||||
}
|
||||
|
||||
bool containsRightToLeft(const QString& text) {
|
||||
|
||||
for(QChar ch : text) {
|
||||
switch(ch.direction()) {
|
||||
case QChar::DirR:
|
||||
case QChar::DirAL:
|
||||
case QChar::DirRLE:
|
||||
case QChar::DirRLO:
|
||||
case QChar::DirRLI:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool startsWithBom(const QByteArray& data)
|
||||
{
|
||||
if(data.startsWith(bom3) ||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
// text but makes it less reliable
|
||||
bool isTextOnly(QByteArray data, const QString& encoding = QString(), bool quickTest = false);
|
||||
|
||||
// This returns true if text contains some character whose direction is right-to-left.
|
||||
bool containsRightToLeft(const QString& text);
|
||||
|
||||
// This function returns true if the data in the data parameter starts with a Unicode BOM. Otherwise it returns false.
|
||||
bool startsWithBom(const QByteArray& data);
|
||||
|
||||
|
||||
@@ -816,7 +816,7 @@ void EditDialog::editTextChanged()
|
||||
|
||||
// Switch to the Qt Editor if we detect right-to-left text,
|
||||
// since the QScintilla editor does not support it.
|
||||
if (sciEdit->text().isRightToLeft())
|
||||
if (containsRightToLeft(sciEdit->text()))
|
||||
ui->comboMode->setCurrentIndex(RtlTextEditor);
|
||||
}
|
||||
|
||||
@@ -871,7 +871,7 @@ int EditDialog::checkDataType(const QByteArray& bArrdata)
|
||||
if(!json::parse(cellData, nullptr, false).is_discarded())
|
||||
return JSON;
|
||||
else {
|
||||
if (QString::fromUtf8(cellData).isRightToLeft())
|
||||
if (containsRightToLeft(QString::fromUtf8(cellData)))
|
||||
return RtlText;
|
||||
else
|
||||
return Text;
|
||||
|
||||
Reference in New Issue
Block a user