forked from qt-creator/qt-creator
QmlConsole: Remove zero width space
Zero width space is inserted at every punctuation to serve as a potential line break. All occurrences should be removed before sending the expression to JS engine for evaluation. Task-number: QTCREATORBUG-8859 Change-Id: I170dfd5fb0f1122ed945bb2e5f77ecaad925004b Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
committed by
Kai Koehne
parent
f57795aaf2
commit
7bba366482
@@ -149,4 +149,10 @@ const QString &ConsoleItem::text() const
|
|||||||
return m_text;
|
return m_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ConsoleItem::expression() const
|
||||||
|
{
|
||||||
|
QString text = m_text;
|
||||||
|
return text.remove(QChar(0x200b)); // ZERO WIDTH SPACE
|
||||||
|
}
|
||||||
|
|
||||||
} // QmlJS
|
} // QmlJS
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
int childNumber() const;
|
int childNumber() const;
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
const QString &text() const;
|
const QString &text() const;
|
||||||
|
QString expression() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConsoleItem *m_parentItem;
|
ConsoleItem *m_parentItem;
|
||||||
|
|||||||
@@ -213,7 +213,8 @@ void QmlConsoleEdit::handleUpKey()
|
|||||||
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
||||||
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
||||||
m_historyIndex = index;
|
m_historyIndex = index;
|
||||||
replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
|
replaceCurrentScript(
|
||||||
|
model->data(index, QmlConsoleItemModel::ExpressionRole).toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,10 +233,12 @@ void QmlConsoleEdit::handleDownKey()
|
|||||||
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
|
||||||
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
index, QmlConsoleItemModel::TypeRole).toInt()) {
|
||||||
m_historyIndex = index;
|
m_historyIndex = index;
|
||||||
if (currentRow == model->rowCount() - 1)
|
if (currentRow == model->rowCount() - 1) {
|
||||||
replaceCurrentScript(m_cachedScript);
|
replaceCurrentScript(m_cachedScript);
|
||||||
else
|
} else {
|
||||||
replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
|
replaceCurrentScript(
|
||||||
|
model->data(index, QmlConsoleItemModel::ExpressionRole).toString());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ void QmlConsoleItemDelegate::setEditorData(QWidget *editor,
|
|||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QmlConsoleEdit *edtr = qobject_cast<QmlConsoleEdit *>(editor);
|
QmlConsoleEdit *edtr = qobject_cast<QmlConsoleEdit *>(editor);
|
||||||
edtr->insertPlainText(index.data(Qt::DisplayRole).toString());
|
edtr->insertPlainText(index.data(QmlConsoleItemModel::ExpressionRole).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlConsoleItemDelegate::setModelData(QWidget *editor,
|
void QmlConsoleItemDelegate::setModelData(QWidget *editor,
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ QVariant QmlConsoleItemModel::data(const QModelIndex &index, int role) const
|
|||||||
return item->file;
|
return item->file;
|
||||||
else if (role == QmlConsoleItemModel::LineRole)
|
else if (role == QmlConsoleItemModel::LineRole)
|
||||||
return item->line;
|
return item->line;
|
||||||
|
else if (role == QmlConsoleItemModel::ExpressionRole)
|
||||||
|
return item->expression();
|
||||||
else
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class QmlConsoleItemModel : public QAbstractItemModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole };
|
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole, ExpressionRole };
|
||||||
|
|
||||||
explicit QmlConsoleItemModel(QObject *parent = 0);
|
explicit QmlConsoleItemModel(QObject *parent = 0);
|
||||||
~QmlConsoleItemModel();
|
~QmlConsoleItemModel();
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ void QmlConsoleView::copyToClipboard(const QModelIndex &index)
|
|||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString contents = model()->data(index).toString();
|
QString contents = model()->data(index, QmlConsoleItemModel::ExpressionRole).toString();
|
||||||
// See if we have file and line Info
|
// See if we have file and line Info
|
||||||
QString filePath = model()->data(index, QmlConsoleItemModel::FileRole).toString();
|
QString filePath = model()->data(index, QmlConsoleItemModel::FileRole).toString();
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user