Commit 7bba3664 authored by Aurindam Jana's avatar Aurindam Jana Committed by Kai Koehne

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: default avatarMitch Curtis <mitch.curtis@digia.com>
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent f57795aa
......@@ -149,4 +149,10 @@ const QString &ConsoleItem::text() const
return m_text;
}
QString ConsoleItem::expression() const
{
QString text = m_text;
return text.remove(QChar(0x200b)); // ZERO WIDTH SPACE
}
} // QmlJS
......@@ -67,6 +67,7 @@ public:
int childNumber() const;
void setText(const QString &text);
const QString &text() const;
QString expression() const;
private:
ConsoleItem *m_parentItem;
......
......@@ -213,7 +213,8 @@ void QmlConsoleEdit::handleUpKey()
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
index, QmlConsoleItemModel::TypeRole).toInt()) {
m_historyIndex = index;
replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
replaceCurrentScript(
model->data(index, QmlConsoleItemModel::ExpressionRole).toString());
break;
}
}
......@@ -232,10 +233,12 @@ void QmlConsoleEdit::handleDownKey()
if (ConsoleItem::InputType == (ConsoleItem::ItemType)model->data(
index, QmlConsoleItemModel::TypeRole).toInt()) {
m_historyIndex = index;
if (currentRow == model->rowCount() - 1)
if (currentRow == model->rowCount() - 1) {
replaceCurrentScript(m_cachedScript);
else
replaceCurrentScript(model->data(index, Qt::DisplayRole).toString());
} else {
replaceCurrentScript(
model->data(index, QmlConsoleItemModel::ExpressionRole).toString());
}
break;
}
}
......
......@@ -313,7 +313,7 @@ void QmlConsoleItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
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,
......
......@@ -159,6 +159,8 @@ QVariant QmlConsoleItemModel::data(const QModelIndex &index, int role) const
return item->file;
else if (role == QmlConsoleItemModel::LineRole)
return item->line;
else if (role == QmlConsoleItemModel::ExpressionRole)
return item->expression();
else
return QVariant();
}
......
......@@ -43,7 +43,7 @@ class QmlConsoleItemModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole };
enum Roles { TypeRole = Qt::UserRole, FileRole, LineRole, ExpressionRole };
explicit QmlConsoleItemModel(QObject *parent = 0);
~QmlConsoleItemModel();
......
......@@ -242,7 +242,7 @@ void QmlConsoleView::copyToClipboard(const QModelIndex &index)
if (!index.isValid())
return;
QString contents = model()->data(index).toString();
QString contents = model()->data(index, QmlConsoleItemModel::ExpressionRole).toString();
// See if we have file and line Info
QString filePath = model()->data(index, QmlConsoleItemModel::FileRole).toString();
if (!filePath.isEmpty()) {
......
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