diff options
| author | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
| commit | 82ebb1ed1af30cee4dfbb1c628431d32885a00e0 (patch) | |
| tree | 1a1f782d3e576b758be0bc61171574a7cd8f2376 /widgets/JttyLiveEntry.hpp | |
| parent | 061658210acb6425517733ea012dda803a7f72a1 (diff) | |
| parent | 61d684922b0f1c8455cc60eb3d123df058c9e1f5 (diff) | |
Merge tag 'debian/3.3.0_beta2+dfsg-1' into hibbian/trixie-backports
tagging wsjtx 3.3.0~beta2+dfsg-1
Diffstat (limited to 'widgets/JttyLiveEntry.hpp')
| -rw-r--r-- | widgets/JttyLiveEntry.hpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/widgets/JttyLiveEntry.hpp b/widgets/JttyLiveEntry.hpp new file mode 100644 index 00000000..fc4810d8 --- /dev/null +++ b/widgets/JttyLiveEntry.hpp @@ -0,0 +1,53 @@ +// -*- Mode: C++ -*- +#ifndef JTTY_LIVE_ENTRY_HPP +#define JTTY_LIVE_ENTRY_HPP + +#include <QString> +#include <QStringList> + +namespace Jtty +{ + // Widest lookahead try_compact() uses (lib/jtty/jtty_mod.f90, words(3)); holding back this many trailing words guarantees an atom in progress is never split by an early commit. + inline constexpr int maxCompactAtomWords = 3; + + struct IncrementalCommitPlan + { + QString text; // Text to pack and send now; empty means nothing yet. + int length {0}; // uncommittedText.left(length) == text, exactly. + }; + + // Number of complete (space-terminated) words in uncommittedText -- a word still being typed (no trailing space yet) doesn't count. Exposed so callers can gate on how much has piled up, not just whether anything has. + inline int completeWordCount (QString const& uncommittedText) + { + if (uncommittedText.isEmpty ()) return 0; + bool const endsWithCompleteWord = uncommittedText.back () == QLatin1Char {' '}; + QStringList const words = uncommittedText.split ( + QLatin1Char {' '}, Qt::SkipEmptyParts); + return endsWithCompleteWord ? words.size () : words.size () - 1; + } + + // Releases uncommittedText up to its trailing holdbackWords complete words (plus any partial word), since a compact atom there could still be extended by what's typed next; forceFlush releases all of it (newline/segment-limit boundary). Assumes single-space-normalized input, matching prepareTransmitText's convention. + inline IncrementalCommitPlan planIncrementalCommit ( + QString const& uncommittedText, bool forceFlush = false, + int holdbackWords = maxCompactAtomWords) + { + if (uncommittedText.isEmpty ()) return {}; + if (forceFlush) return {uncommittedText, uncommittedText.size ()}; + + int const commitWordCount = completeWordCount (uncommittedText) - holdbackWords; + if (commitWordCount <= 0) return {}; + + // Advance to the end of the commitWordCount-th word's trailing space, so the remainder starts cleanly at the next word. + int length = 0; + int wordsSeen = 0; + while (wordsSeen < commitWordCount) { + int const spaceAt = uncommittedText.indexOf (QLatin1Char {' '}, length); + Q_ASSERT (spaceAt >= 0); // completeWordCount already bounds this walk. + length = spaceAt + 1; + ++wordsSeen; + } + return {uncommittedText.left (length), length}; + } +} + +#endif |
