Skip to content

Commit 99d237a

Browse files
committedOct 13, 2020
fix compose editor cursor position for long urls/text without space
1 parent b291342 commit 99d237a

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed
 

‎CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project
22
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
3-
project(nmail VERSION "1.96" LANGUAGES CXX)
3+
project(nmail VERSION "1.97" LANGUAGES CXX)
44
set(CMAKE_CXX_STANDARD 11)
55

66
# Ccache

‎src/nmail.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH NMAIL "1" "October 2020" "nmail v1.96" "User Commands"
2+
.TH NMAIL "1" "October 2020" "nmail v1.97" "User Commands"
33
.SH NAME
44
nmail \- ncurses mail
55
.SH SYNOPSIS

‎src/ui.cpp

+19-24
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Ui::Cleanup()
162162
void Ui::InitWindows()
163163
{
164164
getmaxyx(stdscr, m_ScreenHeight, m_ScreenWidth);
165-
m_MaxLineLength = m_ScreenWidth - 1;
165+
m_MaxLineLength = m_ScreenWidth;
166166
wclear(stdscr);
167167
wrefresh(stdscr);
168168
const int topHeight = 1;
@@ -1260,25 +1260,17 @@ void Ui::DrawComposeMessage()
12601260

12611261
for (int i = 0; i < (int)headerLines.size(); ++i)
12621262
{
1263-
if (i != m_ComposeHeaderLine)
1263+
if (m_IsComposeHeader && (i == m_ComposeHeaderLine) && (cursX >= m_ScreenWidth))
12641264
{
1265-
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
1265+
std::wstring line = headerLines.at(i) +
1266+
m_ComposeHeaderStr.at(i).substr(cursX - m_ScreenWidth + 1);
12661267
composeLines.push_back(line.substr(0, m_ScreenWidth));
1268+
cursX = m_ScreenWidth - 1;
12671269
}
12681270
else
12691271
{
1270-
if (cursX >= m_ScreenWidth)
1271-
{
1272-
std::wstring line = headerLines.at(i) +
1273-
m_ComposeHeaderStr.at(i).substr(cursX - m_ScreenWidth + 1);
1274-
composeLines.push_back(line.substr(0, m_ScreenWidth));
1275-
cursX = m_ScreenWidth - 1;
1276-
}
1277-
else
1278-
{
1279-
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
1280-
composeLines.push_back(line.substr(0, m_ScreenWidth));
1281-
}
1272+
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
1273+
composeLines.push_back(line.substr(0, m_ScreenWidth));
12821274
}
12831275
}
12841276

@@ -3178,7 +3170,7 @@ void Ui::ResponseHandler(const ImapManager::Request& p_Request, const ImapManage
31783170
}
31793171
}
31803172

3181-
const int maxBodysFetchRequest = 1; // XXX evaluate
3173+
const int maxBodysFetchRequest = 1;
31823174
if (!prefetchBodys.empty())
31833175
{
31843176
std::set<uint32_t> subsetPrefetchBodys;
@@ -3918,21 +3910,20 @@ void Ui::ComposeMessagePrevLine()
39183910
{
39193911
if (m_ComposeMessageWrapLine > 0)
39203912
{
3913+
int stepsBack = 0;
39213914
if ((int)m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() >
39223915
m_ComposeMessageWrapPos)
39233916
{
3924-
int stepsBack = m_ComposeMessageWrapPos + 1 +
3925-
(m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() -
3926-
m_ComposeMessageWrapPos);
3927-
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
3928-
(int)m_ComposeMessageStr.size());
3917+
stepsBack = m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() + 1;
39293918
}
39303919
else
39313920
{
3932-
int stepsBack = m_ComposeMessageWrapPos + 1;
3933-
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
3934-
(int)m_ComposeMessageStr.size());
3921+
stepsBack = m_ComposeMessageWrapPos + 1;
39353922
}
3923+
3924+
stepsBack = std::min(stepsBack, m_MaxLineLength);
3925+
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
3926+
(int)m_ComposeMessageStr.size());
39363927
}
39373928
else
39383929
{
@@ -3955,13 +3946,17 @@ void Ui::ComposeMessageNextLine()
39553946
{
39563947
stepsForward += m_ComposeMessageLines[m_ComposeMessageWrapLine + 1].size();
39573948
}
3949+
3950+
stepsForward = std::min(stepsForward, m_MaxLineLength);
39583951
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos + stepsForward,
39593952
(int)m_ComposeMessageStr.size());
39603953
}
39613954
else if ((int)m_ComposeMessageLines.size() > 0)
39623955
{
39633956
int stepsForward = m_ComposeMessageLines[m_ComposeMessageWrapLine].size() -
39643957
m_ComposeMessageWrapPos;
3958+
3959+
stepsForward = std::min(stepsForward, m_MaxLineLength);
39653960
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos + stepsForward,
39663961
(int)m_ComposeMessageStr.size());
39673962
}

‎src/util.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,17 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
799799

800800
std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLength,
801801
bool p_WrapQuoteLines,
802-
int p_Pos, int &p_WrapLine, int &p_WrapPos)
802+
int p_Pos, int& p_WrapLine, int& p_WrapPos)
803803
{
804804
std::wostringstream wrapped;
805805
std::vector<std::wstring> lines;
806806

807807
p_WrapLine = 0;
808808
p_WrapPos = 0;
809809

810+
const unsigned wrapLineLength = p_LineLength - 1; // lines with spaces allowed to width - 1
811+
const unsigned overflowLineLength = p_LineLength; // overflowing/long lines allowed to full width
812+
810813
{
811814
std::wstring line;
812815
std::wistringstream textss(p_Text);
@@ -815,10 +818,10 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
815818
std::wstring linePart = line;
816819
while (true)
817820
{
818-
if ((linePart.size() >= p_LineLength) &&
821+
if ((linePart.size() >= wrapLineLength) &&
819822
(p_WrapQuoteLines || (linePart.rfind(L">", 0) != 0)))
820823
{
821-
size_t spacePos = linePart.rfind(L' ', p_LineLength);
824+
size_t spacePos = linePart.rfind(L' ', wrapLineLength);
822825
if (spacePos != std::wstring::npos)
823826
{
824827
lines.push_back(linePart.substr(0, spacePos));
@@ -833,10 +836,10 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
833836
}
834837
else
835838
{
836-
lines.push_back(linePart.substr(0, p_LineLength));
837-
if (linePart.size() > p_LineLength)
839+
lines.push_back(linePart.substr(0, overflowLineLength));
840+
if (linePart.size() > overflowLineLength)
838841
{
839-
linePart = linePart.substr(p_LineLength);
842+
linePart = linePart.substr(overflowLineLength);
840843
}
841844
else
842845
{
@@ -858,7 +861,7 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
858861
{
859862
if (p_Pos > 0)
860863
{
861-
int lineLength = line.size() + 1;
864+
int lineLength = std::min((unsigned)line.size() + 1, overflowLineLength);
862865
if (lineLength <= p_Pos)
863866
{
864867
p_Pos -= lineLength;

0 commit comments

Comments
 (0)
Please sign in to comment.