Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions src/NotepadNext/docks/LuaConsoleDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ LuaConsoleDock::LuaConsoleDock(LuaState *l, QWidget *parent) :
input->braceHighlight(INVALID_POSITION, INVALID_POSITION);
}
});

connect(input, &ScintillaNext::linesAdded, [=](int linesAdded) {
if (input->lineCount() > 0)
qInfo("lines added %d", linesAdded);
});
}

LuaConsoleDock::~LuaConsoleDock()
Expand Down Expand Up @@ -262,6 +257,50 @@ void LuaConsoleDock::writeErrorToOutput(const char *s)
output->documentEnd();
}

void LuaConsoleDock::historyNext()
{
if (history.isEmpty()) return;

if (currentHistoryIndex < history.size() - 1) {
currentHistoryIndex++;
input->setText(history[currentHistoryIndex].toLatin1().constData());
}

input->documentEnd();
input->emptyUndoBuffer();
input->scrollToEnd();
}

void LuaConsoleDock::historyPrevious()
{
if (currentHistoryIndex == 0) return;

currentHistoryIndex--;

input->setText(history[currentHistoryIndex].toLatin1().constData());
input->documentEnd();
input->emptyUndoBuffer();
input->scrollToEnd();
}

void LuaConsoleDock::historyAdd(QString line)
{
if (!line.isEmpty()) {
if (history.isEmpty() || history.last() != line) {
history.append(line);
}
}

currentHistoryIndex = history.size();
}

void LuaConsoleDock::historyEnd()
{
currentHistoryIndex = history.size();
input->emptyUndoBuffer(); // Empty first in case it was a mistake
input->setText("");
}

void LuaConsoleDock::runCurrentCommand()
{
int prevLastLine = output->lineCount();
Expand Down Expand Up @@ -289,7 +328,7 @@ void LuaConsoleDock::runCurrentCommand()
}

QString text((const char *)input->characterPointer());
//historyAdd(GUI::StringFromUTF8(text).c_str());
historyAdd(text);

input->clearAll();
input->emptyUndoBuffer();
Expand All @@ -307,11 +346,32 @@ bool LuaConsoleDock::eventFilter(QObject *obj, QEvent *event)
runCurrentCommand();
return true;
}

if (keyEvent->key() == Qt::Key_Up)
{
if (input->lineCount() == 1 || input->currentPos() == input->length()) {
historyPrevious();
return true;
}
}

if (keyEvent->key() == Qt::Key_Down) {
if (input->lineCount() == 1 || input->currentPos() == 0) {
historyNext();
return true;
}
}

if (keyEvent->key() == Qt::Key_Escape) {
historyEnd();
return true;
}
}
else {
// standard event processing
return QObject::eventFilter(obj, event);
}

return false;
}

Expand Down
7 changes: 7 additions & 0 deletions src/NotepadNext/docks/LuaConsoleDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class LuaConsoleDock : public QDockWidget
void writeErrorToOutput(const char *s);
LuaState *L = Q_NULLPTR;

void historyNext();
void historyPrevious();
void historyAdd(QString line);
void historyEnd();

public slots:
void runCurrentCommand(void);

Expand All @@ -53,6 +58,8 @@ public slots:
ScintillaNext *output;
ScintillaNext *input;

QStringList history;
int currentHistoryIndex = 0;

void setupStyle(ScintillaNext *editor);
};
Expand Down
Loading