Skip to content

Commit

Permalink
Fix frozen window for large requests (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
falbru authored Jul 25, 2024
1 parent a1407e0 commit 0aaf1e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/kakouneclient.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kakouneclient.hpp"

#include "rpc/rpc.hpp"
#include <qjsondocument.h>

void KakouneClient::handleRequest(QJsonObject request)
{
Expand Down Expand Up @@ -83,13 +84,27 @@ KakouneClient::KakouneClient(const QString &session_id, QString arguments,
{
connect(&m_process, &QProcess::readyReadStandardOutput, [=]() {
QByteArray buffer = m_process.readAllStandardOutput();
if (!m_request_buffer.isEmpty())
{
buffer = m_request_buffer + buffer;
}

QList<QByteArray> requests = buffer.split('\n');
for (QByteArray request : requests)
{
if (request == "")
continue;

auto doc = QJsonDocument::fromJson(request);
if (!doc.isObject()) // Will occur when the remaining part of the request is sent in the next "chunk" of
// standard output
{
m_request_buffer = request;
break;
}

handleRequest(QJsonDocument::fromJson(request).object());
m_request_buffer.clear();
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/kakouneclient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "rpc/line.hpp"
#include "rpc/rpc.hpp"
#include <QtWidgets>
#include <qglobal.h>

class KakouneClient : public QObject
{
Expand Down Expand Up @@ -60,6 +61,8 @@ class KakouneClient : public QObject
QString m_client_name;
QProcess m_process;

QByteArray m_request_buffer;

QList<RPC::Line> m_lines;
RPC::Face m_default_face;
RPC::Face m_padding_face;
Expand Down

0 comments on commit 0aaf1e8

Please sign in to comment.