[Libreoffice-commits] core.git: starmath/inc starmath/source
Luke Dixon (via logerrit)
logerrit at kemper.freedesktop.org
Tue Sep 8 06:18:40 UTC 2020
starmath/inc/caret.hxx | 13 ++++++-------
starmath/inc/cursor.hxx | 3 +--
starmath/source/cursor.cxx | 17 ++---------------
starmath/source/view.cxx | 16 ++++++++--------
4 files changed, 17 insertions(+), 32 deletions(-)
New commits:
commit 5267b6c04eed2662726bb90899eb40414779fcb3
Author: Luke Dixon <luke at luke.dixon.name>
AuthorDate: Tue Sep 8 01:37:23 2020 +0100
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 8 08:17:59 2020 +0200
starmath: stop change to caret pos graph when moving after brace
Currently, the code that moves the cursor after the brace changes the
current caret pos instead of moving to the next pos. Because of this, we
end up with one missing graph pos and a duplicate graph pos. This can be
seen by moving to the end of a brace body, pressing the key for the
closing brace and then pressing left and right to move in and out of the
brace.
This fix uses the existing code that sets the cursor position to the
next element in the graph instead of changing the cursor pos directly.
It also marks the caret pos as const to suggest not changing the caret
pos inside a graph entry.
Change-Id: I5492e54f1bddbfc90036f29698982fd8696f5e88
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102214
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/starmath/inc/caret.hxx b/starmath/inc/caret.hxx
index 327ee1d6ed16..c0e5c4f5fca0 100644
--- a/starmath/inc/caret.hxx
+++ b/starmath/inc/caret.hxx
@@ -103,15 +103,14 @@ private:
/** An entry in SmCaretPosGraph */
struct SmCaretPosGraphEntry{
- SmCaretPosGraphEntry(SmCaretPos pos,
- SmCaretPosGraphEntry* left,
- SmCaretPosGraphEntry* right) {
- CaretPos = pos;
- Left = left;
- Right = right;
+ SmCaretPosGraphEntry(SmCaretPos pos, SmCaretPosGraphEntry* left, SmCaretPosGraphEntry* right)
+ : CaretPos{pos}
+ , Left{left}
+ , Right{right}
+ {
}
/** Caret position */
- SmCaretPos CaretPos;
+ const SmCaretPos CaretPos;
/** Entry to the left visually */
SmCaretPosGraphEntry* Left;
/** Entry to the right visually */
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 236485d5e04c..47218e490865 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -184,8 +184,7 @@ public:
/** Draw the caret */
void Draw(OutputDevice& pDev, Point Offset, bool isCaretVisible);
- bool IsAtTailOfBracket(SmBracketType eBracketType, SmBraceNode** ppBraceNode) const;
- void MoveAfterBracket(SmBraceNode* pBraceNode);
+ bool IsAtTailOfBracket(SmBracketType eBracketType) const;
private:
friend class SmDocShell;
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 5e69b5876a45..c476bd41228e 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -1327,7 +1327,8 @@ void SmCursor::RequestRepaint(){
}
}
-bool SmCursor::IsAtTailOfBracket(SmBracketType eBracketType, SmBraceNode** ppBraceNode) const {
+bool SmCursor::IsAtTailOfBracket(SmBracketType eBracketType) const
+{
const SmCaretPos pos = GetPosition();
if (!pos.IsValid()) {
return false;
@@ -1391,23 +1392,9 @@ bool SmCursor::IsAtTailOfBracket(SmBracketType eBracketType, SmBraceNode** ppBra
return false;
}
- if (ppBraceNode) {
- *ppBraceNode = pBraceNode;
- }
-
return true;
}
-void SmCursor::MoveAfterBracket(SmBraceNode* pBraceNode)
-{
- mpPosition->CaretPos.pSelectedNode = pBraceNode;
- mpPosition->CaretPos.nIndex = 1;
- mpAnchor->CaretPos.pSelectedNode = pBraceNode;
- mpAnchor->CaretPos.nIndex = 1;
- RequestRepaint();
-}
-
-
/////////////////////////////////////// SmNodeListParser
SmNode* SmNodeListParser::Parse(SmNodeList* list){
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 19274324ada7..dd967232723b 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -490,7 +490,6 @@ void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
default:
{
sal_Unicode code = rKEvt.GetCharCode();
- SmBraceNode* pBraceNode = nullptr;
if(code == ' ') {
rCursor.InsertElement(BlankElement);
@@ -506,13 +505,14 @@ void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
rCursor.InsertElement(FactorialElement);
}else if(code == '%') {
rCursor.InsertElement(PercentElement);
- }else if(code == ')' && rCursor.IsAtTailOfBracket(SmBracketType::Round, &pBraceNode)) {
- rCursor.MoveAfterBracket(pBraceNode);
- }else if(code == ']' && rCursor.IsAtTailOfBracket(SmBracketType::Square, &pBraceNode)) {
- rCursor.MoveAfterBracket(pBraceNode);
- }else if(code == '}' && rCursor.IsAtTailOfBracket(SmBracketType::Curly, &pBraceNode)) {
- rCursor.MoveAfterBracket(pBraceNode);
- }else{
+ }
+ else if ((code == ')' && rCursor.IsAtTailOfBracket(SmBracketType::Round))
+ || (code == ']' && rCursor.IsAtTailOfBracket(SmBracketType::Square))
+ || (code == '}' && rCursor.IsAtTailOfBracket(SmBracketType::Curly)))
+ {
+ rCursor.Move(this, MoveRight);
+ }
+ else{
if(code != 0){
rCursor.InsertText(OUString(code));
}else if (! (GetView() && GetView()->KeyInput(rKEvt)) )
More information about the Libreoffice-commits
mailing list