[FarGroup/FarManager] master: Continue fullwidth-aware rendering (0098cabbd)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Jan 11, 2026, 9:15:55 AM (5 days ago) Jan 11
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/0098cabbdccd2d5af7c26793ea89a203e2783c7e

>---------------------------------------------------------------

commit 0098cabbdccd2d5af7c26793ea89a203e2783c7e
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Sun Jan 11 14:05:57 2026 +0000

Continue fullwidth-aware rendering


>---------------------------------------------------------------

0098cabbdccd2d5af7c26793ea89a203e2783c7e
far/message.cpp | 19 +++++++++++--------
far/strmix.cpp | 43 +++++++++++++++++++++----------------------
far/strmix.hpp | 4 +++-
3 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/far/message.cpp b/far/message.cpp
index 1c0e3d928..afd003e87 100644
--- a/far/message.cpp
+++ b/far/message.cpp
@@ -47,7 +47,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "colormix.hpp"
#include "config.hpp"
#include "keyboard.hpp"
-#include "FarDlgBuilder.hpp"
#include "clipboard.hpp"
#include "lang.hpp"
#include "stddlg.hpp"
@@ -198,7 +197,10 @@ static message_result MessageImpl(
}
}

- auto MaxLength = !Strings.empty()? std::ranges::fold_left(Strings, 0uz, [](size_t const Value, string const& i){ return std::max(Value, i.size()); }) : 0;
+ std::vector<size_t> StringLengths;
+ std::ranges::transform(Strings, std::back_inserter(StringLengths), visual_string_length);
+
+ auto MaxLength = StringLengths.empty()? 0 : std::ranges::max(StringLengths);

string strClipText;

