[dasher: 206/217] Correctly calculate offset after control box move and delete commands.
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 206/217] Correctly calculate offset after control box move and delete commands.
- Date: Sat, 27 Feb 2016 12:17:38 +0000 (UTC)
commit 5f82c6af7ae639621aa5c49ae046dee4556dc64e
Author: Ada Majorek <amajorek google com>
Date: Mon Feb 8 11:47:37 2016 -0800
Correctly calculate offset after control box move and delete commands.
fixeshttps://github.com/ipomoena/dasher/issues/13
Src/DasherCore/ControlManager.cpp | 27 +++------------------------
Src/DasherCore/DasherInterfaceBase.h | 10 ++++++++++
Src/Win32/Dasher.cpp | 4 ++++
Src/Win32/Dasher.h | 1 +
Src/Win32/Widgets/Edit.cpp | 7 +++++++
Src/Win32/Widgets/Edit.h | 3 ++-
6 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index d831af6..1d051c6 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -312,15 +312,8 @@ public:
int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) override {
if (m_bForwards)
return offsetBefore;
- switch (m_dist) {
- case CControlManager::EDIT_FILE:
- return -1;
- case CControlManager::EDIT_CHAR: {
- return max(-1, offsetBefore - 1);
- }
- default:
- return offsetBefore;
- }
+
+ return pNode->mgr()->GetDasherInterface()->ctrlOffsetAfterMove(offsetBefore + 1, m_bForwards, m_dist) -
1;
}
virtual void happen(CControlBase::CContNode *pNode) {
pNode->mgr()->GetDasherInterface()->ctrlDelete(m_bForwards, m_dist);
@@ -334,21 +327,7 @@ public:
Move(bool bForwards, CControlManager::EditDistance dist) : m_bForwards(bForwards), m_dist(dist) {
}
int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) override {
- switch (m_dist) {
- case CControlManager::EDIT_FILE:
- return m_bForwards ? pNode->mgr()->GetDasherInterface()->GetAllContextLenght() - 1 : -1;
-
- case CControlManager::EDIT_CHAR: {
- if (m_bForwards) {
- int maxPos = pNode->mgr()->GetDasherInterface()->GetAllContextLenght() - 1;
- return min(maxPos, offsetBefore + 1);
- }
- else
- return max(-1, offsetBefore - 1);
- }
- default:
- return offsetBefore;
- }
+ return pNode->mgr()->GetDasherInterface()->ctrlOffsetAfterMove(offsetBefore + 1, m_bForwards, m_dist) -
1;
}
virtual void happen(CControlBase::CContNode *pNode) {
pNode->mgr()->GetDasherInterface()->ctrlMove(m_bForwards, m_dist);
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index 4f90441..ffd9be4 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -182,6 +182,16 @@ public:
///Subclasses supporting clipboard operations should override to copy
/// the specified text to the clipboard. (Default implementation does nothing).
virtual void CopyToClipboard(const std::string &text) {}
+
+ ///Called to calculate offset after control-mode "move" or delete commands.
+ ///\param bForwards true to move forwards (right), false for backwards
+ ///\param dist how far to move: character, word, line, ..., file. (Usually defined
+ /// by OS, e.g. for non-european languages)
+ ///\return the offset, into the edit buffer where the cursor would be *after* the move.
+ virtual unsigned int ctrlOffsetAfterMove(unsigned int offsetBefore, bool bForwards,
+ CControlManager::EditDistance iDist) {
+ return offsetBefore;
+ }
///Called to execute a control-mode "move" command.
///\param bForwards true to move forwards (right), false for backwards
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index 310f4f4..73a5ccc 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -127,6 +127,10 @@ void Dasher::CDasher::editDelete(const string &strText, CDasherNode *pSource) {
CDasherInterfaceBase::editDelete(strText, pSource);
}
+unsigned int Dasher::CDasher::ctrlOffsetAfterMove(unsigned int offsetBefore, bool bForwards,
CControlManager::EditDistance iDist) {
+ return m_pEdit->OffsetAfterMove(offsetBefore, bForwards, iDist);
+}
+
unsigned int Dasher::CDasher::ctrlMove(bool bForwards, CControlManager::EditDistance iDist) {
return m_pEdit->Move(bForwards, iDist);
}
diff --git a/Src/Win32/Dasher.h b/Src/Win32/Dasher.h
index 488c24e..a194a89 100644
--- a/Src/Win32/Dasher.h
+++ b/Src/Win32/Dasher.h
@@ -58,6 +58,7 @@ public:
void HandleEvent(int iParameter) override;
void editOutput(const std::string &strText, CDasherNode *pSource) override;
void editDelete(const std::string &strText, CDasherNode *pSource) override;
+ unsigned int ctrlOffsetAfterMove(unsigned int offsetBefore, bool bForwards, CControlManager::EditDistance
iDist) override;
unsigned int ctrlMove(bool bForwards, CControlManager::EditDistance iDist) override;
unsigned int ctrlDelete(bool bForwards, CControlManager::EditDistance iDist) override;
diff --git a/Src/Win32/Widgets/Edit.cpp b/Src/Win32/Widgets/Edit.cpp
index 4cd5c34..b7d0c07 100644
--- a/Src/Win32/Widgets/Edit.cpp
+++ b/Src/Win32/Widgets/Edit.cpp
@@ -434,6 +434,13 @@ std::string CEdit::GetTextAroundCursor(CControlManager::EditDistance iDist) {
return wstring_to_UTF8string(wideText.Mid(iStart, iEnd-iStart));
}
+unsigned int CEdit::OffsetAfterMove(unsigned int offsetBefore, bool bForwards, CControlManager::EditDistance
iDist) {
+ int iStart, iEnd;
+ iStart = iEnd = offsetBefore;
+ GetRange(bForwards, iDist, &iStart, &iEnd);
+ return bForwards ? iEnd : iStart;
+}
+
int CEdit::Move(bool bForwards, CControlManager::EditDistance iDist) {
int iStart = 0;
int iEnd = 0;
diff --git a/Src/Win32/Widgets/Edit.h b/Src/Win32/Widgets/Edit.h
index 68138b5..b6cd43f 100644
--- a/Src/Win32/Widgets/Edit.h
+++ b/Src/Win32/Widgets/Edit.h
@@ -76,7 +76,8 @@ class CEdit : public ATL::CWindowImpl<CEdit> {
void Move(int x, int y, int Width, int Height);
-
+
+ unsigned int OffsetAfterMove(unsigned int offsetBefore, bool bForwards,
Dasher::CControlManager::EditDistance iDist);
int Move(bool bForwards, Dasher::CControlManager::EditDistance iDist);
int Delete(bool bForwards, Dasher::CControlManager::EditDistance iDist);
std::string GetTextAroundCursor(Dasher::CControlManager::EditDistance iDist);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]