Add support for pasting multiline code to python
This commit is contained in:
parent
7e54d2c305
commit
6566b5da73
@ -19,6 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "line_editor.h"
|
#include "line_editor.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include "ColumnFormatter.h"
|
#include "ColumnFormatter.h"
|
||||||
@ -43,8 +45,19 @@ LineEditor::LineEditor(ParseHelper *helper, QWidget *parent) : QLineEdit(parent)
|
|||||||
|
|
||||||
void LineEditor::keyPressEvent(QKeyEvent *ev)
|
void LineEditor::keyPressEvent(QKeyEvent *ev)
|
||||||
{
|
{
|
||||||
|
if (ev->matches(QKeySequence::Paste)) {
|
||||||
if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
|
QString clipboard = QApplication::clipboard()->text();
|
||||||
|
if (clipboard.isEmpty())
|
||||||
|
return;
|
||||||
|
if (clipboard.contains('\n')) {
|
||||||
|
QStringList clipboard_lines = clipboard.split('\n');
|
||||||
|
for (int i = 0; i < clipboard_lines.size(); i++) {
|
||||||
|
addLineToHistory(clipboard_lines[i]);
|
||||||
|
Q_EMIT textLineInserted(clipboard_lines[i]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
|
||||||
QToolTip::hideText();
|
QToolTip::hideText();
|
||||||
if (lines.empty())
|
if (lines.empty())
|
||||||
return;
|
return;
|
||||||
@ -79,13 +92,18 @@ bool LineEditor::focusNextPrevChild(bool next) { return false; }
|
|||||||
|
|
||||||
void LineEditor::textInserted()
|
void LineEditor::textInserted()
|
||||||
{
|
{
|
||||||
if (lines.empty() || lines.back() != text())
|
addLineToHistory(text());
|
||||||
lines += text();
|
clear();
|
||||||
|
Q_EMIT textLineInserted(lines.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEditor::addLineToHistory(QString line)
|
||||||
|
{
|
||||||
|
if (lines.empty() || lines.back() != line)
|
||||||
|
lines += line;
|
||||||
if (lines.size() > 100)
|
if (lines.size() > 100)
|
||||||
lines.removeFirst();
|
lines.removeFirst();
|
||||||
index = lines.size();
|
index = lines.size();
|
||||||
clear();
|
|
||||||
Q_EMIT textLineInserted(lines.back());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEditor::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); }
|
void LineEditor::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); }
|
||||||
|
@ -47,6 +47,7 @@ class LineEditor : public QLineEdit
|
|||||||
void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
|
void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
|
||||||
bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
|
bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE;
|
||||||
void autocomplete();
|
void autocomplete();
|
||||||
|
void addLineToHistory(QString line);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int index;
|
int index;
|
||||||
|
Loading…
Reference in New Issue
Block a user