Skip to content

Commit

Permalink
fix compose editor cursor position for long urls/text without space
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Oct 13, 2020
1 parent b291342 commit 99d237a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(nmail VERSION "1.96" LANGUAGES CXX)
project(nmail VERSION "1.97" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)

# Ccache
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "October 2020" "nmail v1.96" "User Commands"
.TH NMAIL "1" "October 2020" "nmail v1.97" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
43 changes: 19 additions & 24 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void Ui::Cleanup()
void Ui::InitWindows()
{
getmaxyx(stdscr, m_ScreenHeight, m_ScreenWidth);
m_MaxLineLength = m_ScreenWidth - 1;
m_MaxLineLength = m_ScreenWidth;
wclear(stdscr);
wrefresh(stdscr);
const int topHeight = 1;
Expand Down Expand Up @@ -1260,25 +1260,17 @@ void Ui::DrawComposeMessage()

for (int i = 0; i < (int)headerLines.size(); ++i)
{
if (i != m_ComposeHeaderLine)
if (m_IsComposeHeader && (i == m_ComposeHeaderLine) && (cursX >= m_ScreenWidth))
{
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
std::wstring line = headerLines.at(i) +
m_ComposeHeaderStr.at(i).substr(cursX - m_ScreenWidth + 1);
composeLines.push_back(line.substr(0, m_ScreenWidth));
cursX = m_ScreenWidth - 1;
}
else
{
if (cursX >= m_ScreenWidth)
{
std::wstring line = headerLines.at(i) +
m_ComposeHeaderStr.at(i).substr(cursX - m_ScreenWidth + 1);
composeLines.push_back(line.substr(0, m_ScreenWidth));
cursX = m_ScreenWidth - 1;
}
else
{
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
composeLines.push_back(line.substr(0, m_ScreenWidth));
}
std::wstring line = headerLines.at(i) + m_ComposeHeaderStr.at(i);
composeLines.push_back(line.substr(0, m_ScreenWidth));
}
}

Expand Down Expand Up @@ -3178,7 +3170,7 @@ void Ui::ResponseHandler(const ImapManager::Request& p_Request, const ImapManage
}
}

const int maxBodysFetchRequest = 1; // XXX evaluate
const int maxBodysFetchRequest = 1;
if (!prefetchBodys.empty())
{
std::set<uint32_t> subsetPrefetchBodys;
Expand Down Expand Up @@ -3918,21 +3910,20 @@ void Ui::ComposeMessagePrevLine()
{
if (m_ComposeMessageWrapLine > 0)
{
int stepsBack = 0;
if ((int)m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() >
m_ComposeMessageWrapPos)
{
int stepsBack = m_ComposeMessageWrapPos + 1 +
(m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() -
m_ComposeMessageWrapPos);
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
(int)m_ComposeMessageStr.size());
stepsBack = m_ComposeMessageLines[m_ComposeMessageWrapLine - 1].size() + 1;
}
else
{
int stepsBack = m_ComposeMessageWrapPos + 1;
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
(int)m_ComposeMessageStr.size());
stepsBack = m_ComposeMessageWrapPos + 1;
}

stepsBack = std::min(stepsBack, m_MaxLineLength);
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos - stepsBack,
(int)m_ComposeMessageStr.size());
}
else
{
Expand All @@ -3955,13 +3946,17 @@ void Ui::ComposeMessageNextLine()
{
stepsForward += m_ComposeMessageLines[m_ComposeMessageWrapLine + 1].size();
}

stepsForward = std::min(stepsForward, m_MaxLineLength);
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos + stepsForward,
(int)m_ComposeMessageStr.size());
}
else if ((int)m_ComposeMessageLines.size() > 0)
{
int stepsForward = m_ComposeMessageLines[m_ComposeMessageWrapLine].size() -
m_ComposeMessageWrapPos;

stepsForward = std::min(stepsForward, m_MaxLineLength);
m_ComposeMessagePos = Util::Bound(0, m_ComposeMessagePos + stepsForward,
(int)m_ComposeMessageStr.size());
}
Expand Down
17 changes: 10 additions & 7 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,17 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen

std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLength,
bool p_WrapQuoteLines,
int p_Pos, int &p_WrapLine, int &p_WrapPos)
int p_Pos, int& p_WrapLine, int& p_WrapPos)
{
std::wostringstream wrapped;
std::vector<std::wstring> lines;

p_WrapLine = 0;
p_WrapPos = 0;

const unsigned wrapLineLength = p_LineLength - 1; // lines with spaces allowed to width - 1
const unsigned overflowLineLength = p_LineLength; // overflowing/long lines allowed to full width

{
std::wstring line;
std::wistringstream textss(p_Text);
Expand All @@ -815,10 +818,10 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
std::wstring linePart = line;
while (true)
{
if ((linePart.size() >= p_LineLength) &&
if ((linePart.size() >= wrapLineLength) &&
(p_WrapQuoteLines || (linePart.rfind(L">", 0) != 0)))
{
size_t spacePos = linePart.rfind(L' ', p_LineLength);
size_t spacePos = linePart.rfind(L' ', wrapLineLength);
if (spacePos != std::wstring::npos)
{
lines.push_back(linePart.substr(0, spacePos));
Expand All @@ -833,10 +836,10 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
}
else
{
lines.push_back(linePart.substr(0, p_LineLength));
if (linePart.size() > p_LineLength)
lines.push_back(linePart.substr(0, overflowLineLength));
if (linePart.size() > overflowLineLength)
{
linePart = linePart.substr(p_LineLength);
linePart = linePart.substr(overflowLineLength);
}
else
{
Expand All @@ -858,7 +861,7 @@ std::vector<std::wstring> Util::WordWrap(std::wstring p_Text, unsigned p_LineLen
{
if (p_Pos > 0)
{
int lineLength = line.size() + 1;
int lineLength = std::min((unsigned)line.size() + 1, overflowLineLength);
if (lineLength <= p_Pos)
{
p_Pos -= lineLength;
Expand Down

0 comments on commit 99d237a

Please sign in to comment.