@@ -206,7 +208,7 @@ static message_result MessageImpl(

if (!Title.empty())
{
- MaxLength = std::max(MaxLength, Title.size() + 2); // 2 for surrounding spaces
+ MaxLength = std::max(MaxLength, visual_string_length(Title) + 2); // 2 for surrounding spaces
append(strClipText, Title, Eol, Eol);
}

@@ -247,7 +249,7 @@ static message_result MessageImpl(
for (const auto& i : wrapped_text(Str, MAX_MESSAGE_WIDTH))
{
Strings.emplace_back(i);
- MaxLength = std::max(MaxLength, i.size());
+ MaxLength = std::max(MaxLength, visual_string_length(i));
}
};

@@ -333,7 +335,7 @@ static message_result MessageImpl(
}
else
{
- if (Str.size() + 6 + 2 + 2 > static_cast<size_t>(MessageWidth)) // 6 for frame, 2 for border, 2 for inner margin
+ if (StringLengths[Index] + 6 + 2 + 2 > static_cast<size_t>(MessageWidth)) // 6 for frame, 2 for border, 2 for inner margin
{
Item.Type = DI_EDIT;
Item.Flags |= DIF_READONLY | DIF_BTNNOCLOSE | DIF_SELECTONENTRY;
@@ -441,7 +443,7 @@ static message_result MessageImpl(
{
const auto strTempTitle = cut_right(Title, MaxLength);

- GotoXY(Position.left + (Position.width() - 2 - static_cast<int>(strTempTitle.size())) / 2, Position.top + 1);
+ GotoXY(Position.left + (Position.width() - 2 - static_cast<int>(visual_string_length(strTempTitle))) / 2, Position.top + 1);
Text(concat(L' ', strTempTitle, L' '));
}

@@ -469,9 +471,10 @@ static message_result MessageImpl(
SeparatorText.push_back(L' ');
}

- if (SeparatorText.size() < static_cast<size_t>(Length))
+ const auto SeparatorTextVisualLength = visual_string_length(SeparatorText);
+ if (SeparatorTextVisualLength < static_cast<size_t>(Length))
{
- GotoXY(Position.left + 3 + static_cast<int>(Length - SeparatorText.size()) / 2, Position.top + static_cast<int>(i)+2);
+ GotoXY(Position.left + 3 + static_cast<int>(Length - SeparatorTextVisualLength) / 2, Position.top + static_cast<int>(i)+2);
Text(SeparatorText);
}

diff --git a/far/strmix.cpp b/far/strmix.cpp
index b61d4217b..551831b03 100644
--- a/far/strmix.cpp
+++ b/far/strmix.cpp
@@ -853,52 +853,51 @@ bool wrapped_text::get(bool Reset, string_view& Value) const

const auto advance = [&](size_t TokenEnd, size_t SeparatorSize)
{
+ if (TokenEnd == string::npos)
+ TokenEnd = visual_pos_to_string_pos(m_Tail, m_Width, 1);
+
Value = m_Tail.substr(0, TokenEnd);
m_Tail.remove_prefix(TokenEnd + SeparatorSize);
return true;
};

// Try to take a line, drop line breaks
- auto ChopSize = m_Tail.find_first_of(LineBreaks);
+ auto Piece = m_Tail.substr(0, m_Tail.find_first_of(LineBreaks));
auto BreaksSize = 1;

- if (ChopSize == m_Tail.npos)
- {
- ChopSize = m_Tail.size();
+ if (Piece.size() == m_Tail.size())
BreaksSize = 0;
- }

- if (ChopSize <= m_Width)
- return advance(ChopSize, BreaksSize);
+ if (visual_string_length(Piece) <= m_Width)
+ return advance(Piece.size(), BreaksSize);

// Try to take some words, drop spaces
- ChopSize = m_Tail.find_last_of(WordSpaceBreaks, m_Width);
+ Piece = m_Tail.substr(0 ,m_Tail.find_last_of(WordSpaceBreaks, m_Width));
BreaksSize = 1;

- if (ChopSize == m_Tail.npos)
- {
- ChopSize = m_Tail.size();
+ if (Piece.size() == m_Tail.size())
BreaksSize = 0;
- }

- if (ChopSize <= m_Width)
- return advance(ChopSize, BreaksSize);
+ if (visual_string_length(Piece) <= m_Width)
+ return advance(Piece.size(), BreaksSize);

// Try to take some words, keep separators
- ChopSize = m_Tail.find_last_of(WordOtherBreaks, m_Width);
+ Piece = m_Tail.substr(0, m_Tail.find_last_of(WordOtherBreaks, m_Width));
BreaksSize = 1;

- if (ChopSize == m_Tail.npos)
- {
- ChopSize = m_Tail.size();
+ if (Piece.size() == m_Tail.size())
BreaksSize = 0;
- }

- if (ChopSize + BreaksSize <= m_Width)
- return advance(ChopSize + BreaksSize, 0);
+ if (visual_string_length(Piece) + BreaksSize <= m_Width)
+ return advance(Piece.size() + BreaksSize, 0);

// Take a part of the word
- return advance(m_Width, 0);
+ return advance(string::npos, 0);
+}
+
+size_t wrapped_text::width() const
+{
+ return visual_string_length(m_Tail);
}

bool FindWordInString(string_view const Str, size_t CurPos, size_t& Begin, size_t& End, string_view const WordDiv0)
diff --git a/far/strmix.hpp b/far/strmix.hpp
index 52b5a14c9..e6993d4d4 100644
--- a/far/strmix.hpp
+++ b/far/strmix.hpp
@@ -115,7 +115,7 @@ public:
explicit wrapped_text(auto&& Str, size_t const Width):
m_Str(FWD(Str)),
m_Tail(m_Str),
- m_Width(Width? Width : m_Tail.size())
+ m_Width(Width? Width : width())
{
}

@@ -123,6 +123,8 @@ private:
[[nodiscard]]
bool get(bool Reset, string_view& Value) const;

+ size_t width() const;
+
string_copyref m_Str;
string_view mutable m_Tail;
size_t m_Width;


Reply all
Reply to author
Forward
0 new messages